Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SI-9473 Cleaner references to statically owned symbols #4749

Merged
merged 1 commit into from
Sep 22, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/reflect/scala/reflect/internal/TreeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,16 @@ abstract class TreeGen {

/** Builds a reference to given symbol. */
def mkAttributedRef(sym: Symbol): RefTree =
if (sym.owner.isClass) mkAttributedRef(sym.owner.thisType, sym)
if (sym.owner.isStaticOwner) {
if (sym.owner.isRoot)
mkAttributedIdent(sym)
else {
val ownerModule = sym.owner.sourceModule
assert(ownerModule != NoSymbol, sym.owner)
mkAttributedSelect(mkAttributedRef(sym.owner.sourceModule), sym)
}
}
else if (sym.owner.isClass) mkAttributedRef(sym.owner.thisType, sym)
else mkAttributedIdent(sym)

def mkUnattributedRef(sym: Symbol): RefTree = mkUnattributedRef(sym.fullNameAsName('.'))
Expand Down
6 changes: 3 additions & 3 deletions test/files/neg/t6323a.check
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
t6323a.scala:10: materializing requested scala.reflect.type.ClassTag[Test] using `package`.this.materializeClassTag[Test]()
t6323a.scala:10: materializing requested scala.reflect.type.ClassTag[Test] using scala.reflect.`package`.materializeClassTag[Test]()
val lookAtMe = m.reflect(Test("a",List(5)))
^
t6323a.scala:11: materializing requested reflect.runtime.universe.type.TypeTag[Test] using `package`.this.materializeTypeTag[Test](scala.reflect.runtime.`package`.universe)
t6323a.scala:11: materializing requested reflect.runtime.universe.type.TypeTag[Test] using scala.reflect.api.`package`.materializeTypeTag[Test](scala.reflect.runtime.`package`.universe)
val value = u.typeOf[Test]
^
t6323a.scala:11: `package`.this.materializeTypeTag[Test](scala.reflect.runtime.`package`.universe) is not a valid implicit value for reflect.runtime.universe.TypeTag[Test] because:
t6323a.scala:11: scala.reflect.api.`package`.materializeTypeTag[Test](scala.reflect.runtime.`package`.universe) is not a valid implicit value for reflect.runtime.universe.TypeTag[Test] because:
failed to typecheck the materialized tag:
cannot create a TypeTag referring to class Test.Test local to the reifee: use WeakTypeTag instead
val value = u.typeOf[Test]
Expand Down
2 changes: 1 addition & 1 deletion test/files/presentation/random.check
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ askType at Random.scala(18,14)
================================================================================
[response] askTypeAt (18,14)
val filter: Int => Boolean = try {
java.this.lang.Integer.parseInt(args.apply(0)) match {
java.lang.Integer.parseInt(args.apply(0)) match {
case 1 => ((x: Int) => x.%(2).!=(0))
case 2 => ((x: Int) => x.%(2).==(0))
case _ => ((x: Int) => x.!=(0))
Expand Down
2 changes: 1 addition & 1 deletion test/files/presentation/t8941.check
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ reload: Source.scala
askType at Source.scala(6,7)
================================================================================
[response] askTypeAt (6,7)
scala.this.Predef.???
scala.Predef.???
================================================================================
2 changes: 1 addition & 1 deletion test/files/run/delambdafy_t6028.check
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ package <empty> {
def /*MethodLocalTrait$1$class*/$init$(barParam$1: String): Unit = {
()
};
scala.this.Predef.print(barParam$1)
scala.Predef.print(barParam$1)
};
final <artifact> private[this] def $anonfun$2(tryyParam$1: String, tryyLocal$1: runtime.ObjectRef): Unit = try {
tryyLocal$1.elem = tryyParam$1
Expand Down
12 changes: 6 additions & 6 deletions test/files/run/idempotency-case-classes.check
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ C(2,3)
case 1 => C.this.y
case _ => throw new IndexOutOfBoundsException(x$1.toString())
};
override <synthetic> def productIterator: Iterator[Any] = runtime.this.ScalaRunTime.typedProductIterator[Any](C.this);
override <synthetic> def productIterator: Iterator[Any] = scala.runtime.ScalaRunTime.typedProductIterator[Any](C.this);
<synthetic> def canEqual(x$1: Any): Boolean = x$1.$isInstanceOf[C]();
override <synthetic> def hashCode(): Int = {
<synthetic> var acc: Int = -889275714;
acc = Statics.this.mix(acc, x);
acc = Statics.this.mix(acc, y);
Statics.this.finalizeHash(acc, 2)
acc = scala.runtime.Statics.mix(acc, x);
acc = scala.runtime.Statics.mix(acc, y);
scala.runtime.Statics.finalizeHash(acc, 2)
};
override <synthetic> def toString(): String = ScalaRunTime.this._toString(C.this);
override <synthetic> def toString(): String = scala.runtime.ScalaRunTime._toString(C.this);
override <synthetic> def equals(x$1: Any): Boolean = C.this.eq(x$1.asInstanceOf[Object]).||(x$1 match {
case (_: C) => true
case _ => false
Expand All @@ -45,7 +45,7 @@ C(2,3)
final override <synthetic> def toString(): String = "C";
case <synthetic> def apply(x: Int, y: Int): C = new C(x, y);
case <synthetic> def unapply(x$0: C): Option[(Int, Int)] = if (x$0.==(null))
scala.this.None
scala.None
else
Some.apply[(Int, Int)](scala.Tuple2.apply[Int, Int](x$0.x, x$0.y))
};
Expand Down
2 changes: 1 addition & 1 deletion test/files/run/macro-typecheck-implicitsdisabled.check
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
scala.this.Predef.ArrowAssoc[Int](1).->[Int](2)
scala.Predef.ArrowAssoc[Int](1).->[Int](2)
scala.reflect.macros.TypecheckException: value -> is not a member of Int
12 changes: 6 additions & 6 deletions test/files/run/macroPlugins-enterStats.check
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ package <empty> {
()
};
def x: Int = 2;
def xmacroPlugin1: Nothing = scala.this.Predef.???;
def xmacroPlugin2: Nothing = scala.this.Predef.???;
def xmacroPlugin2macroPlugin1: Nothing = scala.this.Predef.???;
def xmacroPlugin1: Nothing = scala.Predef.???;
def xmacroPlugin2: Nothing = scala.Predef.???;
def xmacroPlugin2macroPlugin1: Nothing = scala.Predef.???;
def y: Int = 3;
def ymacroPlugin1: Nothing = scala.this.Predef.???;
def ymacroPlugin2: Nothing = scala.this.Predef.???;
def ymacroPlugin2macroPlugin1: Nothing = scala.this.Predef.???
def ymacroPlugin1: Nothing = scala.Predef.???;
def ymacroPlugin2: Nothing = scala.Predef.???;
def ymacroPlugin2macroPlugin1: Nothing = scala.Predef.???
}
}

Expand Down
12 changes: 6 additions & 6 deletions test/files/run/macroPlugins-namerHooks.check
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
enterSym(package <empty> { case class C extends scala.Product with scala.Serializable { <caseaccessor> <paramaccessor> val x: Int = _; <caseaccessor> <paramaccessor> val y: Int = _; def <init>(x: Int, y: Int) = { super.<init>(); () } } })
enterSym(case class C extends scala.Product with scala.Serializable { <caseaccessor> <paramaccessor> val x: Int = _; <caseaccessor> <paramaccessor> val y: Int = _; def <init>(x: Int, y: Int) = { super.<init>(); () } })
ensureCompanionObject(case class C extends scala.Product with scala.Serializable { <caseaccessor> <paramaccessor> val x: Int = _; <caseaccessor> <paramaccessor> val y: Int = _; def <init>(x: Int, y: Int) = { super.<init>(); () } }, ...)
enterSym(<synthetic> object C extends runtime.this.AbstractFunction2[Int, Int, C] { def <init>() = { super.<init>(); () }; final override <synthetic> def toString() = "C" })
enterSym(<synthetic> object C extends scala.runtime.AbstractFunction2[Int, Int, C] { def <init>() = { super.<init>(); () }; final override <synthetic> def toString() = "C" })
enterStat(case class C extends scala.Product with scala.Serializable { <caseaccessor> <paramaccessor> val x: Int = _; <caseaccessor> <paramaccessor> val y: Int = _; def <init>(x: Int, y: Int) = { super.<init>(); () } })
enterSym(<caseaccessor> <paramaccessor> val x: Int = _)
enterSym(<caseaccessor> <paramaccessor> val y: Int = _)
Expand All @@ -18,17 +18,17 @@ enterStat(super.<init>())
enterSym(<synthetic> def copy$default$1 = x)
enterSym(<synthetic> def copy$default$2 = y)
enterSym(<synthetic> var acc: Int = -889275714)
enterSym(acc = Statics.this.mix(acc, x))
enterSym(acc = Statics.this.mix(acc, y))
enterSym(acc = scala.runtime.Statics.mix(acc, x))
enterSym(acc = scala.runtime.Statics.mix(acc, y))
enterStat(<synthetic> var acc: Int = -889275714)
enterStat(acc = Statics.this.mix(acc, x))
enterStat(acc = Statics.this.mix(acc, y))
enterStat(acc = scala.runtime.Statics.mix(acc, x))
enterStat(acc = scala.runtime.Statics.mix(acc, y))
enterSym(<synthetic> val C$1: C = x$1.asInstanceOf[C])
enterStat(<synthetic> val C$1: C = x$1.asInstanceOf[C])
enterSym(def <init>() = { super.<init>(); () })
enterSym(final override <synthetic> def toString() = "C")
enterSym(case <synthetic> def apply(x: Int, y: Int): C = new C(x, y))
enterSym(case <synthetic> def unapply(x$0: C): _root_.scala.Option[scala.Tuple2[Int, Int]] = if (x$0.==(null)) scala.this.None else Some(scala.Tuple2(x$0.x, x$0.y)))
enterSym(case <synthetic> def unapply(x$0: C): _root_.scala.Option[scala.Tuple2[Int, Int]] = if (x$0.==(null)) scala.None else Some(scala.Tuple2(x$0.x, x$0.y)))
enterStat(def <init>() = { super.<init>(); () })
enterStat(final override <synthetic> def toString() = "C")
enterSym(def <init>() = { super.<init>(); () })
Expand Down
2 changes: 1 addition & 1 deletion test/files/run/reflection-scala-annotations.check
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ make your annotation visible at runtime. If that is what
you want, you must write the annotation class in Java.
class jann(x: Int, y: Array[Int]) extends ClassfileAnnotation
^
new sann(1, immutable.this.List.apply[Int](1, 2))
new sann(1, scala.collection.immutable.List.apply[Int](1, 2))
new jann(y = Array(1, 2), x = 2)
2 changes: 1 addition & 1 deletion test/files/run/reify-aliases.check
Original file line number Diff line number Diff line change
@@ -1 +1 @@
TypeRef(SingleType(ThisType(scala), scala.Predef), TypeName("String"), List())
TypeRef(SingleType(TypeRef(ThisType(<root>), scala, List()), scala.Predef), TypeName("String"), List())
45 changes: 23 additions & 22 deletions test/files/run/t5064.check
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
[53] T5064.super.<init>()
[53] T5064.super.<init>
[53] this
[16:23] immutable.this.List.apply(scala.this.Predef.wrapIntArray(Array[Int]{1}))
[16:20] immutable.this.List.apply
<16:20> immutable.this.List
<16:20> immutable.this
[16:23] scala.this.Predef.wrapIntArray(Array[Int]{1})
[20] scala.this.Predef.wrapIntArray
[20] scala.this.Predef
[20] scala.this
[26:32] collection.this.Seq.apply(scala.this.Predef.wrapIntArray(Array[Int]{1}))
[26:29] collection.this.Seq.apply
<26:29> collection.this.Seq
<26:29> collection.this
[26:32] scala.this.Predef.wrapIntArray(Array[Int]{1})
[29] scala.this.Predef.wrapIntArray
[29] scala.this.Predef
[29] scala.this
[35:39] immutable.this.List
<35:39> immutable.this
[42:45] collection.this.Seq
<42:45> collection.this
[48:51] immutable.this.Nil
<48:51> immutable.this
[16:23] scala.collection.immutable.List.apply(scala.Predef.wrapIntArray(Array[Int]{1}))
[16:20] scala.collection.immutable.List.apply
<16:20> scala.collection.immutable.List
<16:20> scala.collection.immutable
<16:20> scala.collection
[16:23] scala.Predef.wrapIntArray(Array[Int]{1})
[20] scala.Predef.wrapIntArray
[20] scala.Predef
[26:32] scala.collection.Seq.apply(scala.Predef.wrapIntArray(Array[Int]{1}))
[26:29] scala.collection.Seq.apply
<26:29> scala.collection.Seq
<26:29> scala.collection
[26:32] scala.Predef.wrapIntArray(Array[Int]{1})
[29] scala.Predef.wrapIntArray
[29] scala.Predef
[35:39] scala.collection.immutable.List
<35:39> scala.collection.immutable
<35:39> scala.collection
[42:45] scala.collection.Seq
<42:45> scala.collection
[48:51] scala.collection.immutable.Nil
<48:51> scala.collection.immutable
<48:51> scala.collection
2 changes: 1 addition & 1 deletion test/files/run/t5943a1.check
Original file line number Diff line number Diff line change
@@ -1 +1 @@
scala.this.Predef.intWrapper(1).to(3).map[Int, scala.collection.immutable.IndexedSeq[Int]](((x$1: Int) => x$1.+(1)))(immutable.this.IndexedSeq.canBuildFrom[Int])
scala.Predef.intWrapper(1).to(3).map[Int, scala.collection.immutable.IndexedSeq[Int]](((x$1: Int) => x$1.+(1)))(immutable.this.IndexedSeq.canBuildFrom[Int])
2 changes: 1 addition & 1 deletion test/files/run/t6028.check
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ package <empty> {
def /*MethodLocalTrait$1$class*/$init$(barParam$1: Int): Unit = {
()
};
scala.this.Predef.print(scala.Int.box(barParam$1))
scala.Predef.print(scala.Int.box(barParam$1))
};
@SerialVersionUID(value = 0) final <synthetic> class $anonfun$tryy$1 extends scala.runtime.AbstractFunction0$mcV$sp with Serializable {
def <init>($outer: T, tryyParam$1: Int, tryyLocal$1: runtime.IntRef): <$anon: Function0> = {
Expand Down
6 changes: 3 additions & 3 deletions test/files/run/t6331b.check
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ else
-0.0
res: Double = 0.0

trace> Test.this.intercept.apply[Any](if (scala.this.Predef.???)
trace> Test.this.intercept.apply[Any](if (scala.Predef.???)
-0.0
else
0.0)
res: Any = class scala.NotImplementedError

trace> Test.this.intercept.apply[Any](if (scala.this.Predef.???)
trace> Test.this.intercept.apply[Any](if (scala.Predef.???)
0.0
else
0.0)
res: Any = class scala.NotImplementedError

trace> Test.this.intercept.apply[Any](if (scala.this.Predef.???)
trace> Test.this.intercept.apply[Any](if (scala.Predef.???)
()
else
())
Expand Down
8 changes: 4 additions & 4 deletions test/files/run/t7375b.check
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Predef.this.classOf[C1]
Predef.this.classOf[C2]
Predef.this.classOf[C1]
Predef.this.classOf[C2]
scala.Predef.classOf[C1]
scala.Predef.classOf[C2]
scala.Predef.classOf[C1]
scala.Predef.classOf[C2]
28 changes: 14 additions & 14 deletions test/files/run/t7817-tree-gen.check
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ Joint Compilation:
mixin [ test2.PO] - test2.package$PO
cleanup [ test2.PO] - test2.package$PO

typer [ test2.bar] - `package`.this.bar
pickler [ test2.bar] - `package`.this.bar
refchecks [ test2.bar] - `package`.this.bar
uncurry [ test2.bar] - `package`.this.bar
specialize [ test2.bar] - `package`.this.bar
explicitouter [ test2.bar] - `package`.this.bar
erasure [ test2.bar] - `package`.this.bar
typer [ test2.bar] - test2.`package`.bar
pickler [ test2.bar] - test2.`package`.bar
refchecks [ test2.bar] - test2.`package`.bar
uncurry [ test2.bar] - test2.`package`.bar
specialize [ test2.bar] - test2.`package`.bar
explicitouter [ test2.bar] - test2.`package`.bar
erasure [ test2.bar] - test2.`package`.bar
posterasure [ test2.bar] - test2.`package`.bar
flatten [ test2.bar] - test2.`package`.bar
mixin [ test2.bar] - test2.`package`.bar
Expand Down Expand Up @@ -90,13 +90,13 @@ Separate Compilation:
mixin [ PO] - test2.package$PO
cleanup [ PO] - test2.package$PO

typer [testSep2.bar] - `package`.this.bar
pickler [testSep2.bar] - `package`.this.bar
refchecks [testSep2.bar] - `package`.this.bar
uncurry [testSep2.bar] - `package`.this.bar
specialize [testSep2.bar] - `package`.this.bar
explicitouter [testSep2.bar] - `package`.this.bar
erasure [testSep2.bar] - `package`.this.bar
typer [testSep2.bar] - test2.`package`.bar
pickler [testSep2.bar] - test2.`package`.bar
refchecks [testSep2.bar] - test2.`package`.bar
uncurry [testSep2.bar] - test2.`package`.bar
specialize [testSep2.bar] - test2.`package`.bar
explicitouter [testSep2.bar] - test2.`package`.bar
erasure [testSep2.bar] - test2.`package`.bar
posterasure [testSep2.bar] - test2.`package`.bar
flatten [testSep2.bar] - test2.`package`.bar
mixin [testSep2.bar] - test2.`package`.bar
Expand Down
2 changes: 1 addition & 1 deletion test/files/scalacheck/quasiquotes/TypecheckedProps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ trait TypecheckedTypes { self: QuasiquoteProperties =>
property("applied type") = test {
val tt = typecheckTyp(tq"Map[Int, Int]")
val tq"$tpt[..$tpts]" = tt
val tq"scala.this.Predef.Map" = tpt
val tq"scala.Predef.Map" = tpt
val List(tq"scala.Int", tq"scala.Int") = tpts
}

Expand Down
51 changes: 51 additions & 0 deletions test/junit/scala/reflect/internal/TreeGenTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package scala.reflect.internal

import org.junit.Assert._
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4

import scala.runtime.ScalaRunTime
import scala.tools.nsc.symtab.SymbolTableForUnitTesting

@RunWith(classOf[JUnit4])
class TreeGenTest {
object symbolTable extends SymbolTableForUnitTesting

import symbolTable._

@Test
def attributedRefToTopLevelMemberNotPrefixedByThis_t9473_a(): Unit = {
val SomeClass = symbolOf[Some[_]]
val ref = gen.mkAttributedRef(SomeClass)
assertEquals("scala.Some", ref.toString) // was scala.this.Some
ref match {
case sel @ Select(pre @ Ident(preName), name) =>
assertEquals(TermName("scala"), preName)
assertEquals(TypeName("Some"), name)
assertEquals(SomeClass, sel.symbol)
case _ => fail(showRaw(ref))
}
}

@Test
def attributedRefToTopLevelMemberNotPrefixedByThis_t9473_b(): Unit = {
val ScalaRuntimeModule = symbolOf[ScalaRunTime.type].sourceModule
val ref = gen.mkAttributedRef(ScalaRuntimeModule)
assertEquals("scala.runtime.ScalaRunTime", ref.toString)
ref match {
case sel @ Select(Select(Ident(TermName("scala")), TermName("runtime")), TermName("ScalaRunTime")) =>
case _ => fail(showRaw(ref))
}
}
@Test
def attributedRefToTopLevelMemberNotPrefixedByThis_t9473_c(): Unit = {
val DummyImplicitClass = symbolOf[Predef.DummyImplicit]
val ref = gen.mkAttributedRef(DummyImplicitClass)
assertEquals("scala.Predef.DummyImplicit", ref.toString)
// ref match {
// case sel @ Select(Select(Ident(TermName("scala")), TermName("runtime")), TermName("ScalaRunTime")) =>
// case _ => fail(showRaw(ref))
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ class SymbolTableForUnitTesting extends SymbolTable {
}
phasesArray
}
lazy val treeInfo: scala.reflect.internal.TreeInfo{val global: SymbolTableForUnitTesting.this.type} = ???
lazy val treeInfo = new scala.reflect.internal.TreeInfo {
val global: SymbolTableForUnitTesting.this.type = SymbolTableForUnitTesting.this
}

val currentFreshNameCreator = new reflect.internal.util.FreshNameCreator

Expand Down