Skip to content

Commit 6aba5f7

Browse files
committed
Propagate Range through MatchType cases
1 parent 2df96f9 commit 6aba5f7

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5953,7 +5953,13 @@ object Types {
59535953
case _ =>
59545954
scrutinee match
59555955
case Range(lo, hi) => range(bound.bounds.lo, bound.bounds.hi)
5956-
case _ => tp.derivedMatchType(bound, scrutinee, cases)
5956+
case _ =>
5957+
if cases.exists(isRange) then
5958+
Range(
5959+
tp.derivedMatchType(bound, scrutinee, cases.map(lower)),
5960+
tp.derivedMatchType(bound, scrutinee, cases.map(upper)))
5961+
else
5962+
tp.derivedMatchType(bound, scrutinee, cases)
59575963

59585964
override protected def derivedSkolemType(tp: SkolemType, info: Type): Type =
59595965
if info eq tp.info then tp

tests/neg/i15352.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import scala.compiletime.*
2+
import scala.compiletime.ops.int.*
3+
4+
abstract sealed class HList :
5+
def ::[H](head: H): HNonEmpty[H, this.type] = HNonEmpty(head, this)
6+
7+
case object HNil extends HList
8+
case class HNonEmpty[H, T <: HList](head: H, tail: T) extends HList :
9+
type Elem[N <: Int] =
10+
N match
11+
case 0 => H
12+
case S[n1] => Elem[n1]
13+
14+
inline def apply[N <: Int](n: N): Elem[N] =
15+
n match
16+
case _: 0 => head
17+
case _: S[n1] => tail.asInstanceOf[HNonEmpty[?, ?]].apply(constValue[n1]) // error

0 commit comments

Comments
 (0)