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

Crash with Recursive Reference in Annotation with Type parameter #9314

Closed
bishabosha opened this issue Jul 7, 2020 · 0 comments
Closed

Crash with Recursive Reference in Annotation with Type parameter #9314

bishabosha opened this issue Jul 7, 2020 · 0 comments

Comments

@bishabosha
Copy link
Member

bishabosha commented Jul 7, 2020

Minimized code

final class fooAnnot[T](member: T) extends scala.annotation.StaticAnnotation // must have type parameter

@fooAnnot(new RecAnnotated {}) // must pass instance of anonymous subclass
trait RecAnnotated

Output (click arrow to expand)

exception occurred while typechecking example.scala
exception occurred while compiling example.scala
java.lang.AssertionError: assertion failed: leak: Object with RecAnnotated {...} in {
  final class $anon() extends Object(), RecAnnotated {}
  new $anon():Object with RecAnnotated {...}
} while compiling example.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: leak: Object with RecAnnotated {...} in {
  final class $anon() extends Object(), RecAnnotated {}
  new $anon():Object with RecAnnotated {...}
}
	at dotty.DottyPredef$.assertFail(DottyPredef.scala:17)
	at dotty.tools.dotc.typer.Typer.ensureNoLocalRefs(Typer.scala:892)
	at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:858)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2400)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2452)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2518)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2527)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2530)
	at dotty.tools.dotc.typer.Typer.typedNew(Typer.scala:679)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2396)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2452)
	at dotty.tools.dotc.typer.ProtoTypes$FunProto.$anonfun$2(ProtoTypes.scala:337)
	at dotty.tools.dotc.typer.ProtoTypes$FunProto.cacheTypedArg(ProtoTypes.scala:293)
	at dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:338)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:815)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:815)
	at dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:538)
	at dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:607)
	at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:363)
	at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:710)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:814)
	at dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1022)
	at dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:84)
	at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:887)
	at dotty.tools.dotc.typer.Applications.realApply$5$$anonfun$4(Applications.scala:948)
	at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:2649)
	at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:959)
	at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:997)
	at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:84)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2392)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2452)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2518)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2527)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2530)
	at dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1354)
	at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1344)
	at dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1354)
	at dotty.tools.dotc.typer.Namer.typedAheadAnnotation(Namer.scala:1357)
	at dotty.tools.dotc.typer.Namer$Completer.$anonfun$2(Namer.scala:861)
	at dotty.tools.dotc.core.Annotations$.dotty$tools$dotc$core$Annotations$$anon$2$$_$$lessinit$greater$$anonfun$2(Annotations.scala:159)
	at dotty.tools.dotc.core.Annotations$LazyAnnotation.tree(Annotations.scala:83)
	at dotty.tools.dotc.core.Annotations$Annotation.ensureCompleted(Annotations.scala:44)
	at dotty.tools.dotc.typer.Typer.completeAnnotations$$anonfun$1(Typer.scala:1832)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at dotty.tools.dotc.typer.Typer.completeAnnotations(Typer.scala:1832)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2038)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$2(Typer.scala:2380)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2384)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2451)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2518)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2527)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2530)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2552)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2597)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2176)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2424)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2452)
	at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2518)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2527)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2530)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2641)
	at dotty.tools.dotc.typer.FrontEnd.liftedTree1$1(FrontEnd.scala:79)
	at dotty.tools.dotc.typer.FrontEnd.typeCheck$$anonfun$1(FrontEnd.scala:84)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:42)
	at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:85)
	at dotty.tools.dotc.typer.FrontEnd.runOn$$anonfun$3(FrontEnd.scala:114)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.immutable.List.foreach(List.scala:333)
	at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:114)
	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:180)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
	at dotty.tools.dotc.Run.runPhases$5(Run.scala:190)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:198)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:64)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:205)
	at dotty.tools.dotc.Run.compileSources(Run.scala:142)
	at dotty.tools.dotc.Run.compile(Run.scala:124)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:38)
	at dotty.tools.dotc.Driver.process(Driver.scala:194)
	at dotty.tools.dotc.Driver.process(Driver.scala:163)
	at dotty.tools.dotc.Driver.process(Driver.scala:175)
	at dotty.tools.dotc.Driver.main(Driver.scala:202)
	at dotty.tools.dotc.Main.main(Main.scala)
@KacperFKorban KacperFKorban self-assigned this Jun 29, 2022
KacperFKorban added a commit to KacperFKorban/dotty that referenced this issue Jun 29, 2022
Possible fix for scala#9314

Typer.ensureNoLocalRefs doesn't avoid local static refs like anonymous
class instances to allow typing more specific expected types with e.g. refinements.
Unfortunately this can cause leaks when expected types have to be
inferred. This PR tries to fix this problem by adding a fallback that
avoids all local symbols if this leak were to happen.
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

3 participants