Skip to content

Inconsistent extension methods with same signature [on different types] #10870

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
antognini opened this issue Dec 20, 2020 · 1 comment · Fixed by #10902
Closed

Inconsistent extension methods with same signature [on different types] #10870

antognini opened this issue Dec 20, 2020 · 1 comment · Fixed by #10902
Milestone

Comments

@antognini
Copy link

antognini commented Dec 20, 2020

Everything compiled with 3.0.0-M3:

This fails to compile:

package ext

final case class A()
final case class B(a:A)

extension(a:A) 
  def x = 5

extension(b:B)
  def x = b.a.x
//        ^^^^^
//        value x is not a member of ext.A.
//        An extension method was tried, but could not be fully constructed:
//
//        b.a

However, with explicit return types [Int], it compiles:

package ext

final case class A()
final case class B(a:A)

extension(a:A)
  def x:Int = 5

extension(b:B)
  def x:Int = b.a.x

Furthermore, when the very same example is split into separate compilation units, it fails with yet another error message:
ExtensionA.scala

package ext

final case class A()

extension(a:A)
  def x:Int = 5

ExtensionB.scala

package ext
import ext.A

final case class B(a:A)

extension(b:B)
  def x:Int = b.a.x
//^^^^^^^^^^^^^^^^^
//x is already defined as method x in ext.ExtensionA.scala

Expectation

Leveraging same extension signatures [on different types] should be consistently defined (is it possible or not?)
The behaviour should not depend on using/not using type inference, nor on same/separate compilation units.

@antognini
Copy link
Author

antognini commented Dec 22, 2020

In other words, I expect the three given examples to either compile/work or fail with the same error message (or similar error messages).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants