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

typeTag fails when non-root scala package in scope #9397

Closed
scabug opened this issue Jul 14, 2015 · 2 comments
Closed

typeTag fails when non-root scala package in scope #9397

scabug opened this issue Jul 14, 2015 · 2 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Jul 14, 2015

If a package named scala that is not the root scala package is in scope, root.scala.reflect.runtime.universe.typeTag fail with a "No TypeTag available for T" exception, where T is the type argument. An example of T is String. I suspect that other reflection methods have the same problem.

The attached project demonstrates the problem.

@scabug
Copy link
Author

scabug commented Jul 14, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9397?orig=1
Reporter: Jeff Shaw (shawjef3)
Affected Versions: 2.10.5, 2.11.7
Attachments:

@scabug
Copy link
Author

scabug commented Jul 21, 2015

@retronym said (edited on Jul 21, 2015 12:32:39 AM UTC):

% cat sandbox/test.scala

class C {
  type scala
  object scala
  def test {
    implicitly[reflect.runtime.universe.TypeTag[String]]
  }

}

%scalac -Ydebug -Ymacro-debug-verbose sandbox/test.scala
[running phase parser on test.scala]
[running phase namer on test.scala]
[running phase packageobjects on test.scala]
[running phase typer on test.scala]
macroExpand: expander = scala.tools.nsc.typechecker.Macros$DefMacroExpander@68be2bc2, expandee = Apply[1](TypeApply[2](Select[3](This[4](typeNames.PACKAGE), TermName("materializeTypeTag")#9691), List(TypeTree[5]())), List(Select[6](Select[7](Select[8](Select[9](This[10](TypeName("scala")), scala.reflect#2775), scala.reflect.runtime#2961), scala.reflect.runtime.package#14945), TermName("universe")#15044)))
[1] TypeRef(SingleType(SingleType(SingleType(SingleType(ThisType(scala#27), scala.reflect#2775), scala.reflect.runtime#2961), scala.reflect.runtime.package#14945), TermName("universe")#15044), TypeName("TypeTag")#11505, List(TypeRef(SingleType(ThisType(scala#27), scala.Predef#1781), TypeName("String")#7839, List())))
[2] MethodType(List(TermName("u")#9692), TypeRef(SingleType(NoPrefix, TermName("u")#9692), TypeName("TypeTag")#11505, List(TypeRef(SingleType(ThisType(scala#27), scala.Predef#1781), TypeName("String")#7839, List()))))
[3] PolyType(List(TypeName("T")#9693), MethodType(List(TermName("u")#9692), TypeRef(SingleType(NoPrefix, TermName("u")#9692), TypeName("TypeTag")#11505, List(TypeRef(NoPrefix, TypeName("T")#9693, List())))))
[4] ThisType(scala.reflect.api.package#9545)
[5] TypeRef(SingleType(ThisType(scala#27), scala.Predef#1781), TypeName("String")#7839, List())
[6] SingleType(SingleType(SingleType(SingleType(ThisType(scala#27), scala.reflect#2775), scala.reflect.runtime#2961), scala.reflect.runtime.package#14945), TermName("universe")#15044)
[7] SingleType(SingleType(SingleType(ThisType(scala#27), scala.reflect#2775), scala.reflect.runtime#2961), scala.reflect.runtime.package#14945)
[8] SingleType(SingleType(ThisType(scala#27), scala.reflect#2775), scala.reflect.runtime#2961)
[9] SingleType(ThisType(scala#27), scala.reflect#2775)
[10] ThisType(scala#27), desugared = ()
looking for macro implementation: term macro materializeTypeTag
macro expansion is serviced by a fast track
calculateUndetparams: Set()
performing macro expansion `package`.this.materializeTypeTag[String](scala.this.reflect.runtime.`package`.universe) at source-/Users/jason/code/scala3/sandbox/test.scala,line-6,offset=66
context: MacroContext(materializeTypeTag@source-/Users/jason/code/scala3/sandbox/test.scala,line-6,offset=66 +0)
prefix: `package`.this
targs: List(String)
argss: List(List(scala.this.reflect.runtime.`package`.universe))
paramss: List(List(value u))
macroImplArgs: List(scala.this.reflect.runtime.`package`.universe)
inferring implicit value of type api.this.Universe#TypeTag[String], macros = false
typechecking {
  val $u: scala.this.reflect.runtime.`package`.universe.type = scala.this.reflect.runtime.`package`.universe;
  val $m: $u.Mirror = scala.this.reflect.runtime.`package`.universe.runtimeMirror(Predef.this.classOf[<empty>.this.C].getClassLoader);
  $u.TypeTag.apply[String]($m, {
    final class $typecreator1 extends TypeCreator {
      def <init>() = {
        super.<init>();
        ()
      };
      def apply[U >: Nothing <: Universe with Singleton]($m$untyped: Mirror[U]): U#Type = {
        val $u: U = $m$untyped.universe;
        val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror];
        $u.internal.reificationSupport.TypeRef($u.internal.reificationSupport.SingleType($u.internal.reificationSupport.ThisType($m.staticPackage("scala").asModule.moduleClass), $m.staticModule("scala.Predef")), $u.internal.reificationSupport.selectType($m.staticModule("scala.Predef").asModule.moduleClass, "String"), scala.collection.immutable.List.apply())
      }
    };
    new $typecreator1.<init>()
  })
} with expected type ?, implicit views = true, macros = true
value collection is not a member of object C.this.scala
macro expansion has been aborted
macro expansion has failed: No TypeTag available for String
macroExpand: expander = scala.tools.nsc.typechecker.Macros$DefMacroExpander@6a396c1e, expandee = Apply[1](TypeApply[2](Select[3](This[4](typeNames.PACKAGE), TermName("materializeTypeTag")#9691), List(TypeTree[5]())), List(Select[6](Select[7](Select[8](Select[9](This[10](TypeName("scala")), scala.reflect#2775), scala.reflect.runtime#2961), scala.reflect.runtime.package#14945), TermName("universe")#15044)))
[1] TypeRef(SingleType(SingleType(SingleType(SingleType(ThisType(scala#27), scala.reflect#2775), scala.reflect.runtime#2961), scala.reflect.runtime.package#14945), TermName("universe")#15044), TypeName("TypeTag")#11505, List(TypeRef(SingleType(ThisType(scala#27), scala.Predef#1781), TypeName("String")#7839, List())))
[2] MethodType(List(TermName("u")#9692), TypeRef(SingleType(NoPrefix, TermName("u")#9692), TypeName("TypeTag")#11505, List(TypeRef(SingleType(ThisType(scala#27), scala.Predef#1781), TypeName("String")#7839, List()))))
[3] PolyType(List(TypeName("T")#9693), MethodType(List(TermName("u")#9692), TypeRef(SingleType(NoPrefix, TermName("u")#9692), TypeName("TypeTag")#11505, List(TypeRef(NoPrefix, TypeName("T")#9693, List())))))
[4] ThisType(scala.reflect.api.package#9545)
[5] TypeRef(SingleType(ThisType(scala#27), scala.Predef#1781), TypeName("String")#7839, List())
[6] SingleType(SingleType(SingleType(SingleType(ThisType(scala#27), scala.reflect#2775), scala.reflect.runtime#2961), scala.reflect.runtime.package#14945), TermName("universe")#15044)
[7] SingleType(SingleType(SingleType(ThisType(scala#27), scala.reflect#2775), scala.reflect.runtime#2961), scala.reflect.runtime.package#14945)
[8] SingleType(SingleType(ThisType(scala#27), scala.reflect#2775), scala.reflect.runtime#2961)
[9] SingleType(ThisType(scala#27), scala.reflect#2775)
[10] ThisType(scala#27), desugared = ()
looking for macro implementation: term macro materializeTypeTag
macro expansion is serviced by a fast track
calculateUndetparams: Set()
performing macro expansion `package`.this.materializeTypeTag[String](scala.this.reflect.runtime.`package`.universe) at source-/Users/jason/code/scala3/sandbox/test.scala,line-6,offset=66
context: MacroContext(materializeTypeTag@source-/Users/jason/code/scala3/sandbox/test.scala,line-6,offset=66 +0)
prefix: `package`.this
targs: List(String)
argss: List(List(scala.this.reflect.runtime.`package`.universe))
paramss: List(List(value u))
macroImplArgs: List(scala.this.reflect.runtime.`package`.universe)
inferring implicit value of type api.this.Universe#TypeTag[String], macros = false
typechecking {
  val $u: scala.this.reflect.runtime.`package`.universe.type = scala.this.reflect.runtime.`package`.universe;
  val $m: $u.Mirror = scala.this.reflect.runtime.`package`.universe.runtimeMirror(Predef.this.classOf[<empty>.this.C].getClassLoader);
  $u.TypeTag.apply[String]($m, {
    final class $typecreator2 extends TypeCreator {
      def <init>() = {
        super.<init>();
        ()
      };
      def apply[U >: Nothing <: Universe with Singleton]($m$untyped: Mirror[U]): U#Type = {
        val $u: U = $m$untyped.universe;
        val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror];
        $u.internal.reificationSupport.TypeRef($u.internal.reificationSupport.SingleType($u.internal.reificationSupport.ThisType($m.staticPackage("scala").asModule.moduleClass), $m.staticModule("scala.Predef")), $u.internal.reificationSupport.selectType($m.staticModule("scala.Predef").asModule.moduleClass, "String"), scala.collection.immutable.List.apply())
      }
    };
    new $typecreator2.<init>()
  })
} with expected type ?, implicit views = true, macros = true
value collection is not a member of object C.this.scala
macro expansion has been aborted
macro expansion has failed: No TypeTag available for String
sandbox/test.scala:6: error: No TypeTag available for String
    implicitly[reflect.runtime.universe.TypeTag[String]]
              ^
sandbox/test.scala:6: error: [ suppressed ] not enough arguments for method implicitly: (implicit <param> e: scala.this.reflect.runtime.universe.TypeTag[String])scala.this.reflect.runtime.universe.TypeTag[String].
Unspecified value parameter e.
    implicitly[reflect.runtime.universe.TypeTag[String]]
              ^
two errors found

I suspect this is the first culprit:

git diff head -- src/compiler/scala/reflect/
diff --git a/src/compiler/scala/reflect/reify/codegen/GenUtils.scala b/src/compiler/scala/reflect/reify/codegen/GenUtils.scala
index b5b0f93..242e5d6 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: _*)

@scabug scabug closed this as completed May 11, 2016
@scabug scabug added this to the 2.12.0-M5 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants