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

Suppress "extension method will never be selected" for overrides #20164

Merged
merged 2 commits into from
Apr 11, 2024

Conversation

smarter
Copy link
Member

@smarter smarter commented Apr 11, 2024

When we're overriding an existing extension method, we don't have the liberty
of renaming the method, so we shouldn't get warnings we can't do anything
about.

In daeee35, support for tests in the directory
`tests/pos-special/fatal-warnings` was dropped in favor of magic `//>` comments
in the regular `tests/pos` directory, but a few tests were forgotten in the
original directory and were thus not run. This commit moves them to the
appropriate directory with the correct magic comment.
When we're overriding an existing extension method, we don't have the liberty
of renaming the method, so we shouldn't get warnings we can't do anything
about.
@@ -1,4 +1,4 @@
//> using options -Wvalue-discard
//> using options -Xfatal-warnings -Wvalue-discard
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i.e. -Werror

if !target.typeSymbol.denot.isAliasType && !target.typeSymbol.denot.isOpaqueAlias && hidden
then report.warning(ExtensionNullifiedByMember(sym, target.typeSymbol), sym.srcPos)
def checkExtensionMethods(sym: Symbol)(using Context): Unit =
if sym.is(Extension) && !sym.nextOverriddenSymbol.exists then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the actual diff

@som-snytt
Copy link
Contributor

This is like the mitigation for "unused param" which says that if my method signature is constrained by an override, don't warn.

Here, I must supply the given (for some purpose), and I'm not interested in this extension. I could signal that with a LHS that is ???. It would be nice to have a special never marker.

But probably this case has an odor of niche. Overriders of extensions probably know what they're doing.

From the Doors song, Overriders on the Storm.

@smarter smarter enabled auto-merge April 11, 2024 17:37
@smarter smarter merged commit b096764 into scala:main Apr 11, 2024
17 checks passed
@smarter smarter deleted the silence-ext-override branch April 11, 2024 18:43
@Kordyjan Kordyjan added this to the 3.5.0 milestone May 10, 2024
WojciechMazur added a commit that referenced this pull request Jul 5, 2024
…rides" to LTS (#21060)

Backports #20164 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants