Skip to content

Dotty crashes on type with Structural type subtyping #14771

@mhammons-ledger

Description

@mhammons-ledger

Compiler version

3.1.1

Minimized code

trait Layouts:
  type Layout <: {
    def withName(name: String): Layout
  }
  val l: Layout

val ls = new Layouts: 
  class Layout17:
    def withName(name: String): Layout17 = this
  type Layout = Layout17
  val l = Layout17()

ls.l

Output (click arrow to expand)

Exception in thread "main" java.lang.AssertionError: assertion failed
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:11)
        at dotty.tools.dotc.core.Types$LazyRef.ref(Types.scala:2873)
        at dotty.tools.dotc.core.Types$TypeAccumulator.foldOver(Types.scala:5942)
        at dotty.tools.dotc.core.Types$TermLambda.dotty$tools$dotc$core$Types$TermLambda$$_$compute$1(Types.scala:3626)
        at dotty.tools.dotc.core.Types$TermLambda.dotty$tools$dotc$core$Types$TermLambda$$depStatus(Types.scala:3627)
        at dotty.tools.dotc.core.Types$TermLambda.dependencyStatus(Types.scala:3641)
        at dotty.tools.dotc.core.Types$TermLambda.resultType(Types.scala:3577)
        at dotty.tools.dotc.core.Types$TermLambda.resultType$(Types.scala:3569)
        at dotty.tools.dotc.core.Types$MethodType.resultType(Types.scala:3688)
        at dotty.tools.dotc.core.Types$TypeAccumulator.foldOver(Types.scala:5881)
        at dotty.tools.dotc.core.Types$Type.dotty$tools$dotc$core$Types$Type$$_$test$1(Types.scala:139)
        at dotty.tools.dotc.core.Types$ProAcc$1.apply(Types.scala:116)
        at dotty.tools.dotc.core.Types$ProAcc$1.apply(Types.scala:116)
        at dotty.tools.dotc.core.Types$TypeAccumulator.foldOver(Types.scala:5924)
        at dotty.tools.dotc.core.Types$Type.dotty$tools$dotc$core$Types$Type$$_$test$1(Types.scala:139)
        at dotty.tools.dotc.core.Types$Type.testProvisional(Types.scala:143)
        at dotty.tools.dotc.core.Types$Type.isProvisional(Types.scala:112)
        at dotty.tools.dotc.core.SymDenotations$ClassDenotation.record$1(SymDenotations.scala:2090)
        at dotty.tools.dotc.core.SymDenotations$ClassDenotation.computeTypeProxy$1(SymDenotations.scala:2181)
        at dotty.tools.dotc.core.SymDenotations$ClassDenotation.recur$5(SymDenotations.scala:2186)
        at dotty.tools.dotc.core.SymDenotations$ClassDenotation.baseTypeOf(SymDenotations.scala:2230)
        at dotty.tools.dotc.core.Types$Type.baseType(Types.scala:1128)
        at dotty.tools.dotc.core.TypeComparer.nonExprBaseType(TypeComparer.scala:1339)
        at dotty.tools.dotc.core.TypeComparer.tryBaseType$1(TypeComparer.scala:759)
        at dotty.tools.dotc.core.TypeComparer.thirdTryNamed$1(TypeComparer.scala:538)
        at dotty.tools.dotc.core.TypeComparer.thirdTry$1(TypeComparer.scala:573)
        at dotty.tools.dotc.core.TypeComparer.secondTry$1(TypeComparer.scala:504)
        at dotty.tools.dotc.core.TypeComparer.compareNamed$1(TypeComparer.scala:313)
        at dotty.tools.dotc.core.TypeComparer.firstTry$1(TypeComparer.scala:319)
        at dotty.tools.dotc.core.TypeComparer.recur(TypeComparer.scala:1321)
        at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:201)
        at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:211)
        at dotty.tools.dotc.core.TypeComparer.isSub(TypeComparer.scala:213)
        at dotty.tools.dotc.core.ConstraintHandling.op$proxy1$1(ConstraintHandling.scala:230)
        at dotty.tools.dotc.core.ConstraintHandling.isSubTypeWhenFrozen(ConstraintHandling.scala:230)
        at dotty.tools.dotc.core.ConstraintHandling.isSubTypeWhenFrozen$(ConstraintHandling.scala:27)
        at dotty.tools.dotc.core.TypeComparer.isSubTypeWhenFrozen(TypeComparer.scala:30)
        at dotty.tools.dotc.core.TypeComparer$.isSubTypeWhenFrozen(TypeComparer.scala:2741)
        at dotty.tools.dotc.core.Types$Type.frozen_$less$colon$less(Types.scala:1041)
        at dotty.tools.dotc.core.Types$TypeBounds.$amp(Types.scala:4958)
        at dotty.tools.dotc.core.Types$TypeBounds.$amp(Types.scala:4967)
        at dotty.tools.dotc.core.Types$Type.recoverable_$amp(Types.scala:1159)
        at dotty.tools.dotc.core.Types$Type.goRefined$1(Types.scala:786)
        at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:705)
        at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:873)
        at dotty.tools.dotc.core.Types$Type.memberBasedOnFlags(Types.scala:669)
        at dotty.tools.dotc.core.Types$Type.nonPrivateMember(Types.scala:659)
        at dotty.tools.dotc.core.Types$NamedType.memberDenot(Types.scala:2283)
        at dotty.tools.dotc.core.Types$NamedType.reload$1(Types.scala:2564)
        at dotty.tools.dotc.core.Types$NamedType.withPrefix(Types.scala:2577)
        at dotty.tools.dotc.core.Types$NamedType.derivedSelect(Types.scala:2517)
        at dotty.tools.dotc.core.Types$TypeMap.derivedSelect(Types.scala:5364)
        at dotty.tools.dotc.core.Types$ApproximatingTypeMap.derivedSelect(Types.scala:5666)
        at dotty.tools.dotc.core.TypeOps$AsSeenFromMap.apply(TypeOps.scala:101)
        at dotty.tools.dotc.core.Types$TypeMap.mapOver$$anonfun$1(Types.scala:5489)
        at dotty.tools.dotc.core.Types$LazyRef.ref(Types.scala:2879)
        at dotty.tools.dotc.core.Types$TypeMap.mapOver$$anonfun$1(Types.scala:5488)
        at dotty.tools.dotc.core.Types$LazyRef.ref(Types.scala:2879)
        at dotty.tools.dotc.core.Types$TypeAccumulator.foldOver(Types.scala:5942)
        at dotty.tools.dotc.core.Types$TermLambda.dotty$tools$dotc$core$Types$TermLambda$$_$compute$1(Types.scala:3626)
        at dotty.tools.dotc.core.Types$TermLambda.dotty$tools$dotc$core$Types$TermLambda$$depStatus(Types.scala:3627)
        at dotty.tools.dotc.core.Types$TermLambda.dependencyStatus(Types.scala:3641)
        at dotty.tools.dotc.core.Types$TermLambda.resultType(Types.scala:3577)
        at dotty.tools.dotc.core.Types$TermLambda.resultType$(Types.scala:3569)
        at dotty.tools.dotc.core.Types$MethodType.resultType(Types.scala:3688)
        at dotty.tools.dotc.core.Types$TypeAccumulator.foldOver(Types.scala:5881)
        at dotty.tools.dotc.core.Types$Type.dotty$tools$dotc$core$Types$Type$$_$test$1(Types.scala:139)
        at dotty.tools.dotc.core.Types$ProAcc$1.apply(Types.scala:116)
        at dotty.tools.dotc.core.Types$ProAcc$1.apply(Types.scala:116)
        at dotty.tools.dotc.core.Types$TypeAccumulator.foldOver(Types.scala:5924)
        at dotty.tools.dotc.core.Types$Type.dotty$tools$dotc$core$Types$Type$$_$test$1(Types.scala:139)
        at dotty.tools.dotc.core.Types$Type.testProvisional(Types.scala:143)
        at dotty.tools.dotc.core.Types$Type.isProvisional(Types.scala:112)
        at dotty.tools.dotc.core.SymDenotations$ClassDenotation.record$1(SymDenotations.scala:2090)
        at dotty.tools.dotc.core.SymDenotations$ClassDenotation.computeTypeProxy$1(SymDenotations.scala:2181)
        at dotty.tools.dotc.core.SymDenotations$ClassDenotation.recur$5(SymDenotations.scala:2186)
        at dotty.tools.dotc.core.SymDenotations$ClassDenotation.baseTypeOf(SymDenotations.scala:2230)
        at dotty.tools.dotc.core.Types$Type.baseType(Types.scala:1128)
        at dotty.tools.dotc.core.TypeComparer.nonExprBaseType(TypeComparer.scala:1339)
        at dotty.tools.dotc.core.TypeComparer.tryBaseType$1(TypeComparer.scala:759)
        at dotty.tools.dotc.core.TypeComparer.thirdTryNamed$1(TypeComparer.scala:538)
        at dotty.tools.dotc.core.TypeComparer.thirdTry$1(TypeComparer.scala:573)
        at dotty.tools.dotc.core.TypeComparer.secondTry$1(TypeComparer.scala:504)
        at dotty.tools.dotc.core.TypeComparer.compareNamed$1(TypeComparer.scala:313)
        at dotty.tools.dotc.core.TypeComparer.firstTry$1(TypeComparer.scala:319)
        at dotty.tools.dotc.core.TypeComparer.recur(TypeComparer.scala:1321)
        at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:201)
        at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:211)
        at dotty.tools.dotc.core.TypeComparer.isSub(TypeComparer.scala:213)
        at dotty.tools.dotc.core.ConstraintHandling.op$proxy1$1(ConstraintHandling.scala:230)
        at dotty.tools.dotc.core.ConstraintHandling.isSubTypeWhenFrozen(ConstraintHandling.scala:230)
        at dotty.tools.dotc.core.ConstraintHandling.isSubTypeWhenFrozen$(ConstraintHandling.scala:27)
        at dotty.tools.dotc.core.TypeComparer.isSubTypeWhenFrozen(TypeComparer.scala:30)
        at dotty.tools.dotc.core.TypeComparer$.isSubTypeWhenFrozen(TypeComparer.scala:2741)
        at dotty.tools.dotc.core.Types$Type.frozen_$less$colon$less(Types.scala:1041)
        at dotty.tools.dotc.core.Types$TypeBounds.$amp(Types.scala:4958)
        at dotty.tools.dotc.core.Types$TypeBounds.$amp(Types.scala:4967)
        at dotty.tools.dotc.core.Types$Type.recoverable_$amp(Types.scala:1159)
        at dotty.tools.dotc.core.Types$Type.goRefined$1(Types.scala:786)
        at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:705)
        at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:873)
        at dotty.tools.dotc.core.Types$Type.memberBasedOnFlags(Types.scala:669)
        at dotty.tools.dotc.core.Types$Type.nonPrivateMember(Types.scala:659)
        at dotty.tools.dotc.core.Types$NamedType.memberDenot(Types.scala:2283)
        at dotty.tools.dotc.core.Types$NamedType.reload$1(Types.scala:2564)
        at dotty.tools.dotc.core.Types$NamedType.withPrefix(Types.scala:2577)
        at dotty.tools.dotc.core.Types$NamedType.derivedSelect(Types.scala:2517)
        at dotty.tools.dotc.core.Types$TypeMap.derivedSelect(Types.scala:5364)
        at dotty.tools.dotc.core.Types$ApproximatingTypeMap.derivedSelect(Types.scala:5666)
        at dotty.tools.dotc.core.TypeOps$AsSeenFromMap.apply(TypeOps.scala:101)
        at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:5459)
        at dotty.tools.dotc.core.TypeOps$AsSeenFromMap.apply(TypeOps.scala:109)
        at dotty.tools.dotc.core.TypeOps$.asSeenFrom(TypeOps.scala:54)
        at dotty.tools.dotc.core.Types$Type.asSeenFrom(Types.scala:1027)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.derived$1(Denotations.scala:1096)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.computeAsSeenFrom(Denotations.scala:1118)
        at dotty.tools.dotc.core.Denotations$SingleDenotation.computeAsSeenFrom(Denotations.scala:1076)
        at dotty.tools.dotc.core.Denotations$PreDenotation.asSeenFrom(Denotations.scala:135)
        at dotty.tools.dotc.core.SymDenotations$ClassDenotation.findMember(SymDenotations.scala:2073)
        at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:686)
        at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:873)
        at dotty.tools.dotc.core.Types$Type.memberBasedOnFlags(Types.scala:669)
        at dotty.tools.dotc.core.Types$Type.member(Types.scala:653)
        at dotty.tools.dotc.typer.ProtoTypes$SelectionProto.isMatchedBy(ProtoTypes.scala:187)
        at dotty.tools.dotc.core.TypeComparer.isMatchedByProto(TypeComparer.scala:1899)
        at dotty.tools.dotc.core.TypeComparer.firstTry$1(TypeComparer.scala:321)
        at dotty.tools.dotc.core.TypeComparer.recur(TypeComparer.scala:1321)
        at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:201)
        at dotty.tools.dotc.core.TypeComparer.isSubType(TypeComparer.scala:211)
        at dotty.tools.dotc.core.TypeComparer.topLevelSubType(TypeComparer.scala:128)
        at dotty.tools.dotc.core.TypeComparer.testSubType(TypeComparer.scala:154)
        at dotty.tools.dotc.core.TypeComparer$.testSubType(TypeComparer.scala:2744)
        at dotty.tools.dotc.typer.Typer.adaptNoArgsOther$1(Typer.scala:3612)
        at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:3709)
        at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3909)
        at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:3251)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2907)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2911)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3027)
        at dotty.tools.dotc.typer.Typer.typeSelectOnTerm$1(Typer.scala:626)
        at dotty.tools.dotc.typer.Typer.typedSelect(Typer.scala:676)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2749)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2841)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2907)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2911)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3027)
        at dotty.tools.dotc.typer.Namer.typedAheadExpr$$anonfun$1(Namer.scala:1430)
        at dotty.tools.dotc.typer.Namer.typedAhead(Namer.scala:1420)
        at dotty.tools.dotc.typer.Namer.typedAheadExpr(Namer.scala:1430)
        at dotty.tools.dotc.typer.Namer.typedAheadRhs$1$$anonfun$1(Namer.scala:1682)
        at dotty.tools.dotc.typer.PrepareInlineable$.dropInlineIfError(PrepareInlineable.scala:238)
        at dotty.tools.dotc.typer.Namer.typedAheadRhs$1(Namer.scala:1682)
        at dotty.tools.dotc.typer.Namer.rhsType$1(Namer.scala:1690)
        at dotty.tools.dotc.typer.Namer.cookedRhsType$1(Namer.scala:1708)
        at dotty.tools.dotc.typer.Namer.lhsType$1(Namer.scala:1709)
        at dotty.tools.dotc.typer.Namer.inferredResultType(Namer.scala:1720)
        at dotty.tools.dotc.typer.Namer.inferredType$1(Namer.scala:1469)
        at dotty.tools.dotc.typer.Namer.valOrDefDefSig(Namer.scala:1476)
        at dotty.tools.dotc.typer.Namer$Completer.typeSig(Namer.scala:752)
        at dotty.tools.dotc.typer.Namer$Completer.completeInCreationContext(Namer.scala:888)
        at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:780)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:168)
        at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:188)
        at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:190)
        at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:370)
        at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:2721)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2746)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2841)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2907)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2911)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2933)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2983)
        at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2426)
        at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:2767)
        at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2771)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2841)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2907)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2911)
        at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2933)
        at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2983)
        at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2553)
        at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2812)
        at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2842)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2907)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2911)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3027)
        at dotty.tools.dotc.typer.TyperPhase.liftedTree1$1(TyperPhase.scala:56)
        at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:62)
        at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:411)
        at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:63)
        at dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$1(TyperPhase.scala:106)
        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.typer.TyperPhase.runOn(TyperPhase.scala:106)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:261)
        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:272)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:280)
        at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:289)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:228)
        at dotty.tools.repl.ReplCompiler.runCompilationUnit(ReplCompiler.scala:167)
        at dotty.tools.repl.ReplCompiler.compile(ReplCompiler.scala:178)
        at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:251)
        at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:219)
        at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:153)
        at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:156)
        at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:175)
        at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:156)
        at dotty.tools.repl.ReplDriver.tryRunning(ReplDriver.scala:118)
        at dotty.tools.repl.Main$.main(Main.scala:6)
        at dotty.tools.repl.Main.main(Main.scala)

This points at here

You can get rid of the problem by redefining Layout in Layouts:

type Layout <: Any {
  def withName(name: String): Layout
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions