Skip to content

Crash after erasure for inlined try/catch #7041

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

Closed
liufengyun opened this issue Aug 14, 2019 · 0 comments
Closed

Crash after erasure for inlined try/catch #7041

liufengyun opened this issue Aug 14, 2019 · 0 comments

Comments

@liufengyun
Copy link
Contributor

minimized code

dotc -d out -Ycheck:all examples/exception.scala:

import scala.util.control.NonLocalReturns._

inline def (op: => T) rescue[T, E <: Throwable] (fallback: PartialFunction[E, T]) =
  try op
  catch {
    case ex: ReturnThrowable[_] => throw ex
    case ex: E =>
      if (fallback.isDefinedAt(ex))  fallback(ex) else throw ex
  }

def test: Unit = {
  9 / 0 rescue { case _: ArithmeticException => 10 }
}
Stack trace
*** error while checking examples/exception.scala after phase erasure ***
exception occurred while compiling examples/exception.scala
java.lang.AssertionError: assertion failed: The type util.control.NonLocalReturns.ReturnThrowable[_] @_ @_ - AnnotatedType(AnnotatedType(AppliedType(TypeRef(TermRef(TermRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),module scala),module util),module control),module NonLocalReturns),class ReturnThrowable),List(TypeRef(NoPrefix,type _))),ConcreteAnnotation(Ident($boundType$))),ConcreteAnnotation(Ident($boundType$))) of class class dotty.tools.dotc.core.Types$AnnotatedType of tree util.control.NonLocalReturns.ReturnThrowable[_] @_ @_ : util.control.NonLocalReturns.ReturnThrowable[_] @_ @_ / class dotty.tools.dotc.ast.Trees$Annotated is illegal after erasure, phase = erasure while compiling examples/exception.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: The type util.control.NonLocalReturns.ReturnThrowable[_] @_ @_ - AnnotatedType(AnnotatedType(AppliedType(TypeRef(TermRef(TermRef(TermRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),module scala),module util),module control),module NonLocalReturns),class ReturnThrowable),List(TypeRef(NoPrefix,type _))),ConcreteAnnotation(Ident($boundType$))),ConcreteAnnotation(Ident($boundType$))) of class class dotty.tools.dotc.core.Types$AnnotatedType of tree util.control.NonLocalReturns.ReturnThrowable[_] @_ @_ : util.control.NonLocalReturns.ReturnThrowable[_] @_ @_ / class dotty.tools.dotc.ast.Trees$Annotated is illegal after erasure, phase = erasure
	at dotty.DottyPredef$.assertFail(DottyPredef.scala:16)
	at dotty.tools.dotc.transform.Erasure.assertErased(Erasure.scala:142)
	at dotty.tools.dotc.transform.Erasure.assertErased(Erasure.scala:126)
	at dotty.tools.dotc.transform.Erasure.checkPostCondition(Erasure.scala:104)
	at dotty.tools.dotc.transform.TreeChecker.dotty$tools$dotc$transform$TreeChecker$Checker$$_$typedUnadapted$$anonfun$1(TreeChecker.scala:297)
	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:392)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:297)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2099)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2111)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:265)
	at dotty.tools.dotc.typer.Typer.typedType(Typer.scala:2189)
	at dotty.tools.dotc.typer.ReTyper.typedTyped(ReTyper.scala:56)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2010)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2061)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:280)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2099)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2111)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:265)
	at dotty.tools.dotc.typer.ReTyper.typedBind(ReTyper.scala:76)
	at dotty.tools.dotc.typer.ReTyper.typedBind(ReTyper.scala:74)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1987)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2060)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:280)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2099)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2111)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:265)
	at dotty.tools.dotc.typer.Typer.typedPattern(Typer.scala:2191)
	at dotty.tools.dotc.typer.Typer.typedCase(Typer.scala:1112)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedCase$$anonfun$1(TreeChecker.scala:419)
	at dotty.tools.dotc.transform.TreeChecker$Checker.withPatSyms(TreeChecker.scala:176)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedCase(TreeChecker.scala:420)
	at dotty.tools.dotc.typer.Typer.typedCases$$anonfun$1(Typer.scala:1071)
	at dotty.tools.dotc.core.Decorators$ListDecorator$.loop$1(Decorators.scala:63)
	at dotty.tools.dotc.core.Decorators$ListDecorator$.mapconserve$extension(Decorators.scala:79)
	at dotty.tools.dotc.typer.Typer.typedCases(Typer.scala:1071)
	at dotty.tools.dotc.typer.Typer.$anonfun$20(Typer.scala:1191)
	at dotty.tools.dotc.typer.Applications.harmonic(Applications.scala:1847)
	at dotty.tools.dotc.typer.Typer.harmonic(Typer.scala:83)
	at dotty.tools.dotc.typer.Typer.typedTry(Typer.scala:1193)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2021)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2061)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:280)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2099)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2111)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:265)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2187)
	at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:709)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock$$anonfun$2$$anonfun$1(TreeChecker.scala:438)
	at dotty.tools.dotc.transform.TreeChecker$Checker.withDefinedSyms(TreeChecker.scala:169)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock$$anonfun$1(TreeChecker.scala:438)
	at dotty.tools.dotc.transform.TreeChecker$Checker.withBlock(TreeChecker.scala:186)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock(TreeChecker.scala:438)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2013)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2061)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:280)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2099)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2111)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:265)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2152)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2174)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedStats(TreeChecker.scala:456)
	at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:705)
	at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:708)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock$$anonfun$2$$anonfun$1(TreeChecker.scala:438)
	at dotty.tools.dotc.transform.TreeChecker$Checker.withDefinedSyms(TreeChecker.scala:169)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock$$anonfun$1(TreeChecker.scala:438)
	at dotty.tools.dotc.transform.TreeChecker$Checker.withBlock(TreeChecker.scala:186)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock(TreeChecker.scala:438)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2013)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2061)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:280)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2099)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2111)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:265)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2187)
	at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:709)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock$$anonfun$2$$anonfun$1(TreeChecker.scala:438)
	at dotty.tools.dotc.transform.TreeChecker$Checker.withDefinedSyms(TreeChecker.scala:169)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock$$anonfun$1(TreeChecker.scala:438)
	at dotty.tools.dotc.transform.TreeChecker$Checker.withBlock(TreeChecker.scala:186)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock(TreeChecker.scala:438)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2013)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2061)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:280)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2099)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2111)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:265)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2187)
	at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:1544)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedDefDef$$anonfun$2$$anonfun$1(TreeChecker.scala:411)
	at dotty.tools.dotc.transform.TreeChecker$Checker.withDefinedSyms(TreeChecker.scala:169)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedDefDef$$anonfun$1(TreeChecker.scala:414)
	at dotty.tools.dotc.transform.TreeChecker$Checker.withDefinedSyms(TreeChecker.scala:169)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedDefDef(TreeChecker.scala:415)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1993)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2060)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:280)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2099)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2111)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:265)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2130)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2174)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedStats(TreeChecker.scala:456)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:1673)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedClassDef(TreeChecker.scala:395)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1996)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2060)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:280)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2099)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2111)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:265)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2130)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2174)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedStats(TreeChecker.scala:456)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1797)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2036)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2061)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:280)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2099)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2111)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:265)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2187)
	at dotty.tools.dotc.transform.TreeChecker.check(TreeChecker.scala:122)
	at dotty.tools.dotc.transform.TreeChecker.run(TreeChecker.scala:94)
	at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:316)
	at scala.collection.immutable.List.map(List.scala:286)
	at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:318)
	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:158)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:36)
	at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:33)
	at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:198)
	at dotty.tools.dotc.Run.runPhases$5(Run.scala:170)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:178)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:65)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:185)
	at dotty.tools.dotc.Run.compileSources(Run.scala:120)
	at dotty.tools.dotc.Run.compile(Run.scala:104)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:35)
	at dotty.tools.dotc.Driver.process(Driver.scala:180)
	at dotty.tools.dotc.Driver.process(Driver.scala:149)
	at dotty.tools.dotc.Driver.process(Driver.scala:161)
	at dotty.tools.dotc.Driver.main(Driver.scala:188)
	at dotty.tools.dotc.Main.main(Main.scala)```
</details>
liufengyun added a commit that referenced this issue Aug 26, 2019
Fix #7041: Drop `Annotated` type trees at erasure
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

1 participant