Skip to content

Nowarn receiver of extension taking params #23351

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

Merged
merged 4 commits into from
Jun 17, 2025

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented Jun 11, 2025

Fixes #23349

Extensions are regular methods, but the "receiver" parameter is exempt from the unused check. By error, previously x.m was exempt but not x.f(y).

(The reason for the exemption may be that the method expressed as a member of the receiver type may make no reference to this, without warning.)

Check for parameters used only in default arg expressions. A parameter may be aliased in a default arg getter method, so a usage of that getter param counts as a usage of the method param (or class param). Defaults of class params are found in the class companion.

@som-snytt som-snytt changed the title Nowarn extension taking params Nowarn receiver of extension taking params Jun 11, 2025
@som-snytt som-snytt force-pushed the issue/23349-spurious-explicits branch from 2359cae to d45f06e Compare June 11, 2025 16:08
@som-snytt som-snytt force-pushed the issue/23349-spurious-explicits branch from d45f06e to aef0a25 Compare June 12, 2025 03:25
@som-snytt
Copy link
Contributor Author

There was a sad regression test that is nice to fix at https://github.com/scala/scala3/blob/3.7.1/tests/warn/i15503e.scala#L95

  def f(i: Int)(j: Int = i * 2) = j // warn I guess

Maybe that is called a "concession test".

@som-snytt som-snytt marked this pull request as ready for review June 12, 2025 03:36
@Gedochao Gedochao requested a review from tgodzik June 12, 2025 05:16
Copy link
Contributor

@tgodzik tgodzik left a comment

Choose a reason for hiding this comment

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

LGTM!

@tgodzik tgodzik merged commit a110500 into scala:main Jun 17, 2025
29 checks passed
@som-snytt som-snytt deleted the issue/23349-spurious-explicits branch June 17, 2025 20:29
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.

Probably regression in v3.7.x: false positive warning with -Wunused:explicits
2 participants