Skip to content

Commit 38d2524

Browse files
committed
Dealias an applied match alias
1 parent e994cf0 commit 38d2524

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1441,9 +1441,12 @@ object Types extends TypeUtils {
14411441
private def dealias1(keep: AnnotatedType => Context ?=> Boolean, keepOpaques: Boolean)(using Context): Type = this match {
14421442
case tp: TypeRef =>
14431443
if (tp.symbol.isClass) tp
1444+
else if keepOpaques && tp.symbol.is(Opaque) then tp
14441445
else tp.info match {
1445-
case TypeAlias(alias) if !(keepOpaques && tp.symbol.is(Opaque)) =>
1446+
case TypeAlias(alias) =>
14461447
alias.dealias1(keep, keepOpaques)
1448+
case MatchAlias(alias: AppliedType) =>
1449+
(alias: Type).dealias1(keep, keepOpaques)
14471450
case _ => tp
14481451
}
14491452
case app @ AppliedType(tycon, _) =>

compiler/src/dotty/tools/dotc/inlines/Inlines.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,16 +446,13 @@ object Inlines:
446446
evidence
447447
}
448448

449-
def unrollTupleTypes(tpe: Type): Option[List[Type]] = tpe.dealias match
449+
def unrollTupleTypes(tpe: Type): Option[List[Type]] = tpe.dealias.normalized match
450450
case AppliedType(tycon, args) if defn.isTupleClass(tycon.typeSymbol) =>
451451
Some(args)
452452
case AppliedType(tycon, head :: tail :: Nil) if tycon.isRef(defn.PairClass) =>
453453
unrollTupleTypes(tail).map(head :: _)
454454
case tpe: TermRef if tpe.symbol == defn.EmptyTupleModule =>
455455
Some(Nil)
456-
case tpRef: TypeRef => tpRef.info match
457-
case MatchAlias(alias) => unrollTupleTypes(alias.tryNormalize)
458-
case _ => None
459456
case _ =>
460457
None
461458

tests/pos/i19821.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
type F[X] = X match { case String => Option[Int] }
2+
type G[X] = X match { case Option[x] => Int }
3+
4+
trait T:
5+
type S
6+
val opt1: F[S]
7+
val opt2: O1
8+
type O1 = F[S]
9+
10+
class Test:
11+
def test: Unit =
12+
val t: T { type S = String } = ???
13+
14+
val i1: G[t.opt1.type] = ???
15+
val j1: Int = i1
16+
17+
val i2: G[t.opt2.type] = ???
18+
val j2: Int = i2 // was:
19+
//[E007] Type Mismatch Error: tests/pos/i19821.scala:17:18 --------------------
20+
// val j2: Int = i2
21+
// ^^
22+
// Found: (i2 : G[(t.bar : t.O)])
23+
// Required: Int

0 commit comments

Comments
 (0)