-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #9994: Handle subtyping between two ThisType
#10008
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
Conversation
30db3fb
to
9aa5fef
Compare
@@ -310,6 +310,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling | |||
def compareThis = { | |||
val cls2 = tp2.cls | |||
tp1 match { | |||
case tp1: ThisType => | |||
(tp1.cls eq cls2) && recur(tp1.tref, tp2.tref) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about the condition here, isSubPrefix
does something different:
https://github.com/lampepfl/dotty/blob/0525ba010061c060d759d869c63ea5b54415f729/compiler/src/dotty/tools/dotc/core/TypeComparer.scala#L859-L863
Should we do the same here and get rid of isSubPrefix
, or is there a good reason for treating ThisType in prefix positions specially?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The isSubPrefix logic is needed to deal with double vision with self types.
I think the test here can be simplified to
case tp1: ThisType => tp1.cls eq cls2
The tref
is just used to carry the class.
9aa5fef
to
78c3925
Compare
@@ -310,6 +310,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling | |||
def compareThis = { | |||
val cls2 = tp2.cls | |||
tp1 match { | |||
case tp1: ThisType => | |||
(tp1.cls eq cls2) && recur(tp1.tref, tp2.tref) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The isSubPrefix logic is needed to deal with double vision with self types.
I think the test here can be simplified to
case tp1: ThisType => tp1.cls eq cls2
The tref
is just used to carry the class.
Doesn't the tref also determine the path? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise LGTM
@@ -310,6 +310,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling | |||
def compareThis = { | |||
val cls2 = tp2.cls | |||
tp1 match { | |||
case tp1: ThisType => | |||
(tp1.cls eq cls2) && recur(tp1.tref, tp2.tref) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(tp1.cls eq cls2) && recur(tp1.tref, tp2.tref) | |
tp1.cls eq cls2 |
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), this is a rare case because `ThisType` are interned, so usually two `ThisType` to the same class are `eq` and therefore `isSubType` returns true.
78c3925
to
212211d
Compare
Previously, i9994.scala failed when compiled with
-Ythrough-tasty
with:
The two types were pretty-printed the same but were actually:
and
Fixed by explicitly handling subtyping between two
ThisType
(previously we felt through tofourthTry
were the type ofthe lhs was widened).