Skip to content

Extension method name collision across different source files #13089

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
soronpo opened this issue Jul 15, 2021 · 3 comments · Fixed by #13090
Closed

Extension method name collision across different source files #13089

soronpo opened this issue Jul 15, 2021 · 3 comments · Fixed by #13090
Milestone

Comments

@soronpo
Copy link
Contributor

soronpo commented Jul 15, 2021

Different extension methods in the same package, with the same name, but in different files collide.
If defined in the same source file no error.

Compiler version

v3.0.1

Minimized code

Minimized project at: https://github.com/soronpo/dottybug/tree/extension_collision

Test/Foo.scala

package Test

trait Foo
extension (foo : Foo)
  def fails : Unit = {}
  def works : Unit = {}

extension (bar : Bar)
  def works : Unit = {}

Test/Bar.scala

package Test

trait Bar
extension (bar : Bar)
  def fails : Unit = {}

Output

[error] -- [E161] Naming Error: C:\IdeaProjects\dottybug\src\main\scala\Test\Foo.scala:5:6 ----------------------------------
[error] 5 |  def fails : Unit = {}
[error]   |  ^^^^^^^^^^^^^^^^^^^^^
[error]   |  fails is already defined as method fails in C:\IdeaProjects\dottybug\src\main\scala\Test\Bar.scala

Expectation

No error.

@odersky
Copy link
Contributor

odersky commented Jul 16, 2021

It is an error. See clause 4 in https://dotty.epfl.ch/docs/reference/dropped-features/package-objects.html

If several top-level definitions are overloaded variants with the same name, they must all come from the same source file.

I have changed the error message to add that as an additional note.

@soronpo
Copy link
Contributor Author

soronpo commented Jul 16, 2021

What is the reason for this limitation?

@odersky
Copy link
Contributor

odersky commented Jul 16, 2021

Name resolution needs a single prefix to represent an overloaded reference. That prefix is the reference to the package object in which all alternatives are defined.

@Kordyjan Kordyjan added this to the 3.1.0 milestone Aug 2, 2023
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.

3 participants