Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MT separate compilation bug #18398

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]]