Skip to content

Commit 30db3fb

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 ca67e4d commit 30db3fb

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
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+
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) ||

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)