Skip to content

Commit 78c3925

Browse files
committed
Fix #9994: Handle subtyping between two ThisType
Previously, i9994.scala failed when compiled with `-Ythrough-tasty` with: 7 | def foo: this.type = this | ^ | error overriding method foo in trait Foo of type => (Bar.this : pkg.Bar); | method foo of type => (Bar.this : pkg.Bar) has incompatible type The two types were pretty-printed the same but were actually: ExprType(ThisType(TypeRef(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class <root>)),module class <empty>)),class Bar))) and ExprType(ThisType(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),class Bar))) Fixed by explicitly handling subtyping between two `ThisType` (previously we felt through to `fourthTry` were the type of the lhs was widened).
1 parent 97da3cb commit 78c3925

File tree

3 files changed

+9
-49
lines changed

3 files changed

+9
-49
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
310310
def compareThis = {
311311
val cls2 = tp2.cls
312312
tp1 match {
313+
case tp1: ThisType =>
314+
(tp1.cls eq cls2) && recur(tp1.tref, tp2.tref)
313315
case tp1: NamedType if cls2.is(Module) && cls2.eq(tp1.typeSymbol) =>
314316
cls2.isStaticOwner ||
315317
recur(tp1.prefix, cls2.owner.thisType) ||

stdlib-bootstrapped-tasty-tests/test/BootstrappedStdLibTASYyTest.scala

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -149,55 +149,6 @@ object BootstrappedStdLibTASYyTest:
149149
"scala.Long",
150150
"scala.Short",
151151
"scala.Unit",
152-
153-
// See #9994
154-
// -- Error:
155-
// | def addOne(kv: (K, V)) = {
156-
// | ^
157-
// |error overriding method addOne in trait Growable of type (elem: (K, V)): (TrieMap.this : scala.collection.concurrent.TrieMap[K, V]);
158-
// | method addOne of type (kv: (K, V)): (TrieMap.this : scala.collection.concurrent.TrieMap[K, V]) has incompatible type
159-
// -- Error:
160-
// | def subtractOne(k: K) = {
161-
// | ^
162-
// |error overriding method subtractOne in trait Shrinkable of type (elem: K): (TrieMap.this : scala.collection.concurrent.TrieMap[K, V]);
163-
// | method subtractOne of type (k: K): (TrieMap.this : scala.collection.concurrent.TrieMap[K, V]) has incompatible type
164-
"scala.collection.concurrent.TrieMap",
165-
"scala.collection.immutable.HashMapBuilder",
166-
"scala.collection.immutable.HashSetBuilder",
167-
"scala.collection.immutable.LazyList",
168-
"scala.collection.immutable.ListMapBuilder",
169-
"scala.collection.immutable.MapBuilderImpl",
170-
"scala.collection.immutable.SetBuilderImpl",
171-
"scala.collection.immutable.TreeSeqMap",
172-
"scala.collection.immutable.VectorBuilder",
173-
"scala.collection.immutable.VectorMapBuilder",
174-
"scala.collection.mutable.AnyRefMap",
175-
"scala.collection.mutable.ArrayBuilder",
176-
"scala.collection.mutable.CollisionProofHashMap",
177-
"scala.collection.mutable.LongMap",
178-
"scala.collection.mutable.SortedMap",
179-
"scala.collection.mutable.StringBuilder",
180-
"scala.jdk.AnyAccumulator",
181-
"scala.jdk.DoubleAccumulator",
182-
"scala.jdk.IntAccumulator",
183-
"scala.jdk.LongAccumulator",
184-
185-
// See #9994
186-
// -- Error:
187-
// | override def filterInPlace(p: A => Boolean): this.type = {
188-
// | ^
189-
// |error overriding method filterInPlace in trait SetOps of type (p: A => Boolean): (HashSet.this : scala.collection.mutable.HashSet[A]);
190-
// | method filterInPlace of type (p: A => Boolean): (HashSet.this : scala.collection.mutable.HashSet[A]) has incompatible type
191-
"scala.collection.mutable.HashSet",
192-
193-
// See #9994
194-
// -- Error:
195-
// | def force: this.type = {
196-
// | ^
197-
// |error overriding method force in class Stream of type => (Cons.this : scala.collection.immutable.Stream.Cons[A]);
198-
// | method force of type => (Cons.this : scala.collection.immutable.Stream.Cons[A]) has incompatible type
199-
"scala.collection.immutable.Stream",
200-
201152
)
202153

203154
/** Set of classes that cannot be loaded from TASTy */

tests/pos/i9994.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package pkg
2+
3+
trait Foo:
4+
def foo: this.type
5+
6+
final class Bar extends Foo:
7+
def foo: this.type = this

0 commit comments

Comments
 (0)