Dotty: Dotc fails with java.lang.AssertionError instead of useful message

Created on 3 Aug 2017  路  2Comments  路  Source: lampepfl/dotty

This invalid piece of code attempts to do a type projection on type constructor Foo without applying type arguments.

class Foo[X] {
  type A = Int
}

object Bar {
  def foo: Foo#A = 42
}

It crashes with

java.lang.AssertionError: assertion failed: invalid prefix HKTypeLambda(List(Foo$$X), List(TypeBounds(TypeRef(ThisType(TypeRef(NoPrefix,scala)),Nothing), TypeRef(ThisType(TypeRef(NoPrefix,scala)),Any))), RefinedType(TypeRef(ThisType(TypeRef(NoPrefix,<empty>)),Foo), Foo$$X, TypeAlias(ParamRef(Foo$$X), 0)))
    at scala.Predef$.assert(Predef.scala:170)
    at dotty.tools.dotc.core.Types$NamedType.<init>(Types.scala:1476)
    at dotty.tools.dotc.core.Types$TypeRef.<init>(Types.scala:1874)
    at dotty.tools.dotc.core.Types$CachedTypeRef.<init>(Types.scala:1956)
    at dotty.tools.dotc.core.Uniques$NamedTypeUniques.newType$1(Uniques.scala:59)
    at dotty.tools.dotc.core.Uniques$NamedTypeUniques.enterIfNew(Uniques.scala:64)
    at dotty.tools.dotc.core.Types$TypeRef$.apply(Types.scala:2065)
    at dotty.tools.dotc.core.Types$TypeRef$.apply(Types.scala:2090)
    at dotty.tools.dotc.core.Types$Type.select(Types.scala:1119)
    at dotty.tools.dotc.typer.TypeAssigner$class.selectionType(TypeAssigner.scala:213)
    at dotty.tools.dotc.typer.Typer.selectionType(Typer.scala:65)
    at dotty.tools.dotc.typer.TypeAssigner$class.accessibleSelectionType(TypeAssigner.scala:234)
    at dotty.tools.dotc.typer.Typer.accessibleSelectionType(Typer.scala:65)
    at dotty.tools.dotc.typer.TypeAssigner$class.assignType(TypeAssigner.scala:265)
    at dotty.tools.dotc.typer.Typer.assignType(Typer.scala:65)
    at dotty.tools.dotc.typer.Typer$$anonfun$typedSelect$1.apply(Typer.scala:422)
    at dotty.tools.dotc.typer.Typer$$anonfun$typedSelect$1.apply(Typer.scala:398)
    at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
    at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:398)
    at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1615)
    at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1680)
    at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1696)
    at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1694)
    at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
    at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:58)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1694)
    at dotty.tools.dotc.typer.Namer$$anonfun$typedAheadType$1.apply(Namer.scala:941)
    at dotty.tools.dotc.typer.Namer$$anonfun$typedAheadType$1.apply(Namer.scala:941)
    at dotty.tools.dotc.typer.Namer.typedAheadImpl(Namer.scala:934)
    at dotty.tools.dotc.typer.Namer.typedAheadType(Namer.scala:941)
    at dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1106)
    at dotty.tools.dotc.typer.Namer.defDefSig(Namer.scala:1155)
    at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:737)
    at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:781)
    at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:759)
    at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:228)
    at dotty.tools.dotc.core.SymDenotations$SymDenotation.info(SymDenotations.scala:206)
    at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:345)
    at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:1587)
    at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1612)
    at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1680)
    at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1696)
    at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1694)
    at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
    at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:58)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1694)
    at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1718)
    at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1741)
    at dotty.tools.dotc.typer.Typer$$anonfun$typedClassDef$1.apply(Typer.scala:1407)
    at dotty.tools.dotc.typer.Typer$$anonfun$typedClassDef$1.apply(Typer.scala:1337)
    at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
    at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:1337)
    at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1625)
    at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1680)
    at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1696)
    at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1694)
    at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
    at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:58)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1694)
    at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1718)
    at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1741)
    at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:1524)
    at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:1511)
    at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
    at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1511)
    at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1664)
    at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1681)
    at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1696)
    at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1694)
    at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
    at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:58)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1694)
    at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1753)
    at dotty.tools.dotc.typer.FrontEnd$$anonfun$typeCheck$1.apply$mcV$sp(FrontEnd.scala:64)
    at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:32)
    at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:62)
    at dotty.tools.dotc.typer.FrontEnd$$anonfun$runOn$3.apply(FrontEnd.scala:93)
    at dotty.tools.dotc.typer.FrontEnd$$anonfun$runOn$3.apply(FrontEnd.scala:93)
    at scala.collection.immutable.List.foreach(List.scala:392)
    at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:93)
    at dotty.tools.dotc.Run$$anonfun$compileUnits$1$$anonfun$apply$mcV$sp$1.apply(Run.scala:82)
    at dotty.tools.dotc.Run$$anonfun$compileUnits$1$$anonfun$apply$mcV$sp$1.apply(Run.scala:79)
    at scala.collection.IndexedSeqOptimized$class.foreach(IndexedSeqOptimized.scala:33)
    at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:186)
    at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply$mcV$sp(Run.scala:79)
    at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply(Run.scala:67)
    at dotty.tools.dotc.Run$$anonfun$compileUnits$1.apply(Run.scala:67)
    at dotty.tools.dotc.util.Stats$.monitorHeartBeat(Stats.scala:76)
    at dotty.tools.dotc.Run.compileUnits(Run.scala:67)
    at dotty.tools.dotc.Run.compileSources(Run.scala:64)
    at dotty.tools.dotc.Run.compile(Run.scala:48)
    at dotty.tools.dotc.Driver.doCompile(Driver.scala:26)
    at dotty.tools.dotc.Driver.process(Driver.scala:124)
    at dotty.tools.dotc.Driver.process(Driver.scala:93)
    at dotty.tools.dotc.Driver.process(Driver.scala:105)
    at dotty.tools.dotc.Driver.main(Driver.scala:132)
    at dotty.tools.dotc.Main.main(Main.scala)
reporting novice help wanted bug crash

Most helpful comment

Maybe also useful: scalac reports error: class Foo takes type parameters.

All 2 comments

Thanks for reporting, I confirm that it indeed goes "explody-boom-boom". Valid code for this example is for future reference:

class Foo[X] {
  type A = Int
}

object Bar {
  def foo[B]: Foo[B]#A = 42
}

Alas, the reported snippets should not cause the compiler to explode.

Maybe also useful: scalac reports error: class Foo takes type parameters.

Was this page helpful?
0 / 5 - 0 ratings