Skip to content

Stub code suggestion in missing method error message should use type parameters of present class, not parent trait #13076

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
jphmrst opened this issue Jul 15, 2021 · 2 comments · Fixed by #13529
Assignees
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug Spree Suitable for a future Spree
Milestone

Comments

@jphmrst
Copy link

jphmrst commented Jul 15, 2021

Compiler version

3.0.1 (and I've noticed this is earlier versions as well)

Minimized code

trait T[A, B] {
  def f(a: A): B
  def g(a: A, b: B): Unit
}

class C[X, Y] extends T[X, Y] {
}

Output

[info] compiling 1 Scala source to /home/jm/tmp/test/target/scala-3.0.1/classes ...
[error] -- Error: /home/jm/tmp/test/src/main/scala/Main.scala:7:6 ---------------------
[error] 7 |class C[X, Y] extends T[X, Y] {
[error]   |      ^
[error]   |      class C needs to be abstract, since:
[error]   |      it has 2 unimplemented members.
[error]   |      /** As seen from class C, the missing signatures are as follows.
[error]   |       *  For convenience, these are usable as stub implementations.
[error]   |       */
[error]   |        def f(a: A): B = ???
[error]   |        def g(a: A, b: B): Unit = ???
[error] one error found

Expectation

The error is obviously valid, but the suggested code is incorrect: C's type variables are X and Y, not A and B.

Bonus whine: the issue "goes away" if the trait only contains one of the two methods, because when it's just one missing method, there is no suggested stub code. It would be nice to get the stub code in those cases anyway!

@odersky odersky added itype:bug Spree Suitable for a future Spree and removed itype:bug labels Jul 15, 2021
@anatoliykmetyuk anatoliykmetyuk added the area:reporting Error reporting including formatting, implicit suggestions, etc label Jul 20, 2021
@griggt griggt self-assigned this Sep 7, 2021
@SethTisue SethTisue self-assigned this Sep 10, 2021
@SethTisue
Copy link
Member

SethTisue commented Sep 14, 2021

Scala 2 gets it right:

On line 6: error: class C needs to be abstract.
       Missing implementations for 2 members. Stub implementations follow:
         def f(a: X): Y = ???
         def g(a: X, b: Y): Unit = ???

griggt added a commit to griggt/dotty that referenced this issue Sep 14, 2021
@SethTisue
Copy link
Member

SethTisue commented Sep 14, 2021

Bonus whine: the issue "goes away" if the trait only contains one of the two methods, because when it's just one missing method, there is no suggested stub code. It would be nice to get the stub code in those cases anyway!

Mind opening a separate ticket on that? Our PR doesn't address this.

griggt added a commit to griggt/dotty that referenced this issue Sep 22, 2021
olsdavis pushed a commit to olsdavis/dotty that referenced this issue Apr 4, 2022
@Kordyjan Kordyjan added this to the 3.1.1 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug Spree Suitable for a future Spree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants