-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Warn if implicit default shadows given #23559
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
base: main
Are you sure you want to change the base?
Conversation
I didn't think to bootstrap; there are many instances, including the classic
|
Could offer a quickfix that inlines the default. |
4bb349c
to
9e53b78
Compare
I think this warning would be too noisy. Implicit defaults are there for a reason, we do not want to warn each time we use one. Also the change set looks too big and risky for such a relatively minor improvment. |
It would be interesting to see how frequently this warning pops up in the open community build to have an understanding of how frequently these situations occur. |
The recursion case is the Scala 2 lint. I find it very confusing for the reason cited on the ticket: was this intentional or an error? The compiler can't help you decide, but you feel better about it if someone had to type in For the In fact, it might be cleaner to refuse to supply defaults in those cases. However, I haven't spent time thinking abstractly about it. Noisy warnings are usually behind a flag; I wasn't sure if the compiler team wants to go that route, since flags (even for warnings) are also a maintenance burden and a challenge for cross-builds (especially under |
Not sure about indirect recursion (where Scala 2 warns for the same reason)
For fun, I'll try doing the check at |
Similar to the Scala 2 lint for "named boolean parameters" where you must name them if necessary to avoid ambiguity or accidentally switching args, one boolean parameter with a default might by OK (where there is one use site which requires the alternate behavior or state) but more than one is hard to follow, especially when recursing. But that sounds like a third-party lint. (The named boolean lint was added as a project-internal lint on Scala 2.) Implicit primitives add extra eye blinking. |
9e53b78
to
f038825
Compare
Put the recursion under a flag, but leave the titular warning. I didn't retry the scaladoc test, which probably requires the "special syntax" for a satisfying fix. |
As suspected, the scaladoc case is noticed, appropriately.
I will nowarn it for now, rather than munging the code. |
f038825
to
c7045ea
Compare
I overlooked that. Yes, this is indeed confusing and should be avoided. |
c7045ea
to
b144877
Compare
Fixes #23541
When supplying a default arg for an implicit application, warn if there is an implicit value available.
That is for
f(using x = v)
where a default is supplied inf(using x = v, y = default)
. The user might think the implicit value is supplied, which is not the case for explicitusing
; this is especially confusing in a recursive call, where the user intends to "replace" an implicit parameter.Separately, behind a flag, warn if any recursive call uses a default arg instead of passing the current parameter value.
"Wtailrec-default", "Warn when a tail-recursive call uses a default arg."