diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index a83628c65cf4..9273bef4b9f5 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -542,16 +542,17 @@ object Types { * Inherited by all type proxies. Overridden for And and Or types. * `Nil` for all other types. */ - def baseClasses(using Context): List[ClassSymbol] = { + def baseClasses(using Context): List[ClassSymbol] = record("baseClasses") - this match { - case tp: TypeProxy => - tp.underlying.baseClasses - case tp: ClassInfo => - tp.cls.classDenot.baseClasses - case _ => Nil - } - } + try + this match + case tp: TypeProxy => + tp.underlying.baseClasses + case tp: ClassInfo => + tp.cls.classDenot.baseClasses + case _ => Nil + catch case ex: Throwable => + handleRecursive("base classes of", this.show, ex) // ----- Member access ------------------------------------------------- diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 0969fe29009e..ef1f0d225d1a 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -1345,8 +1345,11 @@ class Namer { typer: Typer => // TODO: Look only at member of supertype instead? lazy val schema = paramFn(WildcardType) val site = sym.owner.thisType - - sym.owner.info.baseClasses.tail.foldLeft(NoType: Type) { (tp, cls) => + val bcs = sym.owner.info.baseClasses + if bcs.isEmpty then + assert(ctx.reporter.errorsReported) + NoType + else bcs.tail.foldLeft(NoType: Type) { (tp, cls) => def instantiatedResType(info: Type, paramss: List[List[Symbol]]): Type = info match case info: PolyType => paramss match diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 91ebd333c051..7ab102186a5e 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -1320,7 +1320,9 @@ class Typer extends Namer EmptyTree } case tp => - throw new java.lang.Error(i"internal error: closing over non-method $tp, pos = ${tree.span}") + if !tp.isErroneous then + throw new java.lang.Error(i"internal error: closing over non-method $tp, pos = ${tree.span}") + TypeTree(defn.AnyType) } else typed(tree.tpt) //println(i"typing closure $tree : ${meth1.tpe.widen}") diff --git a/tests/neg/i9299.scala b/tests/neg/i9299.scala new file mode 100644 index 000000000000..6c23d11553ff --- /dev/null +++ b/tests/neg/i9299.scala @@ -0,0 +1,4 @@ +type F <: F = 1 match { // error + case _ => foo.foo // error // error +} +def foo(a: Int): Unit = ??? diff --git a/tests/neg/i9299a.scala b/tests/neg/i9299a.scala new file mode 100644 index 000000000000..bc3ec57b947b --- /dev/null +++ b/tests/neg/i9299a.scala @@ -0,0 +1,4 @@ +type T <: foo.a = Int match { // error + case "" => foo.b // error +} +def foo(x: Int): Unit = ??? \ No newline at end of file