diff options
author | Shixiong Zhu <zsxwing@gmail.com> | 2016-05-11 12:53:21 -0700 |
---|---|---|
committer | Lukas Rytz <lukas.rytz@typesafe.com> | 2016-05-11 21:53:21 +0200 |
commit | 1de4fff089eaa6b280652dc8183a57162a8f2ad2 (patch) | |
tree | df71ecf1eecd5c9ef1f4a78f681440618015def2 | |
parent | fec54d6bb437280e74e4ec0286e42ae757b9b691 (diff) | |
download | scala-1de4fff089eaa6b280652dc8183a57162a8f2ad2.tar.gz scala-1de4fff089eaa6b280652dc8183a57162a8f2ad2.tar.bz2 scala-1de4fff089eaa6b280652dc8183a57162a8f2ad2.zip |
SI-9397 Add "_root_" to "GenUtils.scalaFactoryCall" to avoid the scala package name conflits (#5150)
When a user imports some package ending with `scala`, the macro expansion of TypeTag may not work because it uses `scala.collection.immutable.List` but it's overrided. This patch adds the `_root_` prefix to avoid the scala package name conflits. Of cause, after this fix, importing a package ending with `_root_` has the same issue. However, people rarely do that.
-rw-r--r-- | src/compiler/scala/reflect/reify/codegen/GenUtils.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/reflect/reify/utils/NodePrinters.scala | 2 | ||||
-rw-r--r-- | test/files/pos/t9397.scala | 12 |
3 files changed, 14 insertions, 2 deletions
diff --git a/src/compiler/scala/reflect/reify/codegen/GenUtils.scala b/src/compiler/scala/reflect/reify/codegen/GenUtils.scala index b5b0f93750..242e5d60b3 100644 --- a/src/compiler/scala/reflect/reify/codegen/GenUtils.scala +++ b/src/compiler/scala/reflect/reify/codegen/GenUtils.scala @@ -55,7 +55,7 @@ trait GenUtils { mirrorCall(TermName("" + prefix), args: _*) def scalaFactoryCall(name: TermName, args: Tree*): Tree = - call(s"scala.$name.apply", args: _*) + call(s"_root_.scala.$name.apply", args: _*) def scalaFactoryCall(name: String, args: Tree*): Tree = scalaFactoryCall(TermName(name), args: _*) diff --git a/src/compiler/scala/reflect/reify/utils/NodePrinters.scala b/src/compiler/scala/reflect/reify/utils/NodePrinters.scala index 3b91d28360..a5c4c7e0a3 100644 --- a/src/compiler/scala/reflect/reify/utils/NodePrinters.scala +++ b/src/compiler/scala/reflect/reify/utils/NodePrinters.scala @@ -28,7 +28,7 @@ trait NodePrinters { var s = line substring 2 s = s.replace(nme.UNIVERSE_PREFIX.toString, "") s = s.replace(".apply", "") - s = "([^\"])scala\\.collection\\.immutable\\.".r.replaceAllIn(s, "$1") + s = "([^\"])(_root_\\.)?scala\\.collection\\.immutable\\.".r.replaceAllIn(s, "$1") s = "List\\[List\\[.*?\\].*?\\]".r.replaceAllIn(s, "List") s = "List\\[.*?\\]".r.replaceAllIn(s, "List") s = s.replace("immutable.this.Nil", "List()") diff --git a/test/files/pos/t9397.scala b/test/files/pos/t9397.scala new file mode 100644 index 0000000000..3dbc6591d3 --- /dev/null +++ b/test/files/pos/t9397.scala @@ -0,0 +1,12 @@ +package foo.scala + +import scala.reflect.runtime.universe._ + +object Foo { + + def bar[T: TypeTag]() { + } + + import foo._ + bar[String]() +} |