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
Extend -Xlint:nullary-override
for the reverse (nilary) case
#8293
Conversation
The limited
|
2a0f629
to
9a36594
Compare
I think we should postpone any nullary/nilary changes to 2.13.3 (will do that for the other related PRs as well) |
9a36594
to
8b72825
Compare
This just enhances the optional warning and encourages alignment with Scala 3. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. It could be that this needs to be pushed further into -Xsource:2.14
or even on-by-default-land, but we can tweak that post-merge.
Lint warns when an override adds an empty parameter section, but not the other way around, when an empty parameter section is automatically supplied to match the overridden member. An overriding nullary method has already been upgraded to its matching nilary, so refchecks is unfortunately too late.
8b72825
to
41e2411
Compare
Added a commit (not prematurely squashed) to use the warning category; the test tests that the warning is nowarnable; and the doc for nowarn is fixed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a great addition. Thanks, Som.
repeating this just to make sure nobody hits “merge” for now |
repeating this in case @lrytz retracts his objection because it uses his warning framework. Or his nowarning framework. |
I was swimming in some confusion about the entrie situation when I made that comment :-) We should still merge improvements in this area that are non-controversial. For the issue here, maybe we can first investigate the viability of an alternative approach: allow
|
(by "allow" i mean the implementation; for users, any mismatch in overriding should trigger a warning) |
Since this PR doesn't introduce any options or cruft, I hear lrytz saying we can merge this and get the doc fix, and then further experiments with parens may update the check files. The current spec is surely all about Java parens: implementing a trait in Java. But maybe there is no downside to letting overrides add or remove empty parens willy-nilly. Which is an apt pun for nillary. The advance warning for eta-expansion is true only when expected type:
|
The next change is to enable override warnings under -Xsource:2.14 (aka -Xsource:3). |
-Xlint:nullary-override
for the reverse (nilary) case
@som-snytt I took the liberty of updating the PR title and description for the current state of the PR. But please check as I might've made mistakes (or killed your PR description "vibe" - edit away 😄). Also, looking back again, I'm not sure about the tests: asides from the Lastly, should this addition be under the same lint warning? It's simpler, but do we think users might want to enable one but not the other? |
@dwijnand thanks for the improved doc factor. I think having both checks exercised in the nullary-override test shows that both warnings are shown and also that they are reported in an unexpected order. It looks like I added the nowarn test when I added warning category support. As to having a separate lint, the mechanics of that are just heavy enough to weigh against it. Also they are really the same, a mismatch in scala 3. Also too many options, and what would you name it. |
|
Right, except for a possible pun on "nilary clinton", it's not meaningful to folks not accustomed to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
investigate the viability of an alternative approach: allow
f
to overridef()
without synthetically inserting the parameter list.
For the record, previous discussion about this is here: #8445 (comment).
The adaptation leaks, that's why I'd prefer to change the implementation:
scala> class C { def name = "C"; override def toString = name }
defined class C
scala> (new C).name(0)
res0: Char = C
scala> (new C).toString(0)
^
error: no arguments allowed for nullary method toString: ()String
That said, I'm fine merging this as a step in the right direction.
I agree it will be nice to respect the parens as written. There is an analogy in constructors, although the different syntax ruins it:
|
The suggested change would likely also fix scala/bug#11158 (and be an alternative to #7625) |
If
def m
is overriding adef m()
-Xlint:nullary-override
now reports it as well, unless thedef m()
is defined in Java (such as Object's toString or hashCode) which are exempt.