-
Notifications
You must be signed in to change notification settings - Fork 1.1k
The unexpected assertion failed when using the type field syntax to represent the generic type #2492
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
Comments
@odersky should have a look at this one. It looks like a general issue when refining type parameters using type members. Here is a smaller example that fails in a similar way class Map[K]
object Foo {
type X = Map { type Map$$K = String }
} It crashes with -- [E055] Syntax Error: foo.scala:4:11 -----------------------------------------
4 | type X = Map { type Map$$K = String }
| ^^^
| missing type parameter for [Map$$K] => Map[K]
exception occurred while typechecking foo.scala
exception occurred while compiling foo.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: [Map$$K] => Map[K] & <refinement> / HKTypeLambda(List(Map$$K), List(TypeBounds(TypeRef(ThisType(TypeRef(NoPrefix,scala)),Nothing), TypeRef(ThisType(TypeRef(NoPrefix,scala)),Any))), RefinedType(TypeRef(ThisType(TypeRef(NoPrefix,<empty>)),Map), Map$$K, TypeAlias(ParamRef(Map$$K), 0))) & TypeRef(NoPrefix,<refinement>)
at scala.Predef$.assert(Predef.scala:170)
at dotty.tools.dotc.core.Types$AndType$.apply(Types.scala:2314)
at dotty.tools.dotc.core.Types$ClassInfo.selfType(Types.scala:3221)
at dotty.tools.dotc.core.Types$ThisType.underlying(Types.scala:2076)
at dotty.tools.dotc.core.Types$Type.goThis$1(Types.scala:590)
at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:478)
at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:629)
at dotty.tools.dotc.core.Types$Type.memberExcluding(Types.scala:465)
at dotty.tools.dotc.core.Types$Type$$anonfun$member$1.apply(Types.scala:449)
at dotty.tools.dotc.core.Types$Type$$anonfun$member$1.apply(Types.scala:449)
at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
at dotty.tools.dotc.core.Types$Type.member(Types.scala:448)
at dotty.tools.dotc.typer.NamerContextOps$class.denotNamed(Namer.scala:52)
at dotty.tools.dotc.core.Contexts$Context.denotNamed(Contexts.scala:57)
at dotty.tools.dotc.typer.Typer$$anonfun$typedIdent$1.loop$1(Typer.scala:249)
at dotty.tools.dotc.typer.Typer$$anonfun$typedIdent$1.findRef$1(Typer.scala:300)
at dotty.tools.dotc.typer.Typer$$anonfun$typedIdent$1.apply(Typer.scala:319)
at dotty.tools.dotc.typer.Typer$$anonfun$typedIdent$1.apply(Typer.scala:98)
at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
at dotty.tools.dotc.typer.Typer.typedIdent(Typer.scala:98)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1506)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1571)
at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1587)
at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1585)
at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1585)
at dotty.tools.dotc.typer.Namer$$anonfun$typedAheadType$1.apply(Namer.scala:931)
at dotty.tools.dotc.typer.Namer$$anonfun$typedAheadType$1.apply(Namer.scala:931)
at dotty.tools.dotc.typer.Namer.typedAheadImpl(Namer.scala:924)
at dotty.tools.dotc.typer.Namer.typedAheadType(Namer.scala:931)
at dotty.tools.dotc.typer.Namer.typeDefSig(Namer.scala:1168)
at dotty.tools.dotc.typer.Namer$TypeDefCompleter.typeSig(Namer.scala:806)
at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:777)
at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:755)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:219)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.info(SymDenotations.scala:197)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:336)
at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:1479)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1504)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1571)
at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1587)
at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1585)
at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1585)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1609)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1629)
at dotty.tools.dotc.typer.Typer$$anonfun$typedClassDef$1.apply(Typer.scala:1319)
at dotty.tools.dotc.typer.Typer$$anonfun$typedClassDef$1.apply(Typer.scala:1267)
at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:1267)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1517)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1571)
at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1587)
at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1585)
at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1585)
at dotty.tools.dotc.typer.Typer$$anonfun$typedRefinedTypeTree$1.apply(Typer.scala:1038)
at dotty.tools.dotc.typer.Typer$$anonfun$typedRefinedTypeTree$1.apply(Typer.scala:1034)
at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
at dotty.tools.dotc.typer.Typer.typedRefinedTypeTree(Typer.scala:1034)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1550)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1572)
at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1587)
at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1585)
at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1585)
at dotty.tools.dotc.typer.Namer$$anonfun$typedAheadType$1.apply(Namer.scala:931)
at dotty.tools.dotc.typer.Namer$$anonfun$typedAheadType$1.apply(Namer.scala:931)
at dotty.tools.dotc.typer.Namer.typedAheadImpl(Namer.scala:924)
at dotty.tools.dotc.typer.Namer.typedAheadType(Namer.scala:931)
at dotty.tools.dotc.typer.Namer.typeDefSig(Namer.scala:1168)
at dotty.tools.dotc.typer.Namer$TypeDefCompleter.typeSig(Namer.scala:806)
at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:777)
at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:755)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:219)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.info(SymDenotations.scala:197)
at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:336)
at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:1479)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1504)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1571)
at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1587)
at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1585)
at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1585)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1609)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1629)
at dotty.tools.dotc.typer.Typer$$anonfun$typedClassDef$1.apply(Typer.scala:1319)
at dotty.tools.dotc.typer.Typer$$anonfun$typedClassDef$1.apply(Typer.scala:1267)
at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:1267)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:1517)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1571)
at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1587)
at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1585)
at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1585)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:1609)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:1629)
at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:1432)
at dotty.tools.dotc.typer.Typer$$anonfun$typedPackageDef$1.apply(Typer.scala:1419)
at dotty.tools.dotc.util.Stats$.track(Stats.scala:35)
at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1419)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:1556)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:1572)
at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1587)
at dotty.tools.dotc.typer.Typer$$anonfun$typed$2.apply(Typer.scala:1585)
at dotty.tools.dotc.reporting.Reporting$class.traceIndented(Reporter.scala:140)
at dotty.tools.dotc.core.Contexts$Context.traceIndented(Contexts.scala:57)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:1585)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:1641)
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) |
You can't refine the types like this. Generally, all symbols containing |
I guess this code came from http://dotty.epfl.ch/docs/internals/higher-kinded-v2.html#the-duality which is misleading. We might want to rephrase that document to not look like valid scala code. |
@odersky, I would imagine given that the compiler has already found an error it could stop there and not crash later. |
Good suggestion about changing the docs. |
I created #2548 to address the issue with the docs. |
Fix #2492: Avoid typing the body when self has error type
When I try this code in dotty repl, repl accidentally generates an assertion failure and crashes
What is the cause of this behavior?
The text was updated successfully, but these errors were encountered: