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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

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
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.

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