Skip to content

Commit 7d50725

Browse files
Merge pull request #8320 from dotty-staging/fix-#8319
Fix #8319: Survive bad parameters in compareCaptured
2 parents 068c09c + a9f376b commit 7d50725

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,11 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
12391239
if (leftRoot.isStable || (ctx.isAfterTyper || ctx.mode.is(Mode.TypevarsMissContext))
12401240
&& leftRoot.member(tparam.name).exists) {
12411241
val captured = TypeRef(leftRoot, tparam)
1242-
isSubArg(captured, arg2)
1242+
try isSubArg(captured, arg2)
1243+
catch case ex: TypeError =>
1244+
// The captured reference could be illegal and cause a
1245+
// TypeError to be thrown in argDenot
1246+
false
12431247
}
12441248
else if (v > 0)
12451249
isSubType(paramBounds(tparam).hi, arg2)

tests/pos/i8319.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package example
2+
3+
sealed abstract class Tree[T]
4+
case class Lam[T,U]() extends Tree[Any]
5+
case class App[T,U]() extends Tree[Any]
6+
case class Var() extends Tree[Any]
7+
8+
object Branch:
9+
def unapply(branch: Lam[?,?] | App[?,?]): true = true
10+
11+
private def foo(s: Option[Tree[?]]) = s match // seems to only occur in a nested pattern
12+
case Some(_: Var) => true // must come first
13+
case Some(Branch()) => true // must be unapply and not direct type check
14+
case _ => false

0 commit comments

Comments
 (0)