From 5a8dfad583b825158cf0abdae5d73a4a7f8cd997 Mon Sep 17 00:00:00 2001 From: Aleksandar Prokopec Date: Tue, 14 Aug 2012 18:00:23 +0200 Subject: 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. --- src/compiler/scala/tools/nsc/backend/icode/GenICode.scala | 10 +++++++--- src/compiler/scala/tools/nsc/transform/CleanUp.scala | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'src') 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 } } -- cgit v1.2.3