Skip to content

Commit 9627957

Browse files
liufengyunsmarter
authored andcommitted
Fix #10085: check if enum case confirms to scrutinee type
1 parent 9ec34f8 commit 9627957

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -633,8 +633,6 @@ object TypeOps:
633633
* returned. Otherwise, `NoType` is returned.
634634
*/
635635
def refineUsingParent(parent: Type, child: Symbol)(using Context): Type = {
636-
if (child.isTerm && child.is(Case, butNot = Module)) return child.termRef // enum vals always match
637-
638636
// <local child> is a place holder from Scalac, it is hopeless to instantiate it.
639637
//
640638
// Quote from scalac (from nsc/symtab/classfile/Pickler.scala):

tests/patmat/i10085.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
enum Bool:
2+
case True
3+
case False
4+
5+
import Bool._
6+
7+
enum SBool[B <: Bool]:
8+
case STrue extends SBool[True.type]
9+
case SFalse extends SBool[False.type]
10+
11+
import SBool._
12+
13+
def f(b: SBool[True.type]): Unit = b match
14+
case STrue => ()

tests/patmat/i9190.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Test {
2+
case object X; type X = X.type
3+
case object Y; type Y = Y.type
4+
5+
type XorY = X | Y
6+
7+
val testee1: XorY = X
8+
testee1 match {
9+
case value: XorY => println(value)
10+
}
11+
12+
val testee2: Tuple1[XorY] = Tuple1(X)
13+
testee2 match {
14+
case Tuple1(value: XorY) => println(value)
15+
}
16+
17+
type IntOrString = Int | String
18+
19+
val testee3: Tuple1[IntOrString] = Tuple1(42)
20+
testee3 match {
21+
case Tuple1(value: IntOrString) => println(value)
22+
}
23+
}

0 commit comments

Comments
 (0)