Skip to content

Commit 1641c10

Browse files
committed
Fix #7815: Harden typedTypeCase for MatchTypes
1 parent cd71999 commit 1641c10

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,10 @@ class Typer extends Namer
12311231
def caseRest(implicit ctx: Context) = {
12321232
val pat1 = checkSimpleKinded(typedType(cdef.pat)(ctx.addMode(Mode.Pattern)))
12331233
val pat2 = indexPattern(cdef).transform(pat1)
1234-
val body1 = typedType(cdef.body, pt)
1234+
var body1 = typedType(cdef.body, pt)
1235+
if !body1.isType then
1236+
assert(ctx.reporter.errorsReported)
1237+
body1 = TypeTree(errorType("<error: not a type>", cdef.sourcePos))
12351238
assignType(cpy.CaseDef(cdef)(pat2, EmptyTree, body1), pat2, body1)
12361239
}
12371240
caseRest(ctx.fresh.setFreshGADTBounds.setNewScope)

tests/neg/i7815.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trait A {
2+
val a: Int match { case Int => this } // error
3+
}

0 commit comments

Comments
 (0)