Skip to content

Avoid more crashes in the presence of cyclic definitions #11011

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

Merged
merged 1 commit into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 -------------------------------------------------

Expand Down
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down
4 changes: 4 additions & 0 deletions tests/neg/i9299.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type F <: F = 1 match { // error
case _ => foo.foo // error // error
}
def foo(a: Int): Unit = ???
4 changes: 4 additions & 0 deletions tests/neg/i9299a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type T <: foo.a = Int match { // error
case "" => foo.b // error
}
def foo(x: Int): Unit = ???