Skip to content

Commit 9d7a17a

Browse files
authored
Merge pull request #11011 from dotty-staging/fix-#9299
Avoid more crashes in the presence of cyclic definitions
2 parents 50a2d66 + 56e0e91 commit 9d7a17a

File tree

5 files changed

+26
-12
lines changed

5 files changed

+26
-12
lines changed

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -542,16 +542,17 @@ object Types {
542542
* Inherited by all type proxies. Overridden for And and Or types.
543543
* `Nil` for all other types.
544544
*/
545-
def baseClasses(using Context): List[ClassSymbol] = {
545+
def baseClasses(using Context): List[ClassSymbol] =
546546
record("baseClasses")
547-
this match {
548-
case tp: TypeProxy =>
549-
tp.underlying.baseClasses
550-
case tp: ClassInfo =>
551-
tp.cls.classDenot.baseClasses
552-
case _ => Nil
553-
}
554-
}
547+
try
548+
this match
549+
case tp: TypeProxy =>
550+
tp.underlying.baseClasses
551+
case tp: ClassInfo =>
552+
tp.cls.classDenot.baseClasses
553+
case _ => Nil
554+
catch case ex: Throwable =>
555+
handleRecursive("base classes of", this.show, ex)
555556

556557
// ----- Member access -------------------------------------------------
557558

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1345,8 +1345,11 @@ class Namer { typer: Typer =>
13451345
// TODO: Look only at member of supertype instead?
13461346
lazy val schema = paramFn(WildcardType)
13471347
val site = sym.owner.thisType
1348-
1349-
sym.owner.info.baseClasses.tail.foldLeft(NoType: Type) { (tp, cls) =>
1348+
val bcs = sym.owner.info.baseClasses
1349+
if bcs.isEmpty then
1350+
assert(ctx.reporter.errorsReported)
1351+
NoType
1352+
else bcs.tail.foldLeft(NoType: Type) { (tp, cls) =>
13501353
def instantiatedResType(info: Type, paramss: List[List[Symbol]]): Type = info match
13511354
case info: PolyType =>
13521355
paramss match

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,9 @@ class Typer extends Namer
13201320
EmptyTree
13211321
}
13221322
case tp =>
1323-
throw new java.lang.Error(i"internal error: closing over non-method $tp, pos = ${tree.span}")
1323+
if !tp.isErroneous then
1324+
throw new java.lang.Error(i"internal error: closing over non-method $tp, pos = ${tree.span}")
1325+
TypeTree(defn.AnyType)
13241326
}
13251327
else typed(tree.tpt)
13261328
//println(i"typing closure $tree : ${meth1.tpe.widen}")

tests/neg/i9299.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type F <: F = 1 match { // error
2+
case _ => foo.foo // error // error
3+
}
4+
def foo(a: Int): Unit = ???

tests/neg/i9299a.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
type T <: foo.a = Int match { // error
2+
case "" => foo.b // error
3+
}
4+
def foo(x: Int): Unit = ???

0 commit comments

Comments
 (0)