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

Nowarn extension matching nonpublic member #21825

Merged
merged 2 commits into from
Nov 20, 2024

Conversation

som-snytt
Copy link
Contributor

Fixes #21816

Consider only public members when checking if an extension method actually extends.

A use site lint would be more thorough, when an extension is in scope but unused because of a visible matching member.

@som-snytt
Copy link
Contributor Author

Possibly, a private[p] extension could warn if there is a private[p] member.

Comment on lines 1172 to 1173
val memberIsPublic = (member.symbol.flags & AccessFlags).isEmpty && !member.symbol.privateWithin.exists
memberIsPublic && {
Copy link
Member

Choose a reason for hiding this comment

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

This could be member.symbol.isPublic but we can also be more precise and check for accessibility (untested):

Suggested change
val memberIsPublic = (member.symbol.flags & AccessFlags).isEmpty && !member.symbol.privateWithin.exists
memberIsPublic && {
val memberIsAccessible = member.symbol.isAccessibleFrom(target)
memberIsAccessible && {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll take another look during daylight, as my first swing was during interrupted sleep. I think the use case is an arbitrary use site, so that is the reason to require isPublic. I'll reconsider after coffee.

@Gedochao Gedochao requested a review from smarter October 28, 2024 12:10
@WojciechMazur WojciechMazur added the backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. label Nov 20, 2024
@WojciechMazur WojciechMazur added this to the 3.6.3 milestone Nov 20, 2024
@sjrd sjrd merged commit bd07317 into scala:main Nov 20, 2024
28 checks passed
@som-snytt som-snytt deleted the issue/21816-ext-warn branch November 20, 2024 15:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positive warning 'Extension method will never be selected'
4 participants