From 09efbe20379034083517b954afe7e46a1d9a2fa9 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sat, 26 Aug 2023 14:03:52 -0600 Subject: [PATCH] Fix MT separate compilation bug (bis) --- .../src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala | 8 +++++++- tests/pos/i18261.bis.min/Main_0.scala | 7 +++++++ tests/pos/i18261.bis.min/Test_1.scala | 4 ++++ tests/pos/i18261.bis/DFBits_0.scala | 7 +++++++ tests/pos/i18261.bis/Foo_0.scala | 4 ++++ tests/pos/i18261.bis/Test_1.scala | 5 +++++ 6 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i18261.bis.min/Main_0.scala create mode 100644 tests/pos/i18261.bis.min/Test_1.scala create mode 100644 tests/pos/i18261.bis/DFBits_0.scala create mode 100644 tests/pos/i18261.bis/Foo_0.scala create mode 100644 tests/pos/i18261.bis/Test_1.scala diff --git a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala index 7fa335afbf44..4f48519c4a92 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala @@ -1452,7 +1452,13 @@ class TreeUnpickler(reader: TastyReader, val args = until(end)(readTpt()) val tree = untpd.AppliedTypeTree(tycon, args) val ownType = ctx.typeAssigner.processAppliedType(tree, tycon.tpe.safeAppliedTo(args.tpes)) - tree.withType(postProcessFunction(ownType)) + val tp = postProcessFunction(ownType) + // Much like in the MATCHtpt case, + // normalize the type to avoid differences in the type of trees, + // (between joint compilation and separate compilation) + // which affects how types are compared in subtyping. + val tpn = tp.normalized + tree.withType(tpn) case ANNOTATEDtpt => Annotated(readTpt(), readTree()) case LAMBDAtpt => diff --git a/tests/pos/i18261.bis.min/Main_0.scala b/tests/pos/i18261.bis.min/Main_0.scala new file mode 100644 index 000000000000..18d746f60d42 --- /dev/null +++ b/tests/pos/i18261.bis.min/Main_0.scala @@ -0,0 +1,7 @@ +trait VAL + +type Foo[T, M] = M match { case VAL => T } + +class Cand[A] +object Cand: + given inst[X, Y <: Foo[X, VAL]]: Cand[Y] = new Cand[Y] diff --git a/tests/pos/i18261.bis.min/Test_1.scala b/tests/pos/i18261.bis.min/Test_1.scala new file mode 100644 index 000000000000..c5d62cc12267 --- /dev/null +++ b/tests/pos/i18261.bis.min/Test_1.scala @@ -0,0 +1,4 @@ +class Test: + def test: Unit = + summon[Cand[Int]] + summon[Cand[Long]] diff --git a/tests/pos/i18261.bis/DFBits_0.scala b/tests/pos/i18261.bis/DFBits_0.scala new file mode 100644 index 000000000000..0313faf04523 --- /dev/null +++ b/tests/pos/i18261.bis/DFBits_0.scala @@ -0,0 +1,7 @@ +trait DFBits[W <: Int] + +trait Candidate[R]: + type OutW <: Int +object Candidate: + given [W <: Int, R <: Foo[DFBits[W], VAL]]: Candidate[R] with + type OutW = W diff --git a/tests/pos/i18261.bis/Foo_0.scala b/tests/pos/i18261.bis/Foo_0.scala new file mode 100644 index 000000000000..47dd67b0984d --- /dev/null +++ b/tests/pos/i18261.bis/Foo_0.scala @@ -0,0 +1,4 @@ +trait VAL + +type Foo[T, M] = M match + case VAL => T diff --git a/tests/pos/i18261.bis/Test_1.scala b/tests/pos/i18261.bis/Test_1.scala new file mode 100644 index 000000000000..3b91847e3326 --- /dev/null +++ b/tests/pos/i18261.bis/Test_1.scala @@ -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]]