Scala Programming Language
  1. Scala Programming Language
  2. SI-5742

incorrect reification of nested free types

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.0-M3
    • Fix Version/s: Scala 2.10.0-M3
    • Component/s: Reflection
    • Labels:
      None

      Description

      import scala.reflect.mirror._
      
      object Test extends App {
        def foo[T](a: T) = reify {
          val x1 = a
          val x2 = reify(a)
        }
      }
      
      reifying = 
      a
      Ident(newTermName("a"))
      reifee is located at: source-C:\Projects\Kepler\sandbox\Test.scala,line-6,offset=120
      prefix = scala.reflect.`package`.mirror
      [calculate phase]
      [reshape phase]
      [metalevels phase]
      [interlude]
      symbol table = <empty>
      reifee = 
      a
      Ident(newTermName("a"))
      [reify phase]
      Free term: value a(value)
      splicing T
      launching implicit search for scala.reflect.`package`.mirror.TypeTag[T]
      reifying = T
      prefix = scala.reflect.`package`.mirror
      splicing T
      splicing has been cancelled: spliceTypesEnabled = false
      Free type: type T (type)
      Filling in: type T (type)
      reified = {
        val $mr: scala.reflect.`package`.mirror.type = scala.reflect.`package`.mirror;
        val free$T1 = $mr.newFreeType("T", $mr.TypeBounds($mr.staticClass("scala.Nothing").asTypeConstructor, $mr.staticClass("scala.Any").asTypeConstructor), $mr.TypeTag[T](null, null), 8208L, "defined by foo in Test.scala:4:11");
        $mr.TypeTag[T]($mr.TypeRef($mr.NoPrefix, free$T1, scala.collection.immutable.List.apply()), Predef.this.classOf[Object])
      }
      implicit search has produced a result: {
        val $mr: reflect.mirror.type = scala.reflect.`package`.mirror;
        val free$T1: $mr.Symbol = $mr.newFreeType("T", $mr.TypeBounds.apply($mr.staticClass("scala.Nothing").asTypeConstructor, $mr.staticClass("scala.Any").asTypeConstructor), $mr.TypeTag.apply[T](null, null), 8208L, "defined by foo in Test.scala:4:11");
        $mr.TypeTag.apply[T]($mr.TypeRef.apply($mr.NoPrefix, free$T1, immutable.this.Nil), classOf[java.lang.Object])
      }
      inlined the splicee: $mr.TypeRef.apply($mr.NoPrefix, free$T1, immutable.this.Nil)
      splicing T
      cache hit: $mr.TypeRef.apply($mr.NoPrefix, free$T1, immutable.this.Nil)
      Filling in: type T (type)
      Filling in: value a (value)
      volatile splice, stripping off from cache: TypeTag[T]
      reified = {
        val $mr: scala.reflect.`package`.mirror.type = scala.reflect.`package`.mirror;
        val free$T1: $mr.Symbol = $mr.newFreeType("T", $mr.TypeBounds.apply($mr.staticClass("scala.Nothing").asTypeConstructor, $mr.staticClass("scala.Any").asTypeConstructor), $mr.TypeTag.apply[T](null, null), 8208L, "defined by foo in Test.scala:4:11");
        val free$a1 = $mr.newFreeTerm("a", $mr.TypeRef.apply($mr.NoPrefix, free$T1, immutable.this.Nil), a, 17592186052608L, "defined by foo in Test.scala:4:14");
        $mr.Expr[T]($mr.Ident(free$a1))($mr.TypeTag[T]($mr.TypeRef.apply($mr.NoPrefix, free$T1, immutable.this.Nil), Predef.this.classOf[Object]))
      }
      reifying = 
      {
        val x1: T = a;
        val x2: reflect.mirror.Expr[T] = {
          val $mr: reflect.mirror.type = scala.reflect.`package`.mirror;
          val free$T1: $mr.Symbol = $mr.newFreeType("T", $mr.TypeBounds.apply($mr.staticClass("scala.Nothing").asTypeConstructor, $mr.staticClass("scala.Any").asTypeConstructor), $mr.TypeTag.apply[T](null, null), 8208L, "defined by foo in Test.scala:4:11");
          val free$a1: $mr.Symbol = $mr.newFreeTerm("a", $mr.TypeRef.apply($mr.NoPrefix, free$T1, immutable.this.Nil), a, 17592186052608L, "defined by foo in Test.scala:4:14");
          $mr.Expr.apply[T]($mr.Ident(free$a1))($mr.TypeTag.apply[T]($mr.TypeRef.apply($mr.NoPrefix, free$T1, immutable.this.Nil), classOf[java.lang.Object]))
        };
        ()
      }
      Block(List(ValDef(Modifiers(), newTermName("x1"), TypeTree().setType(T), Ident(newTermName("a"))), ValDef(Modifiers(), newTermName("x2"), TypeTree().setType(reflect.mirror.Expr[T]), Block(List(ValDef(Modifiers(), newTermName("$mr"), TypeTree().setType(reflect.mirror.type), Select(Select(Select(Ident(newTermName("scala")), newTermName("reflect")), newTermName("package")), newTermName("mirror"))), ValDef(Modifiers(), newTermName("free$T1"), TypeTree().setType($mr.Symbol), Apply(Select(Ident(newTermName("$mr")), newTermName("newFreeType")), List(Literal(Constant("T")), Apply(Select(Select(Ident(newTermName("$mr")), newTermName("TypeBounds")), newTermName("apply")), List(Select(Apply(Select(Ident(newTermName("$mr")), newTermName("staticClass")), List(Literal(Constant("scala.Nothing")))), newTermName("asTypeConstructor")), Select(Apply(Select(Ident(newTermName("$mr")), newTermName("staticClass")), List(Literal(Constant("scala.Any")))), newTermName("asTypeConstructor")))), Apply(TypeApply(Select(Select(Ident(newTermName("$mr")), newTermName("TypeTag")), newTermName("apply")), List(TypeTree().setType(T))), List(Literal(Constant(null)), Literal(Constant(null)))), Literal(Constant(8208)), Literal(Constant("defined by foo in Test.scala:4:11"))))), ValDef(Modifiers(), newTermName("free$a1"), TypeTree().setType($mr.Symbol), Apply(Select(Ident(newTermName("$mr")), newTermName("newFreeTerm")), List(Literal(Constant("a")), Apply(Select(Select(Ident(newTermName("$mr")), newTermName("TypeRef")), newTermName("apply")), List(Select(Ident(newTermName("$mr")), newTermName("NoPrefix")), Ident(newTermName("free$T1")), Select(This(newTypeName("immutable")), newTermName("Nil")))), Ident(newTermName("a")), Literal(Constant(17592186052608)), Literal(Constant("defined by foo in Test.scala:4:14")))))), Apply(Apply(TypeApply(Select(Select(Ident(newTermName("$mr")), newTermName("Expr")), newTermName("apply")), List(TypeTree().setType(T))), List(Apply(Select(Ident(newTermName("$mr")), newTermName("Ident")), List(Ident(newTermName("free$a1")))))), List(Apply(TypeApply(Select(Select(Ident(newTermName("$mr")), newTermName("TypeTag")), newTermName("apply")), List(TypeTree().setType(T))), List(Apply(Select(Select(Ident(newTermName("$mr")), newTermName("TypeRef")), newTermName("apply")), List(Select(Ident(newTermName("$mr")), newTermName("NoPrefix")), Ident(newTermName("free$T1")), Select(This(newTypeName("immutable")), newTermName("Nil")))), Literal(Constant(Object))))))))), Literal(Constant(())))
      reifee is located at: source-C:\Projects\Kepler\sandbox\Test.scala,line-4,offset=84
      prefix = scala.reflect.`package`.mirror
      [calculate phase]
      boundSym: value x1 of type T
      boundSym: value x2 of type reflect.mirror.Expr[T]
      boundSym: value $mr of type reflect.mirror.type
      boundSym: value free$T1 of type $mr.Symbol
      boundSym: value free$a1 of type $mr.Symbol
      [reshape phase]
      TypeTree, non-essential: T (AbstractTypeRef)
      verdict: discarded
      TypeTree, non-essential: reflect.mirror.Expr[T] (TypeRef)
      verdict: discarded
      TypeTree, essential: reflect.mirror.type (SingleType)
      verdict: rolled back to original scala.reflect.`package`.mirror.type
      TypeTree, non-essential: $mr.Symbol (AbstractTypeRef)
      verdict: discarded
      discarding TypeApply: $mr.TypeTag.apply[T]
      TypeTree, non-essential: $mr.Symbol (AbstractTypeRef)
      verdict: discarded
      discarding TypeApply: $mr.Expr.apply[T]
      discarding TypeApply: $mr.TypeTag.apply[T]
      [metalevels phase]
      [interlude]
      symbol table = <empty>
      reifee = 
      {
        val x1: T = a;
        val x2: reflect.mirror.Expr[T] = {
          val $mr: reflect.mirror.type = scala.reflect.`package`.mirror;
          val free$T1: $mr.Symbol = $mr.newFreeType("T", $mr.TypeBounds.apply($mr.staticClass("scala.Nothing").asTypeConstructor, $mr.staticClass("scala.Any").asTypeConstructor), $mr.TypeTag.apply(null, null), 8208L, "defined by foo in Test.scala:4:11");
          val free$a1: $mr.Symbol = $mr.newFreeTerm("a", $mr.TypeRef.apply($mr.NoPrefix, free$T1, immutable.this.Nil), a, 17592186052608L, "defined by foo in Test.scala:4:14");
          $mr.Expr.apply($mr.Ident(free$a1))($mr.TypeTag.apply($mr.TypeRef.apply($mr.NoPrefix, free$T1, immutable.this.Nil), classOf[java.lang.Object]))
        };
        ()
      }
      Block(List(ValDef(Modifiers(), newTermName("x1"), TypeTree(), Ident(newTermName("a"))), ValDef(Modifiers(), newTermName("x2"), TypeTree(), Block(List(ValDef(Modifiers(), newTermName("$mr"), SingletonTypeTree(Select(Select(Select(Ident(newTermName("scala")), newTermName("reflect")), newTermName("package")), newTermName("mirror"))), Select(Select(Select(Ident(newTermName("scala")), newTermName("reflect")), newTermName("package")), newTermName("mirror"))), ValDef(Modifiers(), newTermName("free$T1"), TypeTree(), Apply(Select(Ident(newTermName("$mr")), newTermName("newFreeType")), List(Literal(Constant("T")), Apply(Select(Select(Ident(newTermName("$mr")), newTermName("TypeBounds")), newTermName("apply")), List(Select(Apply(Select(Ident(newTermName("$mr")), newTermName("staticClass")), List(Literal(Constant("scala.Nothing")))), newTermName("asTypeConstructor")), Select(Apply(Select(Ident(newTermName("$mr")), newTermName("staticClass")), List(Literal(Constant("scala.Any")))), newTermName("asTypeConstructor")))), Apply(Select(Select(Ident(newTermName("$mr")), newTermName("TypeTag")), newTermName("apply")), List(Literal(Constant(null)), Literal(Constant(null)))), Literal(Constant(8208)), Literal(Constant("defined by foo in Test.scala:4:11"))))), ValDef(Modifiers(), newTermName("free$a1"), TypeTree(), Apply(Select(Ident(newTermName("$mr")), newTermName("newFreeTerm")), List(Literal(Constant("a")), Apply(Select(Select(Ident(newTermName("$mr")), newTermName("TypeRef")), newTermName("apply")), List(Select(Ident(newTermName("$mr")), newTermName("NoPrefix")), Ident(newTermName("free$T1")), Select(This(newTypeName("immutable")), newTermName("Nil")))), Ident(newTermName("a")), Literal(Constant(17592186052608)), Literal(Constant("defined by foo in Test.scala:4:14")))))), Apply(Apply(Select(Select(Ident(newTermName("$mr")), newTermName("Expr")), newTermName("apply")), List(Apply(Select(Ident(newTermName("$mr")), newTermName("Ident")), List(Ident(newTermName("free$a1")))))), List(Apply(Select(Select(Ident(newTermName("$mr")), newTermName("TypeTag")), newTermName("apply")), List(Apply(Select(Select(Ident(newTermName("$mr")), newTermName("TypeRef")), newTermName("apply")), List(Select(Ident(newTermName("$mr")), newTermName("NoPrefix")), Ident(newTermName("free$T1")), Select(This(newTypeName("immutable")), newTermName("Nil")))), Literal(Constant(Object))))))))), Literal(Constant(())))
      [reify phase]
      Free term: value a(value)
      splicing T
      launching implicit search for scala.reflect.`package`.mirror.TypeTag[T]
      reifying = T
      prefix = scala.reflect.`package`.mirror
      splicing T
      splicing has been cancelled: spliceTypesEnabled = false
      Free type: type T (type)
      Filling in: type T (type)
      reified = {
        val $mr: scala.reflect.`package`.mirror.type = scala.reflect.`package`.mirror;
        val free$T2 = $mr.newFreeType("T", $mr.TypeBounds($mr.staticClass("scala.Nothing").asTypeConstructor, $mr.staticClass("scala.Any").asTypeConstructor), $mr.TypeTag[T](null, null), 8208L, "defined by foo in Test.scala:4:11");
        $mr.TypeTag[T]($mr.TypeRef($mr.NoPrefix, free$T2, scala.collection.immutable.List.apply()), Predef.this.classOf[Object])
      }
      implicit search has produced a result: {
        val $mr: reflect.mirror.type = scala.reflect.`package`.mirror;
        val free$T2: $mr.Symbol = $mr.newFreeType("T", $mr.TypeBounds.apply($mr.staticClass("scala.Nothing").asTypeConstructor, $mr.staticClass("scala.Any").asTypeConstructor), $mr.TypeTag.apply[T](null, null), 8208L, "defined by foo in Test.scala:4:11");
        $mr.TypeTag.apply[T]($mr.TypeRef.apply($mr.NoPrefix, free$T2, immutable.this.Nil), classOf[java.lang.Object])
      }
      inlined the splicee: $mr.TypeRef.apply($mr.NoPrefix, free$T2, immutable.this.Nil)
      Test.scala:4: error: exception during macro expansion: 
      java.lang.Error: unsupported free type def: $mr.TypeTag.apply(null, null)
      Apply(Select(Select(Ident(newTermName("$mr")), newTermName("TypeTag")), newTermName("apply")), List(Literal(Constant(null)), Literal(Constant(null))))
        at scala.reflect.internal.TreeInfo$FreeTypeDef$.unapply(TreeInfo.scala:686)
        at scala.reflect.internal.TreeInfo$FreeDef$.unapply(TreeInfo.scala:652)
        at scala.reflect.reify.codegen.Trees$class.reifyTree(Trees.scala:50)
        at scala.reflect.reify.Reifier.reifyTree(Reifier.scala:14)
        at scala.reflect.reify.phases.Reify$$anonfun$reify$1.apply(Reify.scala:52)
        at scala.reflect.reify.phases.Reify$$anonfun$reify$1.apply(Reify.scala:45)
        at scala.reflect.reify.phases.Reify$reifyStack$.push(Reify.scala:34)
        at scala.reflect.reify.phases.Reify$class.reify(Reify.scala:45)
        at scala.reflect.reify.Reifier.reify(Reifier.scala:14)
        at scala.reflect.reify.codegen.Util$$anonfun$reifyList$1.apply(Util.scala:18)
        at scala.reflect.reify.codegen.Util$$anonfun$reifyList$1.apply(Util.scala:18)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:237)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:237)
        at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
        at scala.collection.immutable.List.foreach(List.scala:77)
        at scala.collection.TraversableLike$class.map(TraversableLike.scala:237)
        at scala.collection.AbstractTraversable.map(Traversable.scala:105)
        at scala.reflect.reify.codegen.Util$class.reifyList(Util.scala:18)
        at scala.reflect.reify.Reifier.reifyList(Reifier.scala:14)
        at scala.reflect.reify.phases.Reify$$anonfun$reify$1.apply(Reify.scala:58)
        at scala.reflect.reify.phases.Reify$$anonfun$reify$1.apply(Reify.scala:45)
        at scala.reflect.reify.phases.Reify$reifyStack$.push(Reify.scala:34)
        at scala.reflect.reify.phases.Reify$class.reify(Reify.scala:45)
        at scala.reflect.reify.Reifier.reify(Reifier.scala:14)
        at scala.reflect.reify.codegen.Util$$anonfun$reifyProduct$2.apply(Util.scala:26)
        at scala.reflect.reify.codegen.Util$$anonfun$reifyProduct$2.apply(Util.scala:26)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:237)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:237)
        at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
        at scala.collection.immutable.List.foreach(List.scala:77)
        at scala.collection.TraversableLike$class.map(TraversableLike.scala:237)
        at scala.collection.AbstractTraversable.map(Traversable.scala:105)
        at scala.reflect.reify.codegen.Util$class.reifyProduct(Util.scala:26)
        at scala.reflect.reify.Reifier.reifyProduct(Reifier.scala:14)
        at scala.reflect.reify.codegen.Util$class.reifyProduct(Util.scala:21)
        at scala.reflect.reify.Reifier.reifyProduct(Reifier.scala:14)
        at scala.reflect.reify.codegen.Trees$class.reifyTree(Trees.scala:87)
        at scala.reflect.reify.Reifier.reifyTree(Reifier.scala:14)
        at scala.reflect.reify.phases.Reify$$anonfun$reify$1.apply(Reify.scala:52)
        at scala.reflect.reify.phases.Reify$$anonfun$reify$1.apply(Reify.scala:45)
        at scala.reflect.reify.phases.Reify$reifyStack$.push(Reify.scala:34)
        at scala.reflect.reify.phases.Reify$class.reify(Reify.scala:45)
        at scala.reflect.reify.Reifier.reify(Reifier.scala:14)
        at scala.reflect.reify.codegen.Util$$anonfun$reifyProduct$2.apply(Util.scala:26)
        at scala.reflect.reify.codegen.Util$$anonfun$reifyProduct$2.apply(Util.scala:26)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:237)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:237)
        at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
        at scala.collection.immutable.List.foreach(List.scala:77)
        at scala.collection.TraversableLike$class.map(TraversableLike.scala:237)
        at scala.collection.AbstractTraversable.map(Traversable.scala:105)
        at scala.reflect.reify.codegen.Util$class.reifyProduct(Util.scala:26)
        at scala.reflect.reify.Reifier.reifyProduct(Reifier.scala:14)
        at scala.reflect.reify.codegen.Util$class.reifyProduct(Util.scala:21)
        at scala.reflect.reify.Reifier.reifyProduct(Reifier.scala:14)
        at scala.reflect.reify.codegen.Trees$class.reifyTree(Trees.scala:87)
        at scala.reflect.reify.Reifier.reifyTree(Reifier.scala:14)
        at scala.reflect.reify.phases.Reify$$anonfun$reify$1.apply(Reify.scala:52)
        at scala.reflect.reify.phases.Reify$$anonfun$reify$1.apply(Reify.scala:45)
        at scala.reflect.reify.phases.Reify$reifyStack$.push(Reify.scala:34)
        at scala.reflect.reify.phases.Reify$class.reify(Reify.scala:45)
        at scala.reflect.reify.Reifier.reify(Reifier.scala:14)
        at scala.reflect.reify.codegen.Util$$anonfun$reifyList$1.apply(Util.scala:18)
        at scala.reflect.reify.codegen.Util$$anonfun$reifyList$1.apply(Util.scala:18)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:237)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:237)
        at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
        at scala.collection.immutable.List.foreach(List.scala:77)
        at scala.collection.TraversableLike$class.map(TraversableLike.scala:237)
        at scala.collection.AbstractTraversable.map(Traversable.scala:105)
        at scala.reflect.reify.codegen.Util$class.reifyList(Util.scala:18)
        at scala.reflect.reify.Reifier.reifyList(Reifier.scala:14)
        at scala.reflect.reify.phases.Reify$$anonfun$reify$1.apply(Reify.scala:58)
        at scala.reflect.reify.phases.Reify$$anonfun$reify$1.apply(Reify.scala:45)
        at scala.reflect.reify.phases.Reify$reifyStack$.push(Reify.scala:34)
        at scala.reflect.reify.phases.Reify$class.reify(Reify.scala:45)
        at scala.reflect.reify.Reifier.reify(Reifier.scala:14)
        at scala.reflect.reify.codegen.Util$$anonfun$reifyProduct$2.apply(Util.scala:26)
        at scala.reflect.reify.codegen.Util$$anonfun$reifyProduct$2.apply(Util.scala:26)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:237)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:237)
        at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
        at scala.collection.immutable.List.foreach(List.scala:77)
        at scala.collection.TraversableLike$class.map(TraversableLike.scala:237)
        at scala.collection.AbstractTraversable.map(Traversable.scala:105)
        at scala.reflect.reify.codegen.Util$class.reifyProduct(Util.scala:26)
        at scala.reflect.reify.Reifier.reifyProduct(Reifier.scala:14)
        at scala.reflect.reify.codegen.Util$class.reifyProduct(Util.scala:21)
        at scala.reflect.reify.Reifier.reifyProduct(Reifier.scala:14)
        at scala.reflect.reify.codegen.Trees$class.reifyTree(Trees.scala:87)
        at scala.reflect.reify.Reifier.reifyTree(Reifier.scala:14)
        at scala.reflect.reify.phases.Reify$$anonfun$reify$1.apply(Reify.scala:52)
        at scala.reflect.reify.phases.Reify$$anonfun$reify$1.apply(Reify.scala:45)
        at scala.reflect.reify.phases.Reify$reifyStack$.push(Reify.scala:34)
        at scala.reflect.reify.phases.Reify$class.reify(Reify.scala:45)
        at scala.reflect.reify.Reifier.reify(Reifier.scala:14)
        at scala.reflect.reify.Phases$$anonfun$mkReificationPipeline$1.apply(Phases.scala:38)
        at scala.reflect.reify.Phases$$anonfun$mkReificationPipeline$1.apply(Phases.scala:18)
        at scala.reflect.reify.Reifier.liftedTree1$1(Reifier.scala:61)
        at scala.reflect.reify.Reifier.reified(Reifier.scala:47)
        at scala.reflect.reify.package$.reifyTree(package.scala:26)
        at scala.reflect.makro.runtime.Reifiers$class.reifyTree(Reifiers.scala:18)
        at scala.reflect.makro.runtime.Context.reifyTree(Context.scala:6)
        at scala.reflect.makro.internal.Utils$$anonfun$2.apply(Utils.scala:117)
        at scala.reflect.makro.internal.Utils$$anonfun$2.apply(Utils.scala:117)
        at scala.reflect.makro.internal.Utils.translatingReificationErrors(Utils.scala:123)
        at scala.reflect.makro.internal.Utils.materializeExpr(Utils.scala:117)
        at scala.reflect.api.Universe$.reify(Universe.scala:69)
      
        def foo[T](a: T) = reify {
                                 ^
      one error found
      

        Activity

        Show
        Eugene Burmako added a comment - Fixed in https://github.com/scala/scala/commit/6355d1a0b825c99560d4ccec1a8769f7421b1a71

          People

          • Assignee:
            Eugene Burmako
            Reporter:
            Eugene Burmako
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development