Skip to content

Commit db3a572

Browse files
committed
Fix scala#9166: Harden check for values in patterns based on class inheritance info
1 parent 758782a commit db3a572

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3808,9 +3808,12 @@ class Typer extends Namer
38083808
mapOver(tp)
38093809
}
38103810

3811-
if tree.symbol.isOneOf(Module | Enum)
3812-
&& !(tree.tpe frozen_<:< pt) // fast track
3813-
&& !(tree.tpe frozen_<:< approx(pt))
3811+
val sym = tree.symbol
3812+
3813+
if !sym.info.classSymbol.asClass.mayHaveCommonChild(pt.classSymbol.asClass)
3814+
|| sym.isOneOf(Module | Enum)
3815+
&& !(tree.tpe frozen_<:< pt) // fast track
3816+
&& !(tree.tpe frozen_<:< approx(pt))
38143817
then
38153818
// We could check whether `equals` is overriden.
38163819
// Reasons for not doing so:

tests/neg/i9166.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object UnitTest extends App {
2+
def foo(m: Unit) = m match {
3+
case runtime.BoxedUnit.UNIT => println("ok") // error
4+
}
5+
foo(())
6+
}

0 commit comments

Comments
 (0)