diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/Trees.scala | 11 | ||||
-rw-r--r-- | test/files/run/resetattrs-this.check | 1 | ||||
-rw-r--r-- | test/files/run/resetattrs-this.scala | 11 |
3 files changed, 19 insertions, 4 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/Trees.scala b/src/compiler/scala/tools/nsc/ast/Trees.scala index 2ad762fd55..f83a9632f6 100644 --- a/src/compiler/scala/tools/nsc/ast/Trees.scala +++ b/src/compiler/scala/tools/nsc/ast/Trees.scala @@ -335,14 +335,17 @@ trait Trees extends scala.reflect.internal.Trees { self: Global => else tree case TypeApply(fn, args) if args map transform exists (_.isEmpty) => transform(fn) - case This(_) if tree.symbol != null && tree.symbol.isPackageClass => - tree case EmptyTree => tree case _ => val dupl = tree.duplicate - if (tree.hasSymbol && (!localOnly || (locals contains tree.symbol)) && !(keepLabels && tree.symbol.isLabel)) - dupl.symbol = NoSymbol + if (dupl.hasSymbol) { + val sym = dupl.symbol + val vetoScope = localOnly && !(locals contains sym) + val vetoLabel = keepLabels && sym.isLabel + val vetoThis = dupl.isInstanceOf[This] && sym.isPackageClass + if (!(vetoScope || vetoLabel || vetoThis)) dupl.symbol = NoSymbol + } dupl.tpe = null dupl } diff --git a/test/files/run/resetattrs-this.check b/test/files/run/resetattrs-this.check new file mode 100644 index 0000000000..27ba77ddaf --- /dev/null +++ b/test/files/run/resetattrs-this.check @@ -0,0 +1 @@ +true diff --git a/test/files/run/resetattrs-this.scala b/test/files/run/resetattrs-this.scala new file mode 100644 index 0000000000..12afa3d712 --- /dev/null +++ b/test/files/run/resetattrs-this.scala @@ -0,0 +1,11 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{currentMirror => cm} +import scala.tools.reflect.ToolBox + +object Test extends App { + val tb = cm.mkToolBox() + val tree = Select(This(cm.staticPackage("scala").moduleClass), newTermName("Predef")) + val ttree = tb.typeCheck(tree) + val rttree = tb.resetAllAttrs(ttree) + println(tb.eval(rttree) == Predef) +}
\ No newline at end of file |