Skip to content

Commit 0ddba5d

Browse files
committed
Fix match type extraction of a MatchAlias
Previously this failed with: ``` 14 | val x: Base.ExtractValue[Sub[Int *: EmptyTuple]] = 1 | ^ | Found: (1 : Int) | Required: Base.ExtractValue[Sub[Int *: EmptyTuple]] | | Note: a match type could not be fully reduced: | | trying to reduce Base.ExtractValue[Sub[Int *: EmptyTuple]] | failed since selector Sub[Int *: EmptyTuple] | does not uniquely determine parameter v in | case Base.BaseOf[v] => v | The computed bounds for the parameter are: | v = Tuple.Head[Int *: EmptyTuple] ``` Because the match type logic incorrectly believed that `v` was a non-alias TypeBounds.
1 parent 617f309 commit 0ddba5d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3518,7 +3518,7 @@ class MatchReducer(initctx: Context) extends TypeComparer(initctx) {
35183518
stableScrut.member(typeMemberName) match
35193519
case denot: SingleDenotation if denot.exists =>
35203520
val info = denot.info match
3521-
case TypeAlias(alias) => alias // Extract the alias
3521+
case alias: AliasingBounds => alias.alias // Extract the alias
35223522
case ClassInfo(prefix, cls, _, _, _) => prefix.select(cls) // Re-select the class from the prefix
35233523
case info => info // Notably, RealTypeBounds, which will eventually give a MatchResult.NoInstances
35243524
val infoRefersToSkolem = stableScrut.isInstanceOf[SkolemType] && stableScrut.occursIn(info)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
trait Base:
2+
type Value
3+
trait Sub[T <: Tuple] extends Base:
4+
type Value = Tuple.Head[T]
5+
object Base:
6+
type BaseOf[V] = Base { type Value = V }
7+
type ExtractValue[B <: Base] = B match
8+
case BaseOf[v] => v
9+
10+
class Test:
11+
val test: Base.ExtractValue[Sub[Int *: EmptyTuple]] = 1

0 commit comments

Comments
 (0)