Skip to content

Commit 6e60814

Browse files
committed
Fix #7807: Add case for MatchTypes to ApproximatingTypeMap
1 parent d45fea0 commit 6e60814

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3966,7 +3966,6 @@ object Types {
39663966
* and `X_1,...X_n` are the type variables bound in `patternType`
39673967
*/
39683968
abstract case class MatchType(bound: Type, scrutinee: Type, cases: List[Type]) extends CachedProxyType with ValueType {
3969-
39703969
def derivedMatchType(bound: Type, scrutinee: Type, cases: List[Type])(implicit ctx: Context): MatchType =
39713970
if (bound.eq(this.bound) && scrutinee.eq(this.scrutinee) && cases.eqElements(this.cases)) this
39723971
else MatchType(bound, scrutinee, cases)
@@ -4945,6 +4944,15 @@ object Types {
49454944
override protected def derivedWildcardType(tp: WildcardType, bounds: Type): WildcardType =
49464945
tp.derivedWildcardType(rangeToBounds(bounds))
49474946

4947+
override protected def derivedMatchType(tp: MatchType, bound: Type, scrutinee: Type, cases: List[Type]): Type =
4948+
bound match
4949+
case Range(lo, hi) =>
4950+
range(derivedMatchType(tp, lo, scrutinee, cases), derivedMatchType(tp, hi, scrutinee, cases))
4951+
case _ =>
4952+
scrutinee match
4953+
case Range(lo, hi) => range(bound.bounds.lo, bound.bounds.hi)
4954+
case _ => tp.derivedMatchType(bound, scrutinee, cases)
4955+
49484956
override protected def derivedSkolemType(tp: SkolemType, info: Type): Type = info match {
49494957
case Range(lo, hi) =>
49504958
range(tp.derivedSkolemType(lo), tp.derivedSkolemType(hi))

tests/pos/i7807.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Test with
2+
3+
def flip: (x: 0 | 1) => x.type match { case 0 => 1 case 1 => 0 } = ???

0 commit comments

Comments
 (0)