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

-Ycheck:erasure crashes when an alias of an applied type is instantiated #20184

Closed
EugeneFlesselle opened this issue Apr 14, 2024 · 0 comments · Fixed by #20190
Closed

-Ycheck:erasure crashes when an alias of an applied type is instantiated #20184

EugeneFlesselle opened this issue Apr 14, 2024 · 0 comments · Fixed by #20190
Labels
area:private options Issues tied to -Y private/internal compiler settings. area:transform itype:bug itype:crash
Milestone

Comments

@EugeneFlesselle
Copy link
Contributor

EugeneFlesselle commented Apr 14, 2024

Compiler version

3.5.0-RC1

Minimized code

def Test =
  object Inner:
    case class Rgb()

  type Id[X] = X
  type TRgb = Id[Inner.Rgb]

  val ok = new Inner.Rgb()
  val crash = new TRgb()

(the placement within def Test is relevant)

Output for scalac -Ycheck:erasure

  exception while retyping scala.asInstanceOf[Inner] of class TypeApply # -1
  An unhandled exception was thrown in the compiler.
  Please file a crash report here:
  https://github.com/scala/scala3/issues/new/choose
  For non-enriched exceptions, compile with -Yno-enrich-error-messages.

     while compiling: tests/playground/example.scala
        during phase: Ycheck
                mode: Mode(ImplicitsEnabled)
     library version: version 2.13.12
    compiler version: version 3.5.0-RC1-bin-SNAPSHOT-nonbootstrapped-git-54d67e0
            settings: -Ycheck List(erasure) -classpath /Users/eugeneflesselle/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.12/scala-library-2.13.12.jar:/Users/eugeneflesselle/Documents/dotty/library/../out/bootstrap/scala3-library-bootstrapped/scala-3.5.0-RC1-bin-SNAPSHOT-nonbootstrapped/scala3-library_3-3.5.0-RC1-bin-SNAPSHOT.jar -d /
*** error while checking tests/playground/example.scala after phase erasure ***
Exception in thread "main" java.lang.AssertionError: assertion failed: non member selection of method asInstanceOf in class Object from scala.type in scala.asInstanceOf
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
        at dotty.tools.dotc.transform.FirstTransform.checkPostCondition(FirstTransform.scala:62)
        at dotty.tools.dotc.transform.TreeChecker$.dotty$tools$dotc$transform$TreeChecker$Checker$$_$typedUnadapted$$anonfun$1(TreeChecker.scala:444)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:333)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:444)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:410)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3413)
        at dotty.tools.dotc.typer.Applications.typedTypeApply(Applications.scala:1186)
        at dotty.tools.dotc.typer.Applications.typedTypeApply$(Applications.scala:367)
        at dotty.tools.dotc.typer.Typer.typedTypeApply(Typer.scala:120)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3157)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3221)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:427)
        at dotty.tools.dotc.typer.ProtoTypes$FunProto.$anonfun$7(ProtoTypes.scala:496)
        at dotty.tools.dotc.typer.ProtoTypes$FunProto.cacheTypedArg(ProtoTypes.scala:419)
        at dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:497)
        at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:929)
        at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:929)
        at dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:621)
        at dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:685)
        at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:507)
        at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:811)
        at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:928)
        at dotty.tools.dotc.typer.Applications.ApplyTo(Applications.scala:1159)
        at dotty.tools.dotc.typer.Applications.ApplyTo$(Applications.scala:367)
        at dotty.tools.dotc.typer.Typer.ApplyTo(Typer.scala:120)
        at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:1001)
        at dotty.tools.dotc.typer.Applications.realApply$1$$anonfun$2(Applications.scala:1084)
        at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:3437)
        at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:1095)
        at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:1133)
        at dotty.tools.dotc.typer.Applications.typedApply$(Applications.scala:367)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedApply(TreeChecker.scala:544)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3137)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3221)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:427)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:410)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedTyped(TreeChecker.scala:564)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3142)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3221)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:427)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:410)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3413)
        at dotty.tools.dotc.typer.Typer.typedValDef(Typer.scala:2564)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedValDef(TreeChecker.scala:625)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3116)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3220)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:427)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:410)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3324)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3370)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedStats(TreeChecker.scala:694)
        at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:1215)
        at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1219)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock$$anonfun$1$$anonfun$1(TreeChecker.scala:676)
        at dotty.tools.dotc.transform.TreeChecker$Checker.withDefinedSyms(TreeChecker.scala:277)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock$$anonfun$1(TreeChecker.scala:676)
        at dotty.tools.dotc.transform.TreeChecker$Checker.withBlock(TreeChecker.scala:305)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock(TreeChecker.scala:676)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3145)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3221)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:427)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:410)
        at dotty.tools.dotc.typer.Typer.typedLabeled(Typer.scala:2012)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedLabeled$$anonfun$1(TreeChecker.scala:699)
        at dotty.tools.dotc.transform.TreeChecker$Checker.withDefinedSyms(TreeChecker.scala:277)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedLabeled(TreeChecker.scala:699)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3130)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3220)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:427)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:410)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3351)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3370)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedStats(TreeChecker.scala:694)
        at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:1215)
        at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:1219)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock$$anonfun$1$$anonfun$1(TreeChecker.scala:676)
        at dotty.tools.dotc.transform.TreeChecker$Checker.withDefinedSyms(TreeChecker.scala:277)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock$$anonfun$1(TreeChecker.scala:676)
        at dotty.tools.dotc.transform.TreeChecker$Checker.withBlock(TreeChecker.scala:305)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedBlock(TreeChecker.scala:676)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3145)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3221)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:427)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:410)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3413)
        at dotty.tools.dotc.typer.Typer.$anonfun$63(Typer.scala:2627)
        at dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:256)
        at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2627)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedDefDef$$anonfun$1(TreeChecker.scala:651)
        at dotty.tools.dotc.transform.TreeChecker$Checker.withDefinedSyms(TreeChecker.scala:277)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedDefDef(TreeChecker.scala:654)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3119)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3220)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:427)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:410)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3324)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3370)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedStats(TreeChecker.scala:694)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2814)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedClassDef(TreeChecker.scala:621)
        at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3125)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3129)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3220)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:427)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:410)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3324)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3370)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedStats(TreeChecker.scala:694)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2947)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedPackageDef(TreeChecker.scala:720)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3171)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3221)
        at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:174)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:427)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3298)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3302)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:410)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3413)
        at dotty.tools.dotc.transform.TreeChecker.check(TreeChecker.scala:130)
        at dotty.tools.dotc.transform.TreeChecker.run(TreeChecker.scala:110)
        at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:380)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:333)
        at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:386)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:319)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:341)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:351)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:361)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:361)
        at dotty.tools.dotc.Run.compileSources(Run.scala:262)
        at dotty.tools.dotc.Run.compile(Run.scala:247)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
        at dotty.tools.dotc.Driver.process(Driver.scala:199)
        at dotty.tools.dotc.Driver.process(Driver.scala:167)
        at dotty.tools.dotc.Driver.process(Driver.scala:179)
        at dotty.tools.dotc.Driver.main(Driver.scala:209)
        at dotty.tools.dotc.Main.main(Main.scala)
@EugeneFlesselle EugeneFlesselle added itype:bug itype:crash stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 14, 2024
@Gedochao Gedochao added area:private options Issues tied to -Y private/internal compiler settings. area:transform and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 16, 2024
odersky added a commit that referenced this issue Apr 25, 2024
Fixes #20184

The overlooked case was an AppliedType where we don't dealias correctly
(i.e. at phase at most erasure).
@Kordyjan Kordyjan added this to the 3.5.0 milestone May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:private options Issues tied to -Y private/internal compiler settings. area:transform itype:bug itype:crash
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants