diff options
author | Aleksandar Prokopec <axel22@gmail.com> | 2012-08-14 18:00:23 +0200 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-08-17 06:40:00 -0700 |
commit | 5a8dfad583b825158cf0abdae5d73a4a7f8cd997 (patch) | |
tree | ede2216c999babc5e10f9c364f22c7732c9b033f /src | |
parent | e6c0439f1ca4270f28def98821def7b10ae84ec8 (diff) | |
download | scala-5a8dfad583b825158cf0abdae5d73a4a7f8cd997.tar.gz scala-5a8dfad583b825158cf0abdae5d73a4a7f8cd997.tar.bz2 scala-5a8dfad583b825158cf0abdae5d73a4a7f8cd997.zip |
Fixes SI-6189.
Disable @static for the REPL code.
The problem is that there are no companion classes generated for objects
that contain the top-level declarations in the REPL.
When there is no companion class, the selecting a @static field will translate
to a getter call, instead of to a field load.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/icode/GenICode.scala | 10 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/CleanUp.scala | 1 |
2 files changed, 8 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala index a480429026..1b89aa5560 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala @@ -880,12 +880,16 @@ abstract class GenICode extends SubComponent { case app @ Apply(fun @ Select(qual, _), args) if !ctx.method.symbol.isStaticConstructor - && fun.symbol.isAccessor && fun.symbol.accessed.hasStaticAnnotation => + && fun.symbol.isAccessor && fun.symbol.accessed.hasStaticAnnotation + && qual.tpe.typeSymbol.orElse(fun.symbol.owner).companionClass != NoSymbol => // bypass the accessor to the companion object and load the static field directly - // the only place were this bypass is not done, is the static intializer for the static field itself + // this bypass is not done: + // - if the static intializer for the static field itself + // - if there is no companion class of the object owner - this happens in the REPL val sym = fun.symbol generatedType = toTypeKind(sym.accessed.info) - val hostClass = qual.tpe.typeSymbol.orElse(sym.owner).companionClass + val hostOwner = qual.tpe.typeSymbol.orElse(sym.owner) + val hostClass = hostOwner.companionClass val staticfield = hostClass.info.findMember(sym.accessed.name, NoFlags, NoFlags, false) if (sym.isGetter) { diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala index 436867257a..4258ee8a88 100644 --- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala +++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala @@ -768,6 +768,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL { // add field definition to new defs newStaticMembers append stfieldDef newStaticInits append stfieldInit + case _ => // ignore @static on other members } } |