diff options
Diffstat (limited to 'src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala | 36 |
1 files changed, 25 insertions, 11 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala b/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala index a4b5a84d5d..8ed5871a95 100644 --- a/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala +++ b/src/compiler/scala/tools/nsc/backend/msil/GenMSIL.scala @@ -1999,9 +1999,8 @@ abstract class GenMSIL extends SubComponent { } def createTypeBuilder(iclass: IClass) { - def getMsilType(tpe: Type): MsilType = { - val sym = tpe.typeSymbol - types.get(sym.asInstanceOf[clrTypes.global.Symbol]) match { + def msilTypeFromSym(sym: Symbol): MsilType = { + types.get(sym.asInstanceOf[clrTypes.global.Symbol]) match { case Some(mtype) => mtype case None => createTypeBuilder(classes(sym)); types(sym.asInstanceOf[clrTypes.global.Symbol]) } @@ -2015,11 +2014,12 @@ abstract class GenMSIL extends SubComponent { if (sym.info.parents.isEmpty) List(definitions.ObjectClass.tpe) else sym.info.parents.removeDuplicates - val superType = if (isInterface(sym)) null else getMsilType(parents.head) + val superType = if (isInterface(sym)) null else msilTypeFromSym(parents.head.typeSymbol) if (settings.debug.value) log("super type: " + parents(0).typeSymbol + ", msil type: " + superType) - val interfaces: Array[MsilType] = parents.tail.map(getMsilType).toArray + val interfaces: Array[MsilType] = + parents.tail.map(p => msilTypeFromSym(p.typeSymbol)).toArray if (parents.length > 1) { if (settings.debug.value){ log("interfaces:") @@ -2029,10 +2029,16 @@ abstract class GenMSIL extends SubComponent { } } - //TODO here: if the class is not top-level, use DefineNestedType? - val tBuilder = - mmodule.DefineType(msilName(sym), msilTypeFlags(sym), superType, interfaces) - mapType(sym, tBuilder) + if (sym.isNestedClass) { + val ownerT = msilTypeFromSym(sym.owner).asInstanceOf[TypeBuilder] + val tBuilder = + ownerT.DefineNestedType(msilName(sym), msilTypeFlags(sym), superType, interfaces) + mapType(sym, tBuilder) + } else { + val tBuilder = + mmodule.DefineType(msilName(sym), msilTypeFlags(sym), superType, interfaces) + mapType(sym, tBuilder) + } } // createTypeBuilder def createClassMembers(iclass: IClass) { @@ -2095,7 +2101,7 @@ abstract class GenMSIL extends SubComponent { } } - if (isStaticModule(iclass.symbol)){ + if (isStaticModule(iclass.symbol)) { addModuleInstanceField(iclass.symbol) notInitializedModules += iclass.symbol addStaticInit(iclass.symbol) @@ -2108,8 +2114,13 @@ abstract class GenMSIL extends SubComponent { sym.isModuleClass && !sym.isImplClass && !sym.isNestedClass } + // if the module is lifted it does not need to be initialized in + // its static constructor, and the MODULE$ field is not required. + // the outer class will care about it. private def isStaticModule(sym: Symbol): Boolean = { - sym.isModuleClass && !sym.isImplClass && !sym.hasFlag(Flags.LIFTED) + // .net inner classes: removed '!sym.hasFlag(Flags.LIFTED)', added + // 'sym.isStatic'. -> no longer compatible without skipping flatten! + sym.isModuleClass && sym.isStatic && !sym.isImplClass } private def isCloneable(sym: Symbol): Boolean = { @@ -2169,6 +2180,9 @@ abstract class GenMSIL extends SubComponent { val instanceConstructor = constructors(sym.primaryConstructor.asInstanceOf[clrTypes.global.Symbol]) + // there are no constructor parameters. assuming the constructor takes no parameter + // is fine: we call (in the static constructor) the constructor of the module class, + // which takes no arguments - an object definition cannot take constructor arguments. sicode.Emit(OpCodes.Newobj, instanceConstructor) // the stsfld is done in the instance constructor, just after the super call. sicode.Emit(OpCodes.Pop) |