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

Warn on bad extensions of effectively final aliases #22233

Open
som-snytt opened this issue Dec 18, 2024 · 4 comments · May be fixed by #22362
Open

Warn on bad extensions of effectively final aliases #22233

som-snytt opened this issue Dec 18, 2024 · 4 comments · May be fixed by #22362
Labels
area:extension-methods area:linting Linting warnings enabled with -W or -Xlint itype:bug Spree Suitable for a future Spree

Comments

@som-snytt
Copy link
Contributor

Compiler version

3.6.2

Minimized code

//extension (s: java.lang.String) def length = 42 // warn
extension (s: String) def length = 42 // nowarn

Output

-- [E194] Potential Issue Warning: .../no-extension.scala:2:36 --
2 |extension (s: java.lang.String) def length = 42
  |                                    ^
  |Extension method length will never be selected
  |because String already has a member with the same name and compatible parameter types.

Expectation

The Scala alias should also warn, obviously.

Noticed at #17821.

@som-snytt som-snytt added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label area:linting Linting warnings enabled with -W or -Xlint and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Dec 18, 2024
@mbovel mbovel added the Spree Suitable for a future Spree label Jan 12, 2025
@mbovel
Copy link
Member

mbovel commented Jan 12, 2025

This issue was picked for the Scala Issue Spree of tomorrow, Monday, January 13th. @jan-pieter, @nmcb and @RoccoMathijn will be working on it. If you have any insight into the issue or guidance on how to fix it, please leave it here.

@mbovel
Copy link
Member

mbovel commented Jan 13, 2025

This will be @RoccoMathijn's first spree. Welcome! I would normally onboard new participants myself, but I would like to try something different today.

@jan-pieter and @nmcb, do you think you could help Rocco setting up his dev environment? Instructions are available at Getting Started and Setting up your IDE.

Then, it would be nice to quickly show him the main parts of the compiler:

@mbovel
Copy link
Member

mbovel commented Jan 13, 2025

About the issue itself, it seems to me that the check could be added in the RefChecks, a phase that does many well-formedness checks. The check might be added in RefChecks.checkExtensionMethods. You will need to add a new class in compiler/src/dotty/tools/dotc/reporting/messages.scala and report the error with report.warning or report.error—I am not sure if it should be a warning or an error, to be investigated.

@mbovel
Copy link
Member

mbovel commented Jan 13, 2025

If you have time, you could also look at #22232, which might be implemented in a similar way. Note the subtly different issue number 😄

@RoccoMathijn RoccoMathijn linked a pull request Jan 13, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:extension-methods area:linting Linting warnings enabled with -W or -Xlint itype:bug Spree Suitable for a future Spree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants