scala / bug

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

Presentation compiler crash on Java annotations #4713

Open scabug opened 13 years ago

scabug commented 13 years ago

The presentation compiler crashes in the type checker on the second run.

First compile the following Java file:

// JavaAnnots.java
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.List;

public abstract class JavaAnnots {
  @Retention(RetentionPolicy.RUNTIME)
  @Target(ElementType.FIELD)
  public @interface Book {
  }

  public static final List<String> Book = null;
}

Then fire up the interactive repl ('scala scala.tools.nsc.interactive.REPL') and pass the following file twice:

// Problem.scala
object Problem {
  def d() {
    val v: java.util.List[String] = JavaAnnots.Book
  }
}

Here's what happens:


> reload annot-prob.scala
==> ()
> reload annot-prob.scala
==> ()
> java.lang.Error: no-symbol does not have owner
    at scala.reflect.internal.SymbolTable.abort(SymbolTable.scala:31)
    at scala.reflect.internal.Symbols$NoSymbol$.owner(Symbols.scala:2238)
    at scala.reflect.internal.Types$Type.memberInfo(Types.scala:562)
    at scala.reflect.internal.Types$TypeRef.relativeInfo(Types.scala:1741)
    at scala.reflect.internal.Types$TypeRef.baseType(Types.scala:1889)
    at scala.reflect.internal.Types$class.firstTry$1(Types.scala:4589)
    at scala.reflect.internal.Types$class.scala$reflect$internal$Types$$isSubType2(Types.scala:4745)
    at scala.reflect.internal.Types$$anonfun$isSubType$1.apply$mcZ$sp(Types.scala:4461)
    at scala.reflect.internal.Types$undoLog$.undoUnless(Types.scala:139)
    at scala.reflect.internal.Types$class.isSubType(Types.scala:4448)
    at scala.reflect.internal.SymbolTable.isSubType(SymbolTable.scala:11)
    at scala.reflect.internal.Types$class.isSubType(Types.scala:4443)
    at scala.reflect.internal.SymbolTable.isSubType(SymbolTable.scala:11)
    at scala.reflect.internal.Types$class.isWeakSubType(Types.scala:5158)
    at scala.reflect.internal.SymbolTable.isWeakSubType(SymbolTable.scala:11)
    at scala.reflect.internal.Types$Type.weak_$less$colon$less(Types.scala:683)
    at scala.tools.nsc.typechecker.Infer$Inferencer.isCompatible(Infer.scala:389)
    at scala.tools.nsc.typechecker.Infer$Inferencer.isWeaklyCompatible(Infer.scala:396)
    at scala.tools.nsc.typechecker.Infer$Inferencer$$anonfun$inferExprAlternative$1$$anonfun$36.apply(Infer.scala:1531)
    at scala.tools.nsc.typechecker.Infer$Inferencer$$anonfun$inferExprAlternative$1$$anonfun$36.apply(Infer.scala:1531)
    at scala.collection.TraversableLike$$anonfun$filter$1.apply(TraversableLike.scala:213)
    at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
    at scala.collection.immutable.List.foreach(List.scala:45)
    at scala.collection.TraversableLike$class.filter(TraversableLike.scala:212)
    at scala.collection.immutable.List.filter(List.scala:45)
    at scala.tools.nsc.typechecker.Infer$Inferencer$$anonfun$inferExprAlternative$1.apply$mcV$sp(Infer.scala:1531)
    at scala.tools.nsc.typechecker.Infer$Inferencer$$anonfun$inferExprAlternative$1.apply(Infer.scala:1530)
    at scala.tools.nsc.typechecker.Infer$Inferencer$$anonfun$inferExprAlternative$1.apply(Infer.scala:1530)
    at scala.tools.nsc.typechecker.Contexts$Context.withImplicitsDisabled(Contexts.scala:153)
    at scala.tools.nsc.typechecker.Infer$Inferencer.tryTwice(Infer.scala:1669)
    at scala.tools.nsc.typechecker.Infer$Inferencer.inferExprAlternative(Infer.scala:1530)
    at scala.tools.nsc.typechecker.Typers$Typer.stabilize(Typers.scala:552)
    at scala.tools.nsc.typechecker.Typers$Typer.typedSelect$1(Typers.scala:3591)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:4128)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4234)
    at scala.tools.nsc.typechecker.Typers$Typer.transformedOrTyped(Typers.scala:4391)
    at scala.tools.nsc.typechecker.Typers$Typer.typedValDef(Typers.scala:1561)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:3879)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4234)
    at scala.tools.nsc.typechecker.Typers$Typer.typedStat$1(Typers.scala:2094)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$24.apply(Typers.scala:2178)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$24.apply(Typers.scala:2178)
    at scala.collection.immutable.List.loop$1(List.scala:117)
    at scala.collection.immutable.List.mapConserve(List.scala:133)
    at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:2178)
    at scala.tools.nsc.typechecker.Typers$Typer.typedBlock(Typers.scala:1913)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:3914)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4234)
    at scala.tools.nsc.typechecker.Typers$Typer.transformedOrTyped(Typers.scala:4391)
    at scala.tools.nsc.typechecker.Typers$Typer.typedDefDef(Typers.scala:1754)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:3882)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4234)
    at scala.tools.nsc.typechecker.Typers$Typer.typedStat$1(Typers.scala:2094)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$24.apply(Typers.scala:2178)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$24.apply(Typers.scala:2178)
    at scala.collection.immutable.List.loop$1(List.scala:117)
    at scala.collection.immutable.List.mapConserve(List.scala:133)
    at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:2178)
    at scala.tools.nsc.typechecker.Typers$Typer.typedTemplate(Typers.scala:1506)
    at scala.tools.nsc.typechecker.Typers$Typer.typedModuleDef(Typers.scala:1314)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:3876)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4234)
    at scala.tools.nsc.typechecker.Typers$Typer.typedStat$1(Typers.scala:2094)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$24.apply(Typers.scala:2178)
    at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$24.apply(Typers.scala:2178)
    at scala.collection.immutable.List.loop$1(List.scala:117)
    at scala.collection.immutable.List.mapConserve(List.scala:133)
    at scala.tools.nsc.typechecker.Typers$Typer.typedStats(Typers.scala:2178)
    at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:3869)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4234)
    at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:4294)
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.apply(Analyzer.scala:94)
    at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:341)
    at scala.tools.nsc.interactive.Global$TyperRun$$anonfun$applyPhase$1.apply$mcV$sp(Global.scala:945)
    at scala.tools.nsc.interactive.Global$TyperRun$$anonfun$applyPhase$1.apply(Global.scala:945)
    at scala.tools.nsc.interactive.Global$TyperRun$$anonfun$applyPhase$1.apply(Global.scala:945)
    at scala.reflect.internal.SymbolTable.atPhase(SymbolTable.scala:91)
    at scala.tools.nsc.interactive.Global$TyperRun.applyPhase(Global.scala:945)
    at scala.tools.nsc.interactive.Global$TyperRun.typeCheck(Global.scala:938)
    at scala.tools.nsc.interactive.Global.scala$tools$nsc$interactive$Global$$typeCheck(Global.scala:489)
    at scala.tools.nsc.interactive.Global$$anonfun$backgroundCompile$4$$anonfun$apply$6.apply(Global.scala:428)
    at scala.tools.nsc.interactive.Global$$anonfun$backgroundCompile$4$$anonfun$apply$6.apply(Global.scala:427)
    at scala.Option.foreach(Option.scala:200)
    at scala.tools.nsc.interactive.Global$$anonfun$backgroundCompile$4.apply(Global.scala:427)
    at scala.tools.nsc.interactive.Global$$anonfun$backgroundCompile$4.apply(Global.scala:427)
    at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
    at scala.collection.immutable.List.foreach(List.scala:45)
    at scala.tools.nsc.interactive.Global.backgroundCompile(Global.scala:427)
    at scala.tools.nsc.interactive.PresentationCompilerThread.run(PresentationCompilerThread.scala:25)
scabug commented 13 years ago

Imported From: https://issues.scala-lang.org/browse/SI-4713?orig=1 Reporter: @dragos Affected Versions: 2.9.0 See #6613

scabug commented 13 years ago

Commit Message Bot (anonymous) said: (odersky in r25128) Putting in a fix for #4713. Not sure this goes deep enough, though. Review and maybe deeper changes by plocinic.

scabug commented 13 years ago

@odersky said: r25128 contains a fix, but it might be just papering over. The problem is that a companion object Book comes back as NoSymbol after adaptation. The patch returns the type unchanged, but we should dig why adaptation failed. You can reproduce it by running the test pending/run/t4713 with -Ydebug. That shows you where the adaptation failure occurs.

scabug commented 12 years ago

@dragos said (edited on Nov 1, 2011 11:04:47 AM UTC): More info: If it is in a jar on the build path, but to work fully it requires the destination type to be known.

i.e. if I do

val book : java.util.List[String] = JavaAnnots.Book

it is ok

but if I do

val book = JavaAnnots.Book

I get the following error:

Multiple markers at this line 
- ambiguous reference to overloaded definition, both value Book in object JavaAnnots of type java.util.List[java.lang.String] and object Book in object JavaAnnots of type 
object com.foo.JavaAnnots.Book match expected type ? 
- ambiguous reference to overloaded definition, both value Book in object JavaAnnots of type java.util.List[java.lang.String] and object Book in object JavaAnnots of type 
object com.foo.JavaAnnots.Book match expected type ?

If JavaAnnots.java is in same project as the scala code ‘val book = JavaAnnots.Book’ works fine.

scabug commented 11 years ago

@adriaanm said: François, could you perhaps have a look?

scabug commented 10 years ago

@retronym said: Seems related to: #6613