Skip to content

Commit d24b6f2

Browse files
committed
Issue recursion overflows in variance checking where they happen
1 parent d86b09d commit d24b6f2

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class VarianceChecker()(implicit ctx: Context) {
180180
sym.is(PrivateLocal) ||
181181
sym.name.is(InlineAccessorName) || // TODO: should we exclude all synthetic members?
182182
sym.is(TypeParam) && sym.owner.isClass // already taken care of in primary constructor of class
183-
tree match {
183+
try tree match {
184184
case defn: MemberDef if skip =>
185185
ctx.debuglog(s"Skipping variance check of ${sym.showDcl}")
186186
case tree: TypeDef =>
@@ -197,6 +197,9 @@ class VarianceChecker()(implicit ctx: Context) {
197197
vparamss foreach (_ foreach traverse)
198198
case _ =>
199199
}
200+
catch {
201+
case ex: TypeError => ctx.error(ex.toMessage, tree.sourcePos.focus)
202+
}
200203
}
201204
}
202205
}

tests/neg-custom-args/matchtype-loop.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object Test {
1111
val x: Int = g[Int] // error: found: L[Int], required: Int
1212

1313
def aa: LL[Boolean] = ???
14-
def bb: LL[Int] = ??? // error: recursion limit exceeded with reduce type LazyRef(Test.LL[Int]) match ...
14+
def bb: LL[Int] = ??? // error: recursion limit exceeded with reduce type LazyRef(Test.LL[Int]) match ... // error
1515
def gg[X]: LL[X] = ???
1616
val xx: Int = gg[Int] // error: recursion limit exceeded with reduce type LazyRef(Test.LL[Int]) match ...
1717
}

0 commit comments

Comments
 (0)