Skip to content
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

False positive extension method will never be selected #22821

Open
abosshard opened this issue Mar 17, 2025 · 2 comments · May be fixed by #22825
Open

False positive extension method will never be selected #22821

abosshard opened this issue Mar 17, 2025 · 2 comments · May be fixed by #22825
Assignees
Labels
area:extension-methods area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug

Comments

@abosshard
Copy link

Compiler version

3.5.0 and later

Minimized code

//> using scala "3.6.4"

class A:
  def f(i: Int) = ()

extension (self: A)
  def f() = println("extension") // [warn]: Extension method f will never be selected from type A

A().f()

Output

[warn] ./Example.sc:7:6
[warn] Extension method f will never be selected from type A
[warn] because A already has a member with the same name and compatible parameter types.
[warn]  def f() = println("extension") // [warn]: Extension method f will never be selected from type A
[warn]      ^
extension

Expectation

No warning, because the extension method is actually selected in this case.

@abosshard abosshard added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 17, 2025
@abosshard
Copy link
Author

I think the issue should have the labels "area:linting" and "area:extension-methods", but it seems I don't have the right to assign them. Thanks!

@som-snytt som-snytt self-assigned this Mar 17, 2025
@som-snytt som-snytt added area:reporting Error reporting including formatting, implicit suggestions, etc area:extension-methods and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 17, 2025
@som-snytt
Copy link
Contributor

som-snytt commented Mar 17, 2025

There is a subtle distinction between "lints" "turned on" by -W and the rare warnings issued unconditionally. (Migration warnings are conditional because dependent on user config.) (Not sure if the compiler team wants to maintain the subtle distinction.)

Probably this one should be a lint, but a scalafix rule could warn more about "collisions" due to extension methods.

There is an existing test for a "nilary" extension method but not for "nullary". Thanks for the report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:extension-methods area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants