Skip to content

Overriding method returning this type in final class from TASTy #9994

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

Closed
nicolasstucki opened this issue Oct 13, 2020 · 2 comments
Closed

Overriding method returning this type in final class from TASTy #9994

nicolasstucki opened this issue Oct 13, 2020 · 2 comments
Assignees

Comments

@nicolasstucki
Copy link
Contributor

Full Reproduction

$ mkdir out/testStringBuilderFromTasty
$ sbt
sbt:dotty> dotty-bootstrapped/dotc -d out/testStringBuilderFromTasty community-build/community-projects/stdLib213/src/library/scala/collection/mutable/StringBuilder.scala
sbt:dotty> dotty-bootstrapped/dotc -from-tasty -classpath out/testStringBuilderFromTasty scala.collection.mutable.StringBuilder
...
-- Error: community-build/community-projects/stdLib213/src/library/scala/collection/mutable/StringBuilder.scala:87:6 
87 |  def addOne(x: Char): this.type = { underlying.append(x); this }
   |      ^
   |error overriding method addOne in trait Growable of type (elem: Char): (StringBuilder.this : StringBuilder);
   |  method addOne of type (x: Char): (StringBuilder.this : StringBuilder) has incompatible type

Minimized Reproduction

Bar.scala

trait Foo:
  def foo: this.type

final class Bar extends Foo:
  def foo: this.type = this
$ mkdir out/test
$ sbt
sbt:dotty> dotty-bootstrapped/dotc StringBuilder.scala -d out/test
sbt:dotty> dotty-bootstrapped/dotc -from-tasty -classpath out/test Bar
@smarter
Copy link
Member

smarter commented Oct 13, 2020

Also reproducible using -Ythrough-tasty.

@smarter
Copy link
Member

smarter commented Oct 13, 2020

the two types seen as incompatible both pretty print as => (Bar.this : Bar) but their internal representation is:

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)))

which aren't subtypes apparently. It seems that we're missing a case in TypeComparer to handle two ThisType which are different but represent the same type?

smarter added a commit to dotty-staging/dotty that referenced this issue Oct 15, 2020
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).
smarter added a commit to dotty-staging/dotty that referenced this issue Oct 15, 2020
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).
smarter added a commit to smarter/dotty that referenced this issue Oct 21, 2020
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).
bishabosha added a commit that referenced this issue Oct 27, 2020
Fix #9994: Handle subtyping between two `ThisType`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants