Skip to content

Commit 1de4fff

Browse files
zsxwinglrytz
authored andcommitted
SI-9397 Add "_root_" to "GenUtils.scalaFactoryCall" to avoid the scala package name conflits (scala#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.
1 parent fec54d6 commit 1de4fff

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

src/compiler/scala/reflect/reify/codegen/GenUtils.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ trait GenUtils {
5555
mirrorCall(TermName("" + prefix), args: _*)
5656

5757
def scalaFactoryCall(name: TermName, args: Tree*): Tree =
58-
call(s"scala.$name.apply", args: _*)
58+
call(s"_root_.scala.$name.apply", args: _*)
5959

6060
def scalaFactoryCall(name: String, args: Tree*): Tree =
6161
scalaFactoryCall(TermName(name), args: _*)

src/compiler/scala/reflect/reify/utils/NodePrinters.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ trait NodePrinters {
2828
var s = line substring 2
2929
s = s.replace(nme.UNIVERSE_PREFIX.toString, "")
3030
s = s.replace(".apply", "")
31-
s = "([^\"])scala\\.collection\\.immutable\\.".r.replaceAllIn(s, "$1")
31+
s = "([^\"])(_root_\\.)?scala\\.collection\\.immutable\\.".r.replaceAllIn(s, "$1")
3232
s = "List\\[List\\[.*?\\].*?\\]".r.replaceAllIn(s, "List")
3333
s = "List\\[.*?\\]".r.replaceAllIn(s, "List")
3434
s = s.replace("immutable.this.Nil", "List()")

test/files/pos/t9397.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package foo.scala
2+
3+
import scala.reflect.runtime.universe._
4+
5+
object Foo {
6+
7+
def bar[T: TypeTag]() {
8+
}
9+
10+
import foo._
11+
bar[String]()
12+
}

0 commit comments

Comments
 (0)