Skip to content

Commit 5a6aa23

Browse files
Make aliases of MatchAliases TypeAliases instead of MatchAliases
Allows for better de-aliasing
1 parent f0cd565 commit 5a6aa23

File tree

7 files changed

+48
-30
lines changed

7 files changed

+48
-30
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -458,14 +458,16 @@ object Types extends TypeUtils {
458458

459459
/** Is this a match type or a higher-kinded abstraction of one?
460460
*/
461-
def isMatch(using Context): Boolean = underlyingMatchType.exists
461+
def isMatch(using Context): Boolean = stripped match
462+
case tp: MatchType => true
463+
case tp: HKTypeLambda => tp.resType.isMatch
464+
case _ => false
462465

463-
def underlyingMatchType(using Context): Type = stripped match {
466+
def underlyingMatchType(using Context): Type = stripped match
464467
case tp: MatchType => tp
465468
case tp: HKTypeLambda => tp.resType.underlyingMatchType
466469
case tp: AppliedType if tp.isMatchAlias => tp.superType.underlyingMatchType
467470
case _ => NoType
468-
}
469471

470472
/** Is this a higher-kinded type lambda with given parameter variances?
471473
* These lambdas are used as the RHS of higher-kinded abstract types or
@@ -4578,16 +4580,15 @@ object Types extends TypeUtils {
45784580

45794581
override def tryNormalize(using Context): Type = tycon.stripTypeVar match {
45804582
case tycon: TypeRef =>
4581-
def tryMatchAlias = tycon.info match {
4582-
case MatchAlias(alias) =>
4583+
def tryMatchAlias = tycon.info match
4584+
case info: AliasingBounds if isMatchAlias =>
45834585
trace(i"normalize $this", typr, show = true) {
45844586
MatchTypeTrace.recurseWith(this) {
4585-
alias.applyIfParameterized(args.map(_.normalized)).tryNormalize
4587+
info.alias.applyIfParameterized(args.map(_.normalized)).tryNormalize
45864588
}
45874589
}
45884590
case _ =>
45894591
NoType
4590-
}
45914592
tryCompiletimeConstantFold.orElse(tryMatchAlias)
45924593
case _ =>
45934594
NoType
@@ -4598,6 +4599,7 @@ object Types extends TypeUtils {
45984599
case tycon: TypeRef =>
45994600
tycon.info match
46004601
case _: MatchAlias => true
4602+
case TypeAlias(alias) => alias.underlyingMatchType.exists
46014603
case _ => false
46024604
case _ => false
46034605

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

compiler/test/dotc/pos-test-pickling.blacklist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ i17149.scala
6464
tuple-fold.scala
6565
mt-redux-norm.perspective.scala
6666
i18211.scala
67+
10867.scala
6768

6869
# Opaque type
6970
i5720.scala

tests/neg-macros/i11795.scala

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/neg/i17944.check

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@
2929
| Therefore, reduction cannot advance to the remaining case
3030
|
3131
| case _ *: t => test.FindField0[t, ("i" : String), scala.compiletime.ops.int.S[(0 : Int)]]
32-
| trying to reduce test.FindField[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String)]
33-
| trying to reduce test.FindField0[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String), (0 : Int)]
34-
| failed since selector (("s" : String) ->> String, ("i" : String) ->> Int)
35-
| does not match case (("i" : String) ->> f) *: _ => (f, (0 : Int))
36-
| and cannot be shown to be disjoint from it either.
37-
| Therefore, reduction cannot advance to the remaining case
38-
|
39-
| case _ *: t => test.FindField0[t, ("i" : String), scala.compiletime.ops.int.S[(0 : Int)]]
4032
| trying to reduce test.FindField0[(("s" : String) ->> String, ("i" : String) ->> Int), ("i" : String), (0 : Int)]
4133
| failed since selector (("s" : String) ->> String, ("i" : String) ->> Int)
4234
| does not match case (("i" : String) ->> f) *: _ => (f, (0 : Int))

tests/pos-macros/i11795.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
import scala.quoted._
22
import scala.deriving._
33

4-
def blah2[P <: Product, MEL <: Tuple: Type, MET <: Tuple: Type](m: Mirror.ProductOf[P] { type MirroredElemLabels = MEL; type MirroredElemTypes = MET})(using Quotes) = {
4+
def blah[P <: Product]
5+
(m: Mirror.ProductOf[P])
6+
(using Quotes, Type[m.MirroredElemLabels], Type[m.MirroredElemTypes]) = {
7+
type z = Tuple.Zip[m.MirroredElemLabels, m.MirroredElemTypes]
8+
Type.of[z] // error
9+
()
10+
}
11+
12+
def blah2[P <: Product, MEL <: Tuple: Type, MET <: Tuple: Type]
13+
(m: Mirror.ProductOf[P] { type MirroredElemLabels = MEL; type MirroredElemTypes = MET})
14+
(using Quotes) = {
515
Type.of[Tuple.Zip[MEL, MET]]
616
()
717
}

tests/pos/i19821.scala

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
object Test:
3+
4+
trait T:
5+
type S
6+
type F = T.F[S]
7+
8+
def foo: F
9+
def bar: T.F[S]
10+
11+
object T:
12+
type F[X] = X match
13+
case String => Option[Int]
14+
15+
type G[X] = X match
16+
case Option[x] => Int
17+
18+
val t: T {type S = String} = ???
19+
20+
val b = t.bar
21+
val m1: T.G[b.type] = ???
22+
val _: Int = m1 // Ok
23+
24+
val f = t.foo
25+
val m: T.G[f.type] = ???
26+
val _: Int = m // Error before changes

0 commit comments

Comments
 (0)