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

Compiler crashes when value class extends an alias of AnyVal #21918

Open
hamzaremmal opened this issue Nov 10, 2024 · 1 comment
Open

Compiler crashes when value class extends an alias of AnyVal #21918

hamzaremmal opened this issue Nov 10, 2024 · 1 comment
Assignees
Labels
area:desugar Desugaring happens after parsing but before typing, see desugar.scala area:value-classes Issues tied to value classes. itype:bug itype:crash Spree Suitable for a future Spree

Comments

@hamzaremmal
Copy link
Member

hamzaremmal commented Nov 10, 2024

Compiler version

cc38962

Minimized code

type AliasToAnyVal = AnyVal
class Foo(a: Int) extends AliasToAnyVal

Output (click arrow to expand)

scalac anyval.scala

  unhandled exception while running erasure on anyval.scala

  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 -Xno-enrich-error-messages.

     while compiling: anyval.scala
        during phase: erasure
                mode: Mode(ImplicitsEnabled)
     library version: version 2.13.14
    compiler version: version 3.5.0
            settings:

Exception in thread "main" java.lang.AssertionError: NoDenotation.owner
	at dotty.tools.dotc.core.SymDenotations$NoDenotation$.owner(SymDenotations.scala:2623)
	at dotty.tools.dotc.ast.tpd$.ref(tpd.scala:462)
	at dotty.tools.dotc.transform.Erasure$Boxing$.wrap$1(Erasure.scala:338)
	at dotty.tools.dotc.transform.Erasure$Boxing$.cast(Erasure.scala:366)
	at dotty.tools.dotc.transform.Erasure$Boxing$.unbox(Erasure.scala:320)
	at dotty.tools.dotc.transform.Erasure$Boxing$.adaptToType(Erasure.scala:403)
	at dotty.tools.dotc.transform.Erasure$Typer.adapt(Erasure.scala:1098)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3554)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3558)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3669)
	at dotty.tools.dotc.transform.Erasure$Typer.$anonfun$7(Erasure.scala:863)
	at dotty.tools.dotc.core.Decorators$.zipWithConserve(Decorators.scala:160)
	at dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:863)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3392)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3477)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3554)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3558)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3669)
	at dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:850)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3392)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3477)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3554)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3558)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3669)
	at dotty.tools.dotc.typer.Typer.$anonfun$64(Typer.scala:2816)
	at dotty.tools.dotc.inlines.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:256)
	at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:2816)
	at dotty.tools.dotc.transform.Erasure$Typer.typedDefDef(Erasure.scala:967)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3374)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3476)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3554)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3558)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3580)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3626)
	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1080)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:3074)
	at dotty.tools.dotc.transform.Erasure$Typer.typedClassDef(Erasure.scala:1056)
	at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3380)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3384)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3476)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3554)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3558)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3580)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3626)
	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:1080)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:3207)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3426)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3477)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3554)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3558)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3669)
	at dotty.tools.dotc.transform.Erasure.run(Erasure.scala:145)
	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:334)
	at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:373)
	at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:343)
	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:336)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:384)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:396)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:69)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:396)
	at dotty.tools.dotc.Run.compileSources(Run.scala:282)
	at dotty.tools.dotc.Run.compile(Run.scala:267)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:37)
	at dotty.tools.dotc.Driver.process(Driver.scala:201)
	at dotty.tools.dotc.Driver.process(Driver.scala:169)
	at dotty.tools.dotc.Driver.process(Driver.scala:181)
	at dotty.tools.dotc.Driver.main(Driver.scala:211)
	at dotty.tools.MainGenericCompiler$.run$1(MainGenericCompiler.scala:162)
	at dotty.tools.MainGenericCompiler$.main(MainGenericCompiler.scala:186)
	at dotty.tools.MainGenericCompiler.main(MainGenericCompiler.scala)

Notes

The check to determine if a class is a value class doesn't take aliasing into account. See:

def isAnyVal(tree: Tree): Boolean = tree match {
case Ident(tpnme.AnyVal) => true
case Select(qual, tpnme.AnyVal) => isScala(qual)
case _ => false
}

@hamzaremmal hamzaremmal added itype:bug itype:crash area:desugar Desugaring happens after parsing but before typing, see desugar.scala Spree Suitable for a future Spree area:value-classes Issues tied to value classes. labels Nov 10, 2024
@odersky
Copy link
Contributor

odersky commented Nov 13, 2024

The extends AnyVal is a crutch anyway, we should have explicit syntax for that. So I would just outlaw this case and forbid inheriting aliases of AnyVal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:desugar Desugaring happens after parsing but before typing, see desugar.scala area:value-classes Issues tied to value classes. itype:bug itype:crash Spree Suitable for a future Spree
Projects
None yet
Development

No branches or pull requests

2 participants