Skip to content

Commit 6bafd95

Browse files
authored
Merge pull request #12153 from dotty-staging/fix-#8666
Make translucentSuperType handle match types
2 parents fd965ab + 71bac46 commit 6bafd95

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,7 +1888,15 @@ object Types {
18881888
case st => st
18891889
}
18901890

1891-
/** Same as superType, except that opaque types are treated as transparent aliases */
1891+
/** Same as superType, except for two differences:
1892+
* - opaque types are treated as transparent aliases
1893+
* - applied type are matchtype-reduced if possible
1894+
*
1895+
* Note: the reason to reduce match type aliases here and not in `superType`
1896+
* is that `superType` is context-independent and cached, whereas matchtype
1897+
* reduction depends on context and should not be cached (at least not without
1898+
* the very specific cache invalidation condition for matchtypes).
1899+
*/
18921900
def translucentSuperType(using Context): Type = superType
18931901
}
18941902

@@ -4011,7 +4019,7 @@ object Types {
40114019
case tycon: TypeRef if tycon.symbol.isOpaqueAlias =>
40124020
tycon.translucentSuperType.applyIfParameterized(args)
40134021
case _ =>
4014-
superType
4022+
tryNormalize.orElse(superType)
40154023
}
40164024

40174025
inline def map(inline op: Type => Type)(using Context) =

tests/pos/i7894.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
case class Box[T](t: T)
2+
3+
type Boxed[T <: Tuple] <: Tuple = T match {
4+
case EmptyTuple => EmptyTuple
5+
case h *: t => Box[h] *: Boxed[t]
6+
}
7+
8+
trait Cmp[T <: Tuple] { def cmp(t: T, b: Boxed[T]): Boolean }
9+
10+
object UnitCmp extends Cmp[EmptyTuple] {
11+
def cmp(t: EmptyTuple, b: EmptyTuple): Boolean = true
12+
}
13+
14+
object UnitCmp2 extends Cmp[EmptyTuple] {
15+
def cmp(t: EmptyTuple, b: Boxed[EmptyTuple]): Boolean = true
16+
}

tests/pos/i8666.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Foo[A, B]()
2+
3+
type FooSnd[X] = X match
4+
case Foo[_, b] => b
5+
6+
trait Bar[A]:
7+
def bar(h: FooSnd[A]): Int
8+
9+
val foo: Bar[Foo[String, Int]] = new Bar[Foo[String, Int]]:
10+
def bar(h: FooSnd[Foo[String, Int]]) = h

0 commit comments

Comments
 (0)