Skip to content

Commit 4885463

Browse files
committed
Survive bad types in pattern alternatives
1 parent b3f9eb8 commit 4885463

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,13 @@ class Typer extends Namer
15491549

15501550
def typedAlternative(tree: untpd.Alternative, pt: Type)(implicit ctx: Context): Alternative = {
15511551
val nestedCtx = ctx.addMode(Mode.InPatternAlternative)
1552+
def ensureValueTypeOrWildcard(tree: Tree) =
1553+
if tree.tpe.isValueTypeOrWildcard then tree
1554+
else
1555+
assert(ctx.reporter.errorsReported)
1556+
tree.withType(defn.AnyType)
15521557
val trees1 = tree.trees.mapconserve(typed(_, pt)(nestedCtx))
1558+
.map(ensureValueTypeOrWildcard)
15531559
assignType(cpy.Alternative(tree)(trees1), trees1)
15541560
}
15551561

tests/neg/i7817.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
trait Foo[A]
2+
class A {
3+
def F[x : Foo]() = ???
4+
5+
Int match {
6+
case Int | F => () // error
7+
}
8+
}

0 commit comments

Comments
 (0)