Skip to content

Commit 3c18a2a

Browse files
committed
Fix #1255: check scrutinee is subtype of selector
1 parent 939bc70 commit 3c18a2a

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,6 +1596,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
15961596
tree match {
15971597
case _: RefTree | _: Literal if !isVarPattern(tree) =>
15981598
checkCanEqual(pt, wtp, tree.pos)(ctx.retractMode(Mode.Pattern))
1599+
case t: Typed if !(wtp <:< pt) =>
1600+
ctx.error(s"scrutinee is incompatible with pattern type, needs to be a subclass of `${pt.show}`", tree.pos)
15991601
case _ =>
16001602
}
16011603
tree

tests/neg/i1255.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object Test {
2+
def foo(x: Option[Int]) = x match {
3+
case Some(_: Double) => true
4+
case None => false
5+
}
6+
}

0 commit comments

Comments
 (0)