scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

Local dummy symbols created by named args in annotation wreak havoc under separate compilation #8868

Closed scabug closed 10 years ago

scabug commented 10 years ago
% tail -n100 sandbox/{test,test1}.scala
==> sandbox/test.scala <==
class C

@deprecated(since = "2.4.0", message = "Either use HttpRequestHandler, or have the router injected")
trait T {
  def foo = implicitly[reflect.ClassTag[C]]
}

==> sandbox/test1.scala <==
case class Sub() extends T {

}

% scalac-hash v2.11.2 sandbox/test.scala && scalac-hash v2.11.2 -Ydebug sandbox/test1.scala
sandbox/test.scala:3: warning: Usage of named or default arguments transformed this annotation
constructor call into a block. The corresponding AnnotationInfo
will contain references to local values and default getters instead
of the actual argument trees
@deprecated(since = "2.4.0", message = "Either use HttpRequestHandler, or have the router injected")
 ^
one warning found
[running phase parser on test1.scala]
[running phase namer on test1.scala]
[running phase packageobjects on test1.scala]
[running phase typer on test1.scala]
warning: !!! creating stub symbol to defer error: bad symbolic reference to <empty>.<local <empty>> encountered in class file 'T.class'.
Cannot access term <local <empty>> in package class <empty>. The current classpath may be
missing a definition for <empty>.<local <empty>>, or T.class may have been compiled against a version that's
incompatible with the one found on the current classpath.
error: bad symbolic reference to <empty>.<local <empty>> encountered in class file 'T.class'.
Cannot access term <local <empty>> in package class <empty>. The current classpath may be
missing a definition for <empty>.<local <empty>>, or T.class may have been compiled against a version that's
incompatible with the one found on the current classpath.
java.lang.Throwable
    at scala.reflect.internal.Symbols$StubSymbol$class.fail(Symbols.scala:3391)
    at scala.reflect.internal.Symbols$StubSymbol$class.info(Symbols.scala:3402)
    at scala.reflect.internal.Symbols$StubTermSymbol.info(Symbols.scala:3407)
    at scala.reflect.internal.Symbols$StubTermSymbol.info(Symbols.scala:3407)
    at scala.reflect.internal.pickling.UnPickler$Scan.scala$reflect$internal$pickling$UnPickler$Scan$$fromName$1(UnPickler.scala:214)
    at scala.reflect.internal.pickling.UnPickler$Scan.readExtSymbol$1(UnPickler.scala:247)
    at scala.reflect.internal.pickling.UnPickler$Scan.readSymbol(UnPickler.scala:272)
    at scala.reflect.internal.pickling.UnPickler$Scan.readSymbolRef(UnPickler.scala:625)
    at scala.reflect.internal.pickling.UnPickler$Scan.readNonEmptyTree(UnPickler.scala:584)
    at scala.reflect.internal.pickling.UnPickler$Scan.readTree(UnPickler.scala:597)
    at scala.reflect.internal.pickling.UnPickler$Scan$$anonfun$readAnnotArg$1.apply(UnPickler.scala:445)
    at scala.reflect.internal.pickling.UnPickler$Scan$$anonfun$readAnnotArg$1.apply(UnPickler.scala:445)
    at scala.reflect.internal.pickling.UnPickler$Scan.at(UnPickler.scala:179)
    at scala.reflect.internal.pickling.UnPickler$Scan.readAnnotArg(UnPickler.scala:445)
    at scala.reflect.internal.pickling.UnPickler$Scan.readAnnotationInfo(UnPickler.scala:479)
    at scala.reflect.internal.pickling.UnPickler$Scan.readSymbolAnnotation(UnPickler.scala:491)
    at scala.reflect.internal.pickling.UnPickler$Scan.run(UnPickler.scala:97)
    at scala.reflect.internal.pickling.UnPickler.unpickle(UnPickler.scala:38)
    at scala.tools.nsc.symtab.classfile.ClassfileParser.scala$tools$nsc$symtab$classfile$ClassfileParser$$parseAttribute$1(ClassfileParser.scala:833)
    at scala.tools.nsc.symtab.classfile.ClassfileParser.parseAttributes(ClassfileParser.scala:1009)
    at scala.tools.nsc.symtab.classfile.ClassfileParser.parseClass(ClassfileParser.scala:497)
    at scala.tools.nsc.symtab.classfile.ClassfileParser.parse(ClassfileParser.scala:134)
    at scala.tools.nsc.symtab.SymbolLoaders$ClassfileLoader.doComplete(SymbolLoaders.scala:293)
    at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:211)
    at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.load(SymbolLoaders.scala:227)
    at scala.tools.nsc.typechecker.Typers$Typer.isStale(Typers.scala:518)
    at scala.tools.nsc.typechecker.Typers$Typer.reallyExists(Typers.scala:509)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$qualifies$1(Typers.scala:4745)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$101.apply(Typers.scala:4771)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$101.apply(Typers.scala:4771)
    at scala.tools.nsc.typechecker.Contexts$Context$$anonfun$lookupInScope$1$1.apply(Contexts.scala:1072)
    at scala.tools.nsc.typechecker.Contexts$Context$$anonfun$lookupInScope$1$1.apply(Contexts.scala:1072)
    at scala.collection.Iterator$$anon$13.hasNext(Iterator.scala:408)
    at scala.collection.Iterator$class.foreach(Iterator.scala:743)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1177)
    at scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:59)
    at scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:183)
    at scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:45)
    at scala.collection.TraversableOnce$class.to(TraversableOnce.scala:295)
    at scala.collection.AbstractIterator.to(Iterator.scala:1177)
    at scala.collection.TraversableOnce$class.toList(TraversableOnce.scala:279)
    at scala.collection.AbstractIterator.toList(Iterator.scala:1177)
    at scala.tools.nsc.typechecker.Contexts$Context.lookupInScope$1(Contexts.scala:1072)
    at scala.tools.nsc.typechecker.Contexts$Context.lookupSymbol(Contexts.scala:1093)
    at scala.tools.nsc.typechecker.Typers$Typer.typedIdent$2(Typers.scala:4771)
    at scala.tools.nsc.typechecker.Typers$Typer.typedIdentOrWildcard$1(Typers.scala:4809)
    at scala.tools.nsc.typechecker.Typers$Typer.typedInAnyMode$1(Typers.scala:5237)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5257)
    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5293)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5320)
    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5267)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5271)
    at scala.tools.nsc.typechecker.Typers$Typer.typedTypeConstructor(Typers.scala:5429)
    at scala.tools.nsc.typechecker.Typers$Typer.typedTypeConstructor(Typers.scala:5446)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedParentType(Typers.scala:1451)
    at scala.tools.nsc.typechecker.Typers$Typer.typedParentTypes(Typers.scala:1608)
    at scala.tools.nsc.typechecker.Namers$Namer.templateSig(Namers.scala:916)
    at scala.tools.nsc.typechecker.Namers$Namer.classSig(Namers.scala:965)
    at scala.tools.nsc.typechecker.Namers$Namer.getSig$1(Namers.scala:1521)
    at scala.tools.nsc.typechecker.Namers$Namer.typeSig(Namers.scala:1539)
    at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1$$anonfun$apply$1.apply$mcV$sp(Namers.scala:778)
    at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1$$anonfun$apply$1.apply(Namers.scala:777)
    at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1$$anonfun$apply$1.apply(Namers.scala:777)
    at scala.tools.nsc.typechecker.Namers$Namer.scala$tools$nsc$typechecker$Namers$Namer$$logAndValidate(Namers.scala:1566)
    at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1.apply(Namers.scala:777)
    at scala.tools.nsc.typechecker.Namers$Namer$$anonfun$monoTypeCompleter$1.apply(Namers.scala:769)
    at scala.tools.nsc.typechecker.Namers$$anon$1.completeImpl(Namers.scala:1681)
    at scala.tools.nsc.typechecker.Namers$LockingTypeCompleter$class.complete(Namers.scala:1689)
    at scala.tools.nsc.typechecker.Namers$$anon$1.complete(Namers.scala:1679)
    at scala.reflect.internal.Symbols$Symbol.info(Symbols.scala:1429)
    at scala.reflect.internal.Symbols$Symbol.initialize(Symbols.scala:1576)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:4909)
    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5293)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5320)
    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5267)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5271)
    at scala.tools.nsc.typechecker.Typers$Typer.typedByValueExpr(Typers.scala:5349)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedStat$1(Typers.scala:2985)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$61.apply(Typers.scala:3089)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$61.apply(Typers.scala:3089)
    at scala.collection.immutable.List.loop$1(List.scala:172)
    at scala.collection.immutable.List.mapConserve(List.scala:188)
    at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:3089)
    at scala.tools.nsc.typechecker.Typers$Typer.typedPackageDef$1(Typers.scala:4916)
    at scala.tools.nsc.typechecker.Typers$Typer.typedMemberDef$1(Typers.scala:5209)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:5256)
    at scala.tools.nsc.typechecker.Typers$Typer.runTyper$1(Typers.scala:5293)
    at scala.tools.nsc.typechecker.Typers$Typer.scala$tools$nsc$typechecker$Typers$Typer$$typedInternal(Typers.scala:5320)
    at scala.tools.nsc.typechecker.Typers$Typer.body$2(Typers.scala:5267)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5271)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5345)
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.apply(Analyzer.scala:102)
    at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:410)
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:94)
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:93)
    at scala.collection.Iterator$class.foreach(Iterator.scala:743)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1177)
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.run(Analyzer.scala:93)
    at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1557)
    at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1542)
    at scala.tools.nsc.Global$Run.compileSources(Global.scala:1537)
    at scala.tools.nsc.Global$Run.compile(Global.scala:1644)
    at scala.tools.nsc.Driver.doCompile(Driver.scala:32)
    at scala.tools.nsc.MainClass.doCompile(Main.scala:23)
    at scala.tools.nsc.Driver.process(Driver.scala:51)
    at scala.tools.nsc.Driver.main(Driver.scala:64)
    at scala.tools.nsc.Main.main(Main.scala)
warning: !!! creating stub symbol to defer error: bad symbolic reference to <local <empty>>.x$2 encountered in class file 'T.class'.
Cannot access term x$2 in value <local <empty>>. The current classpath may be
missing a definition for <local <empty>>.x$2, or T.class may have been compiled against a version that's
incompatible with the one found on the current classpath.
warning: !!! creating stub symbol to defer error: bad symbolic reference to <local <empty>>.x$1 encountered in class file 'T.class'.
Cannot access term x$1 in value <local <empty>>. The current classpath may be
missing a definition for <local <empty>>.x$1, or T.class may have been compiled against a version that's
incompatible with the one found on the current classpath.
three warnings found
one error found
% tail -n100 sandbox/{test,test1}.scala
==> sandbox/test.scala <==
class C

trait T {
  def foo = implicitly[reflect.ClassTag[C]]

  @deprecated(since = "2.4.0", message = "Either use HttpRequestHandler, or have the router injected")
  class X
}

==> sandbox/test1.scala <==
class Sub() extends T {

}

% scalac-hash v2.11.2 sandbox/test.scala && scalac-hash v2.11.2 -Xprint:mixin -Ydebug sandbox/test1.scala
sandbox/test.scala:7: warning: Usage of named or default arguments transformed this annotation
constructor call into a block. The corresponding AnnotationInfo
will contain references to local values and default getters instead
of the actual argument trees
  @deprecated(since = "2.4.0", message = "Either use HttpRequestHandler, or have the router injected")
   ^
one warning found
[running phase parser on test1.scala]
[running phase namer on test1.scala]
[running phase packageobjects on test1.scala]
[running phase typer on test1.scala]
[running phase patmat on test1.scala]
[running phase superaccessors on test1.scala]
[running phase extmethods on test1.scala]
[running phase pickler on test1.scala]
[running phase refchecks on test1.scala]
[running phase uncurry on test1.scala]
[running phase tailcalls on test1.scala]
[running phase specialize on test1.scala]
[running phase explicitouter on test1.scala]
[running phase erasure on test1.scala]
[running phase posterasure on test1.scala]
[running phase lazyvals on test1.scala]
[running phase lambdalift on test1.scala]
[running phase constructors on test1.scala]
[running phase flatten on test1.scala]
[running phase mixin on test1.scala]
[[syntax trees at end of                     mixin]] // test1.scala
package <empty> {
  class Sub extends lang.this.Object with T {
    <method> <stable> <accessor> <existential/mixedin> def <local T>() = Sub.this.<local T> ;
    <existential/mixedin> private[this] val <local T>  = _;
    <method> <accessor> <existential/mixedin> def T$_setter_$<local T>_$eq(x$1): scala.this.Unit = {
      Sub.this.<local T>  = x$1;
      ()
    };
    <method> <existential/mixedin> def foo(): reflect.this.ClassTag = T$class.foo(Sub.this);
    <method> def <init>(): <empty>.this.Sub = {
      Sub.super.<init>();
      T$class./*T$class*/$init$(Sub.this);
      ()
    }
  }
}

[running phase cleanup on test1.scala]
[running phase delambdafy on test1.scala]
[running phase icode on test1.scala]
error:
  Unknown type: <notype>, <notype> [class scala.reflect.internal.Types$NoType$, class scala.reflect.internal.Types$NoType$] TypeRef? false
     while compiling: sandbox/test1.scala
        during phase: icode
     library version: version 2.11.2-20140721-095018-73fb460c1c
    compiler version: version 2.11.2-20140721-095018-73fb460c1c
  reconstructed args: -Ydebug -Xprint:mixin

  last tree to typer: TypeTree(trait T)
       tree position: line 1 of sandbox/test1.scala
            tree tpe: T
              symbol: (<interface> abstract <trait> <lateinterface>) trait T
   symbol definition: <interface> abstract <trait> <lateinterface> trait T extends lang.this.Object (a ClassSymbol)
      symbol package: <empty>
       symbol owners: trait T
           call site: primary constructor Sub in class Sub in package <empty>

== Source file context for tree position ==

     0 class Sub() extends T {
     1
     2 }
error: scala.reflect.internal.FatalError:
  Unknown type: <notype>, <notype> [class scala.reflect.internal.Types$NoType$, class scala.reflect.internal.Types$NoType$] TypeRef? false
     while compiling: sandbox/test1.scala
        during phase: icode
     library version: version 2.11.2-20140721-095018-73fb460c1c
    compiler version: version 2.11.2-20140721-095018-73fb460c1c
  reconstructed args: -Ydebug -Xprint:mixin

  last tree to typer: TypeTree(trait T)
       tree position: line 1 of sandbox/test1.scala
            tree tpe: T
              symbol: (<interface> abstract <trait> <lateinterface>) trait T
   symbol definition: <interface> abstract <trait> <lateinterface> trait T extends lang.this.Object (a ClassSymbol)
      symbol package: <empty>
       symbol owners: trait T
           call site: primary constructor Sub in class Sub in package <empty>

== Source file context for tree position ==

     0 class Sub() extends T {
     1
     2 }
    at scala.reflect.internal.Reporting$class.abort(Reporting.scala:59)
    at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:16)
    at scala.tools.nsc.backend.icode.TypeKinds$class.toTypeKind(TypeKinds.scala:401)
    at scala.tools.nsc.backend.icode.ICodes.toTypeKind(ICodes.scala:19)
    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:115)
    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:71)
    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:148)
    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:98)
    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:71)
    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:89)
    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.gen(GenICode.scala:67)
    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.apply(GenICode.scala:63)
    at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:410)
    at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:377)
    at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:377)
    at scala.collection.Iterator$class.foreach(Iterator.scala:743)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1177)
    at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:377)
    at scala.tools.nsc.backend.icode.GenICode$ICodePhase.run(GenICode.scala:55)
    at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1557)
    at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1542)
    at scala.tools.nsc.Global$Run.compileSources(Global.scala:1537)
    at scala.tools.nsc.Global$Run.compile(Global.scala:1644)
    at scala.tools.nsc.Driver.doCompile(Driver.scala:32)
    at scala.tools.nsc.MainClass.doCompile(Main.scala:23)
    at scala.tools.nsc.Driver.process(Driver.scala:51)
    at scala.tools.nsc.Driver.main(Driver.scala:64)
    at scala.tools.nsc.Main.main(Main.scala)

Don't say we didn't warn you!

scabug commented 10 years ago

Imported From: https://issues.scala-lang.org/browse/SI-8868?orig=1 Reporter: @retronym Affected Versions: 2.10.4, 2.11.2

scabug commented 10 years ago

@retronym said: https://github.com/scala/scala/pull/4013