Skip to content

Commit 96b91d4

Browse files
authored
Merge pull request #12397 from dotty-staging/fix/i12390
GADTs: consider singletons when checking invariant refinement
2 parents 5411298 + 62a2256 commit 96b91d4

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ trait PatternTypeConstrainer { self: TypeComparer =>
196196
*/
197197
def constrainSimplePatternType(patternTp: Type, scrutineeTp: Type, widenParams: Boolean): Boolean = {
198198
def refinementIsInvariant(tp: Type): Boolean = tp match {
199+
case tp: SingletonType => true
199200
case tp: ClassInfo => tp.cls.is(Final) || tp.cls.is(Case)
200201
case tp: TypeProxy => refinementIsInvariant(tp.underlying)
201202
case _ => false

tests/pos/i12390-gadt.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
enum Func[-A, +B] {
2+
case Double extends Func[Int, Int]
3+
case ToString extends Func[Float, String]
4+
5+
def run: A => B = this match {
6+
case Double => (x: Int) => x * 2
7+
case ToString => (x: Float) => x.toString
8+
}
9+
}

0 commit comments

Comments
 (0)