Skip to content

Commit

Permalink
Fix MT separate compilation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Aug 14, 2023
1 parent c5adafc commit 34dbdd8
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 1 deletion.
17 changes: 16 additions & 1 deletion compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,22 @@ class TreeUnpickler(reader: TastyReader,
val fst = readTpt()
val (bound, scrut) =
if (nextUnsharedTag == CASEDEF) (EmptyTree, fst) else (fst, readTpt())
MatchTypeTree(bound, scrut, readCases(end))
val tpt = MatchTypeTree(bound, scrut, readCases(end))
// If a match type definition can reduce (e.g. Id in i18261.min)
// then it's important to trigger that reduction
// before a TypeVar is added to the constraint,
// associated to the match type's type parameter.
// Otherwise, if the reduction is triggered with that constraint,
// the reduction will be simplified,
// at which point the TypeVar will replace the type parameter
// and then that TypeVar will be cached
// as the reduction of the match type definition!
//
// We also override the type, as that's what Typer does.
// The difference here is that a match type that reduces to a non-match type
// makes the TypeRef for that definition will have a TypeAlias info instead of a MatchAlias.
tpt.overwriteType(tpt.tpe.normalized)
tpt
case TYPEBOUNDStpt =>
val lo = readTpt()
val hi = if currentAddr == end then lo else readTpt()
Expand Down
5 changes: 5 additions & 0 deletions tests/pos/i18261.min/Main_0.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type Id[T] = Any match { case Any => T }

class Foo[A]
object Foo:
given inst[X, Y <: Id[X]]: Foo[Y] = new Foo[Y]
4 changes: 4 additions & 0 deletions tests/pos/i18261.min/Test_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Test:
def test: Unit =
summon[Foo[Int]]
summon[Foo[Long]]
7 changes: 7 additions & 0 deletions tests/pos/i18261/DFBits_0.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
trait DFBits[W <: Int]

trait Candidate[R]:
type OutW <: Int
object Candidate:
given [W <: Int, R <: Foo[DFBits[W]]]: Candidate[R] with
type OutW = W
2 changes: 2 additions & 0 deletions tests/pos/i18261/Foo_0.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
type Foo[T] = T match
case Any => T
5 changes: 5 additions & 0 deletions tests/pos/i18261/Test_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
def baz[L](lhs: L)(using icL: Candidate[L]): DFBits[Int] = ???
object Test:
val x: DFBits[8] = ???
val z: DFBits[Int] = baz(x)
summon[Candidate[z.type]]

0 comments on commit 34dbdd8

Please sign in to comment.