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

Warn by default on mismatch of presence/absence of an empty parameter list when overriding #8846

Conversation

dwijnand
Copy link
Member

@dwijnand dwijnand commented Mar 30, 2020

In Scala 3 a method def foo: A (known as a "nullary" method) cannot override a method def foo(): A (recently coined as a "nilary" method - because it contains one, empty parameter list). We now warn in Scala 2.

The reverse (overriding def foo() with def foo) now also warns. But Java-defined methods are exempt, since Java doesn't have nullary methods but Scala users may wish to override non-side-effecting methods as nullary, for example override def toString = ....

This behavior was already available via -Xlint:nullary-override, but now warns by default, and errors under -Xsource:3. -Xlint:nullary-override is no longer accepted.

Strongly related to deprecating auto-application (#8833).

@scala-jenkins scala-jenkins added this to the 2.13.3 milestone Mar 30, 2020
@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Mar 30, 2020
Copy link
Contributor

@som-snytt som-snytt left a comment

Choose a reason for hiding this comment

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

Looks very fast.

Related linting: #8843

@dwijnand dwijnand changed the title Fast-track -Xlint:override-nullary to warn in 2.13 & error in 3 Fast-track deprecating overriding nullary & nilary methods Mar 31, 2020
@dwijnand dwijnand changed the title Fast-track deprecating overriding nullary & nilary methods Fast-track deprecating nullary/nilary method overriding Mar 31, 2020
Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

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

This should be considered together with #8833. I think we should either do them both in a minor 2.13 release, or none. Like 8833, it would be great to have a rewrite for overrides.

src/compiler/scala/tools/nsc/typechecker/Namers.scala Outdated Show resolved Hide resolved
src/compiler/scala/tools/nsc/typechecker/Namers.scala Outdated Show resolved Hide resolved
src/compiler/scala/tools/nsc/typechecker/Namers.scala Outdated Show resolved Hide resolved
src/compiler/scala/tools/nsc/typechecker/RefChecks.scala Outdated Show resolved Hide resolved
@dwijnand dwijnand force-pushed the promote-override-nullary-to-2.13-and-Xsource-3 branch 3 times, most recently from c50606f to 226273f Compare March 31, 2020 16:32
@SethTisue SethTisue modified the milestones: 2.13.3, 2.13.2 Mar 31, 2020
@SethTisue

This comment has been minimized.

@som-snytt
Copy link
Contributor

s/Fast-track/Slow-track

@dwijnand
Copy link
Member Author

Still faster than deprecating in 3.0 and removing in 3.1. 😄

@dwijnand dwijnand force-pushed the promote-override-nullary-to-2.13-and-Xsource-3 branch 2 times, most recently from 20aaee2 to 93c2664 Compare April 2, 2020 17:28
@dwijnand dwijnand force-pushed the promote-override-nullary-to-2.13-and-Xsource-3 branch from 93c2664 to 595a127 Compare April 3, 2020 15:30
@dwijnand dwijnand force-pushed the promote-override-nullary-to-2.13-and-Xsource-3 branch from 595a127 to 6ae3b2a Compare May 12, 2020 13:22
@SethTisue SethTisue added the prio:hi high priority (used only by core team, only near release time) label May 12, 2020
@dwijnand dwijnand force-pushed the promote-override-nullary-to-2.13-and-Xsource-3 branch from 6ae3b2a to 4216bb1 Compare May 13, 2020 10:16
@SethTisue
Copy link
Member

this seems ready for merge, but holding off for now until #8833 is also ready

@SethTisue
Copy link
Member

@dwijnand needs rebase

@SethTisue SethTisue removed the prio:hi high priority (used only by core team, only near release time) label Jun 1, 2020
@SethTisue SethTisue changed the title Fast-track deprecating nullary/nilary method overriding Deprecate non-matching overrides of nullary/nilary methods Jun 1, 2020
@SethTisue SethTisue changed the title Deprecate non-matching overrides of nullary/nilary methods Lint non-matching overrides of nullary/nilary methods Jun 1, 2020
@SethTisue
Copy link
Member

@dwijnand this is just a lint and not an actual deprecation... right?

@dwijnand
Copy link
Member Author

dwijnand commented Jun 2, 2020

@dwijnand this is just a lint and not an actual deprecation... right?

Yeah, I guess? I meant "deprecate" in "phase out" sense. Happy to call it a lint change.

@dwijnand dwijnand force-pushed the promote-override-nullary-to-2.13-and-Xsource-3 branch from 4216bb1 to 88e4569 Compare June 2, 2020 08:32
@SethTisue SethTisue force-pushed the promote-override-nullary-to-2.13-and-Xsource-3 branch from 88e4569 to f491020 Compare June 2, 2020 13:46
@SethTisue SethTisue self-assigned this Jun 2, 2020
Aka "promote -Xlint:override-nullary".

This means warn by default & error under -Xsource:3.
@dwijnand dwijnand force-pushed the promote-override-nullary-to-2.13-and-Xsource-3 branch from f491020 to 43438a6 Compare June 3, 2020 10:39
@SethTisue SethTisue merged commit aba4b5f into scala:2.13.x Jun 3, 2020
@SethTisue
Copy link
Member

@dwijnand could you improve the PR description to document this for folks who don't already know the context/motivation?

@dwijnand dwijnand deleted the promote-override-nullary-to-2.13-and-Xsource-3 branch June 4, 2020 05:56
@SethTisue SethTisue changed the title Lint non-matching overrides of nullary/nilary methods Warn by default on non-matching overrides of nullary/nilary methods Jun 23, 2020
@SethTisue SethTisue changed the title Warn by default on non-matching overrides of nullary/nilary methods Warn by default on mismatch of presence/absence of parentheses on overrides of parameterless methods Jun 24, 2020
@SethTisue SethTisue changed the title Warn by default on mismatch of presence/absence of parentheses on overrides of parameterless methods Warn by default on mismatch of presence/absence of an empty parameter list when overriding Jun 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes worth highlighting in next release notes
Projects
None yet
6 participants