Skip to content

Commit 06df92b

Browse files
authored
Merge pull request #12653 from dotty-staging/fix-12650
Avoid assertion failure when forcing LazyRef while printing
2 parents a9a7e70 + df16731 commit 06df92b

File tree

6 files changed

+30
-18
lines changed

6 files changed

+30
-18
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

+15-13
Original file line numberDiff line numberDiff line change
@@ -2398,19 +2398,21 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
23982398
}
23992399

24002400
/** Show subtype goal that led to an assertion failure */
2401-
def showGoal(tp1: Type, tp2: Type)(using Context): Unit = {
2402-
report.echo(i"assertion failure for ${show(tp1)} <:< ${show(tp2)}, frozen = $frozenConstraint")
2403-
def explainPoly(tp: Type) = tp match {
2404-
case tp: TypeParamRef => report.echo(s"TypeParamRef ${tp.show} found in ${tp.binder.show}")
2405-
case tp: TypeRef if tp.symbol.exists => report.echo(s"typeref ${tp.show} found in ${tp.symbol.owner.show}")
2406-
case tp: TypeVar => report.echo(s"typevar ${tp.show}, origin = ${tp.origin}")
2407-
case _ => report.echo(s"${tp.show} is a ${tp.getClass}")
2408-
}
2409-
if (Config.verboseExplainSubtype) {
2410-
explainPoly(tp1)
2411-
explainPoly(tp2)
2412-
}
2413-
}
2401+
def showGoal(tp1: Type, tp2: Type)(using Context): Unit =
2402+
try
2403+
report.echo(i"assertion failure for ${show(tp1)} <:< ${show(tp2)}, frozen = $frozenConstraint")
2404+
def explainPoly(tp: Type) = tp match {
2405+
case tp: TypeParamRef => report.echo(s"TypeParamRef ${tp.show} found in ${tp.binder.show}")
2406+
case tp: TypeRef if tp.symbol.exists => report.echo(s"typeref ${tp.show} found in ${tp.symbol.owner.show}")
2407+
case tp: TypeVar => report.echo(s"typevar ${tp.show}, origin = ${tp.origin}")
2408+
case _ => report.echo(s"${tp.show} is a ${tp.getClass}")
2409+
}
2410+
if (Config.verboseExplainSubtype) {
2411+
explainPoly(tp1)
2412+
explainPoly(tp2)
2413+
}
2414+
catch case NonFatal(ex) =>
2415+
report.echo(s"assertion failure [[cannot display since $ex was thrown]]")
24142416

24152417
/** Record statistics about the total number of subtype checks
24162418
* and the number of "successful" subtype checks, i.e. checks

compiler/src/dotty/tools/dotc/core/Types.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -2851,7 +2851,9 @@ object Types {
28512851
if myRef == null then
28522852
// if errors were reported previously handle this by throwing a CyclicReference
28532853
// instead of crashing immediately. A test case is neg/i6057.scala.
2854-
assert(ctx.mode.is(Mode.CheckCyclic) || ctx.reporter.errorsReported)
2854+
assert(ctx.mode.is(Mode.CheckCyclic)
2855+
|| ctx.mode.is(Mode.Printing)
2856+
|| ctx.reporter.errorsReported)
28552857
throw CyclicReference(NoDenotation)
28562858
else
28572859
computed = true

compiler/src/dotty/tools/dotc/typer/Checking.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -403,11 +403,11 @@ object Checking {
403403
return
404404

405405
def qualifies(sym: Symbol) = sym.name.isTypeName && !sym.is(Private)
406-
val abstractTypeNames =
407-
for (parent <- parents; mbr <- parent.abstractTypeMembers if qualifies(mbr.symbol))
408-
yield mbr.name.asTypeName
409-
410406
withMode(Mode.CheckCyclic) {
407+
val abstractTypeNames =
408+
for (parent <- parents; mbr <- parent.abstractTypeMembers if qualifies(mbr.symbol))
409+
yield mbr.name.asTypeName
410+
411411
for name <- abstractTypeNames do
412412
try
413413
val mbr = joint.member(name)

compiler/test/dotty/tools/dotc/CompilationTests.scala

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class CompilationTests {
147147
compileFile("tests/neg-custom-args/i3882.scala", allowDeepSubtypes),
148148
compileFile("tests/neg-custom-args/i4372.scala", allowDeepSubtypes),
149149
compileFile("tests/neg-custom-args/i1754.scala", allowDeepSubtypes),
150+
compileFile("tests/neg-custom-args/i12650.scala", allowDeepSubtypes),
150151
compileFile("tests/neg-custom-args/i9517.scala", defaultOptions.and("-Xprint-types")),
151152
compileFile("tests/neg-custom-args/i11637.scala", defaultOptions.and("-explain")),
152153
compileFile("tests/neg-custom-args/interop-polytypes.scala", allowDeepSubtypes.and("-Yexplicit-nulls")),

tests/neg-custom-args/i12650.check

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
-- Error: tests/neg-custom-args/i12650.scala:2:58 ----------------------------------------------------------------------
2+
2 | type This <: FooBase { type This <: FooBase.this.This } & FooBase { type This <: FooBase.this.This } // error
3+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
| cyclic reference involving type This

tests/neg-custom-args/i12650.scala

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trait FooBase {
2+
type This <: FooBase { type This <: FooBase.this.This } & FooBase { type This <: FooBase.this.This } // error
3+
}

0 commit comments

Comments
 (0)