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

@annotation(typeOf[String]) crashes in pickler with AssertionError

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.1, Scala 2.11.0-M2
    • Fix Version/s: Scala 2.10.2-RC1
    • Component/s: Misc Compiler
    • Labels:
    • Environment:

      MacOSX 10.8.3

      Description

      Reproduce code:

      import scala.annotation.StaticAnnotation
      import scala.reflect.runtime.universe._
      
      final class foo(t:Any) extends StaticAnnotation
      trait OperationMapping{
        @foo(typeOf[String]) def bar : Int
      }
      

      Expected result:
      compiles fine.

      Actual Result

      error: uncaught exception during compilation: java.lang.AssertionError
      error: java.lang.AssertionError: assertion failed: 
           while compiling: pickleTypeOfString.scala
              during phase: pickler
           library version: version 2.10.1
          compiler version: version 2.10.1
        reconstructed args: 
      
        last tree to typer: EmptyTree
                    symbol: null
         symbol definition: null
                       tpe: <notype>
             symbol owners: 
            context owners: trait OperationMapping -> package <empty>
      
      == Enclosing template or block ==
      
      ClassDef( // abstract trait OperationMapping extends AnyRef
        <interface> abstract <defaultparam/trait>
        "OperationMapping"
        []
        Template( // val <local OperationMapping>: <notype> in trait OperationMapping, tree.tpe=OperationMapping
          "java.lang.Object" // parents
          ValDef(
            private
            "_"
            <tpt>
            <empty>
          )
          DefDef( // def bar: Int in trait OperationMapping
            <method> <deferred> @{ foo(scala.reflect.runtime.`package`.universe.typeOf[String]({
        val $u: reflect.runtime.universe.type = scala.reflect.runtime.`package`.universe;
        val $m: $u.Mirror = scala.reflect.runtime.`package`.universe.runtimeMirror(classOf[OperationMapping].getClassLoader());
        $u.TypeTag.apply[String]($m, {
          final class $typecreator1 extends TypeCreator {
            def <init>(): $typecreator1 = {
              $typecreator1.super.<init>();
              ()
            };
            def apply[U >: Nothing <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.Mirror[U]): U#Type = {
              val $u: U = $m$untyped.universe;
              val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror];
              $u.TypeRef.apply($u.SingleType.apply($u.ThisType.apply($m.staticPackage("scala").asModule.moduleClass), $m.staticModule("scala.Predef")), $u.build.selectType($m.staticModule("scala.Predef").asModule.moduleClass, "String"), immutable.this.Nil)
            }
          };
          new $typecreator1()
        })
      })) }
            "bar"
            []
            Nil
            <tpt> // tree.tpe=Int
            <empty>
          )
        )
      )
      
      == Expanded type of tree ==
      
      <notype>
      
      
      	at scala.tools.nsc.symtab.classfile.Pickler$Pickle.writeArray(Pickler.scala:1107)
      	at scala.tools.nsc.symtab.classfile.Pickler$PicklePhase.scala$tools$nsc$symtab$classfile$Pickler$PicklePhase$$pickle$1(Pickler.scala:56)
      	at scala.tools.nsc.symtab.classfile.Pickler$PicklePhase.scala$tools$nsc$symtab$classfile$Pickler$PicklePhase$$pickle$1(Pickler.scala:50)
      	at scala.tools.nsc.symtab.classfile.Pickler$PicklePhase.apply(Pickler.scala:81)
      	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:463)
      	at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:430)
      	at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:430)
      	at scala.collection.Iterator$class.foreach(Iterator.scala:727)
      	at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
      	at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:430)
      	at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1582)
      	at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1556)
      	at scala.tools.nsc.Global$Run.compileSources(Global.scala:1552)
      	at scala.tools.nsc.Global$Run.compile(Global.scala:1661)
      	at scala.tools.nsc.Driver.doCompile(Driver.scala:33)
      	at scala.tools.nsc.Main$.doCompile(Main.scala:79)
      	at scala.tools.nsc.Driver.process(Driver.scala:54)
      	at scala.tools.nsc.Driver.main(Driver.scala:67)
      	at scala.tools.nsc.Main.main(Main.scala)
      
      Exception in thread "main" java.lang.AssertionError: assertion failed: 
           while compiling: pickleTypeOfString.scala
              during phase: pickler
           library version: version 2.10.1
          compiler version: version 2.10.1
        reconstructed args: 
      
        last tree to typer: EmptyTree
                    symbol: null
         symbol definition: null
                       tpe: <notype>
             symbol owners: 
            context owners: trait OperationMapping -> package <empty>
      
      == Enclosing template or block ==
      
      ClassDef( // abstract trait OperationMapping extends AnyRef
        <interface> abstract <defaultparam/trait>
        "OperationMapping"
        []
        Template( // val <local OperationMapping>: <notype> in trait OperationMapping, tree.tpe=OperationMapping
          "java.lang.Object" // parents
          ValDef(
            private
            "_"
            <tpt>
            <empty>
          )
          DefDef( // def bar: Int in trait OperationMapping
            <method> <deferred> @{ foo(scala.reflect.runtime.`package`.universe.typeOf[String]({
        val $u: reflect.runtime.universe.type = scala.reflect.runtime.`package`.universe;
        val $m: $u.Mirror = scala.reflect.runtime.`package`.universe.runtimeMirror(classOf[OperationMapping].getClassLoader());
        $u.TypeTag.apply[String]($m, {
          final class $typecreator1 extends TypeCreator {
            def <init>(): $typecreator1 = {
              $typecreator1.super.<init>();
              ()
            };
            def apply[U >: Nothing <: scala.reflect.api.Universe with Singleton]($m$untyped: scala.reflect.api.Mirror[U]): U#Type = {
              val $u: U = $m$untyped.universe;
              val $m: $u.Mirror = $m$untyped.asInstanceOf[$u.Mirror];
              $u.TypeRef.apply($u.SingleType.apply($u.ThisType.apply($m.staticPackage("scala").asModule.moduleClass), $m.staticModule("scala.Predef")), $u.build.selectType($m.staticModule("scala.Predef").asModule.moduleClass, "String"), immutable.this.Nil)
            }
          };
          new $typecreator1()
        })
      })) }
            "bar"
            []
            Nil
            <tpt> // tree.tpe=Int
            <empty>
          )
        )
      )
      
      == Expanded type of tree ==
      
      <notype>
      
      
      	at scala.tools.nsc.symtab.classfile.Pickler$Pickle.writeArray(Pickler.scala:1107)
      	at scala.tools.nsc.symtab.classfile.Pickler$PicklePhase.scala$tools$nsc$symtab$classfile$Pickler$PicklePhase$$pickle$1(Pickler.scala:56)
      	at scala.tools.nsc.symtab.classfile.Pickler$PicklePhase.scala$tools$nsc$symtab$classfile$Pickler$PicklePhase$$pickle$1(Pickler.scala:50)
      	at scala.tools.nsc.symtab.classfile.Pickler$PicklePhase.apply(Pickler.scala:81)
      	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:463)
      	at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:430)
      	at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:430)
      	at scala.collection.Iterator$class.foreach(Iterator.scala:727)
      	at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
      	at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:430)
      	at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1582)
      	at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1556)
      	at scala.tools.nsc.Global$Run.compileSources(Global.scala:1552)
      	at scala.tools.nsc.Global$Run.compile(Global.scala:1661)
      	at scala.tools.nsc.Driver.doCompile(Driver.scala:33)
      	at scala.tools.nsc.Main$.doCompile(Main.scala:79)
      	at scala.tools.nsc.Driver.process(Driver.scala:54)
      	at scala.tools.nsc.Driver.main(Driver.scala:67)
      	at scala.tools.nsc.Main.main(Main.scala)
      

        Activity

        Hide
        Paul Phillips added a comment -

        Minimized. Unrelated to reflection, actually due to the "tree pickler" being undocumented, untested, and carrying heavy duplication. We should not be depending on that code.

        class foo(x: Any) extends annotation.StaticAnnotation
        @foo(new AnyRef { }) trait A
        
        Show
        Paul Phillips added a comment - Minimized. Unrelated to reflection, actually due to the "tree pickler" being undocumented, untested, and carrying heavy duplication. We should not be depending on that code. class foo(x: Any) extends annotation.StaticAnnotation @foo(new AnyRef { }) trait A
        Show
        Paul Phillips added a comment - https://github.com/scala/scala/pull/2458
        Hide
        Christopher Vogt added a comment -

        this is an issue for slick, so we should get it in 2.10

        Show
        Christopher Vogt added a comment - this is an issue for slick, so we should get it in 2.10

          People

          • Assignee:
            Paul Phillips
            Reporter:
            Christopher Vogt
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development