diff options
author | Lukas Rytz <lukas.rytz@epfl.ch> | 2009-11-12 11:10:13 +0000 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@epfl.ch> | 2009-11-12 11:10:13 +0000 |
commit | 33e1dac4e4a3b20b981a3c078e8605ba9a1a22f1 (patch) | |
tree | e1eec724c57fb2d0160d74df122f058395b02bf9 /src/compiler | |
parent | df13e31bbb5f0dedc9739687bae553512a4a2517 (diff) | |
download | scala-33e1dac4e4a3b20b981a3c078e8605ba9a1a22f1.tar.gz scala-33e1dac4e4a3b20b981a3c078e8605ba9a1a22f1.tar.bz2 scala-33e1dac4e4a3b20b981a3c078e8605ba9a1a22f1.zip |
fixed #2470.
Diffstat (limited to 'src/compiler')
3 files changed, 27 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Constants.scala b/src/compiler/scala/tools/nsc/symtab/Constants.scala index dfe7147270..2a4d3e1fa1 100644 --- a/src/compiler/scala/tools/nsc/symtab/Constants.scala +++ b/src/compiler/scala/tools/nsc/symtab/Constants.scala @@ -66,7 +66,12 @@ trait Constants { case StringTag => StringClass.tpe case NullTag => NullClass.tpe case ClassTag => Predef_classOfType(value.asInstanceOf[Type]) - case EnumTag => symbolValue.owner.linkedClassOfClass.tpe + case EnumTag => + // given (in java): "class A { enum E { VAL1 } }" + // - symbolValue: the symbol of the actual enumeration value (VAL1) + // - .owner: the ModuleClasSymbol of the enumeration (object E) + // - .linkedClassOfClass: the ClassSymbol of the enumeration (class E) + symbolValue.owner.linkedClassOfClass.tpe } /** We need the equals method to take account of tags as well as values. diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index 3b9ffa4f58..1c22a6fdaf 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -1235,7 +1235,7 @@ trait Symbols { */ final def linkedClassOfModule: Symbol = { if (this != NoSymbol) - owner.rawInfo.decl(name.toTypeName).suchThat(_ isCoDefinedWith this) + flatOwnerInfo.decl(name.toTypeName).suchThat(_ isCoDefinedWith this) else NoSymbol } @@ -1244,7 +1244,7 @@ trait Symbols { */ final def linkedModuleOfClass: Symbol = if (this.isClass && !this.isAnonymousClass && !this.isRefinementClass) { - owner.rawInfo.decl(name.toTermName).suchThat( + flatOwnerInfo.decl(name.toTermName).suchThat( sym => (sym hasFlag MODULE) && (sym isCoDefinedWith this)) } else NoSymbol @@ -1253,7 +1253,7 @@ trait Symbols { */ final def linkedSym: Symbol = if (isTerm) linkedClassOfModule - else if (isClass) owner.rawInfo.decl(name.toTermName).suchThat(_ isCoDefinedWith this) + else if (isClass) flatOwnerInfo.decl(name.toTermName).suchThat(_ isCoDefinedWith this) else NoSymbol /** For a module class its linked class, for a plain class @@ -1268,6 +1268,23 @@ trait Symbols { final def linkedClassOfClass: Symbol = if (isModuleClass) linkedClassOfModule else linkedModuleOfClass.moduleClass + /** + * Returns the rawInfo of the owner. If the current phase has flat classes, it first + * applies all pending type maps to this symbol. + * + * Asssume this is the ModuleSymbol for B in the follwing definition: + * package p { class A { object B { val x = 1 } } } + * + * The owner after flatten is "package p" (see "def owner"). The flatten type map enters + * symbol B in the decls of p. So to find a linked symbol ("object B" or "class B") + * we need to apply flatten to B first. Fixes #2470. + */ + private final def flatOwnerInfo: Type = { + if (phase.flatClasses && rawowner != NoSymbol && !rawowner.isPackageClass) + info + owner.rawInfo + } + /** If this symbol is an implementation class, its interface, otherwise the symbol itself * The method follows two strategies to determine the interface. * - during or after erasure, it takes the last parent of the implementatation class diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index 940a8e223b..86cb636fb8 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -890,7 +890,7 @@ abstract class ClassfileParser { val innerClass = getOwner(jflags).newClass(NoPosition, name.toTypeName).setInfo(completer).setFlag(sflags) val innerModule = getOwner(jflags).newModule(NoPosition, name).setInfo(completer).setFlag(sflags) - innerClass.moduleClass.setInfo(global.loaders.moduleClassLoader) + innerModule.moduleClass.setInfo(global.loaders.moduleClassLoader) getScope(jflags).enter(innerClass) getScope(jflags).enter(innerModule) |