Skip to content

Commit 6e370a9

Browse files
authored
Fix MT separate compilation bug (#18398)
2 parents d0cc4c1 + 34dbdd8 commit 6e370a9

File tree

6 files changed

+39
-1
lines changed

6 files changed

+39
-1
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

+16-1
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,22 @@ class TreeUnpickler(reader: TastyReader,
14631463
val fst = readTpt()
14641464
val (bound, scrut) =
14651465
if (nextUnsharedTag == CASEDEF) (EmptyTree, fst) else (fst, readTpt())
1466-
MatchTypeTree(bound, scrut, readCases(end))
1466+
val tpt = MatchTypeTree(bound, scrut, readCases(end))
1467+
// If a match type definition can reduce (e.g. Id in i18261.min)
1468+
// then it's important to trigger that reduction
1469+
// before a TypeVar is added to the constraint,
1470+
// associated to the match type's type parameter.
1471+
// Otherwise, if the reduction is triggered with that constraint,
1472+
// the reduction will be simplified,
1473+
// at which point the TypeVar will replace the type parameter
1474+
// and then that TypeVar will be cached
1475+
// as the reduction of the match type definition!
1476+
//
1477+
// We also override the type, as that's what Typer does.
1478+
// The difference here is that a match type that reduces to a non-match type
1479+
// makes the TypeRef for that definition will have a TypeAlias info instead of a MatchAlias.
1480+
tpt.overwriteType(tpt.tpe.normalized)
1481+
tpt
14671482
case TYPEBOUNDStpt =>
14681483
val lo = readTpt()
14691484
val hi = if currentAddr == end then lo else readTpt()

tests/pos/i18261.min/Main_0.scala

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
type Id[T] = Any match { case Any => T }
2+
3+
class Foo[A]
4+
object Foo:
5+
given inst[X, Y <: Id[X]]: Foo[Y] = new Foo[Y]

tests/pos/i18261.min/Test_1.scala

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Test:
2+
def test: Unit =
3+
summon[Foo[Int]]
4+
summon[Foo[Long]]

tests/pos/i18261/DFBits_0.scala

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
trait DFBits[W <: Int]
2+
3+
trait Candidate[R]:
4+
type OutW <: Int
5+
object Candidate:
6+
given [W <: Int, R <: Foo[DFBits[W]]]: Candidate[R] with
7+
type OutW = W

tests/pos/i18261/Foo_0.scala

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
type Foo[T] = T match
2+
case Any => T

tests/pos/i18261/Test_1.scala

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def baz[L](lhs: L)(using icL: Candidate[L]): DFBits[Int] = ???
2+
object Test:
3+
val x: DFBits[8] = ???
4+
val z: DFBits[Int] = baz(x)
5+
summon[Candidate[z.type]]

0 commit comments

Comments
 (0)