Skip to content

Fix #4936: Forbid (or warn on) redundant/illegal object flags #4973

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

Conversation

Blaisorblade
Copy link
Contributor

@Blaisorblade Blaisorblade commented Aug 21, 2018

Forbid/warn on redundant/illegal object flags — fix #4936.

  • Stop using final object in our sources.
  • Give error for abstract and sealed objects, warning for final ones (as long as
    Forbid final object bug#11094 is open).

@smarter
Copy link
Member

smarter commented Aug 21, 2018

could be done in the parser no?

@Blaisorblade Blaisorblade force-pushed the fix-4936-forbidden-object-flags branch from 1ecf67b to 91b540c Compare August 21, 2018 02:07
@Blaisorblade Blaisorblade self-assigned this Aug 21, 2018
@odersky
Copy link
Contributor

odersky commented Jan 12, 2019

@Blaisorblade Inactive for almost 5 months. Can you either finish the PR or close it and re-assign the issue to someone else? Thanks

@Blaisorblade Blaisorblade force-pushed the fix-4936-forbidden-object-flags branch from 6dcd45e to debfde5 Compare January 15, 2019 18:46
@@ -1 +0,0 @@
sealed object Fun
Copy link
Contributor Author

@Blaisorblade Blaisorblade Jan 15, 2019

Choose a reason for hiding this comment

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

This testcase was added in #3486 for #3471 to ensure the compiler didn't crash.
During the discussion, it was demanded that final be handled at the same time, which is done here: #3486 (comment).

@Blaisorblade Blaisorblade changed the title Forbid redundant/illegal object flags Forbid (or warn on) redundant/illegal object flags Jan 15, 2019
@Blaisorblade Blaisorblade changed the title Forbid (or warn on) redundant/illegal object flags Fix #4936: Forbid (or warn on) redundant/illegal object flags Jan 15, 2019
@Blaisorblade Blaisorblade added area:reporting Error reporting including formatting, implicit suggestions, etc and removed stat:wip labels Jan 15, 2019
@Blaisorblade Blaisorblade force-pushed the fix-4936-forbidden-object-flags branch from debfde5 to 0e6095b Compare January 15, 2019 19:02
@allanrenucci
Copy link
Contributor

I think @odersky's comment applies to this PR

@Blaisorblade
Copy link
Contributor Author

That comment does apply, and I guess it overrides contrary suggestions above.

@Blaisorblade
Copy link
Contributor Author

On hold, waiting for decision on flags in #5525.

@Blaisorblade Blaisorblade force-pushed the fix-4936-forbidden-object-flags branch from 19ce196 to 2b6ec51 Compare January 15, 2019 21:07
@Blaisorblade
Copy link
Contributor Author

FWIW, the current CI failure is spurious; while this is on hold, I'd like to get it working as far as possible.

Copy link
Contributor

@nicolasstucki nicolasstucki left a comment

Choose a reason for hiding this comment

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

Add a test in tests/neg-custom-args/fatal-warnings with

final object Foo // error

Otherwise LGTM

@Blaisorblade Blaisorblade force-pushed the fix-4936-forbidden-object-flags branch from 799c6c2 to d547ea4 Compare January 16, 2019 10:01
Fix scala#4936 in parser.

- Stop using final object in our sources.
- Give error for abstract and sealed objects, warning for final ones (as long as
- scala/bug#11094 is open).
- Address review comments.
@Blaisorblade
Copy link
Contributor Author

@nicolasstucki I've done that change, so it could be merged, but @odersky in #5525 suggested centralizing flag checking. Assigning to you for decision.

@nicolasstucki
Copy link
Contributor

We can centralize them later in #5525.

@nicolasstucki nicolasstucki merged commit 6156757 into scala:master Jan 16, 2019
@nicolasstucki nicolasstucki deleted the fix-4936-forbidden-object-flags branch January 16, 2019 10:21
@odersky
Copy link
Contributor

odersky commented Jan 16, 2019

I am afraid this is the wrong fix. See our long discussion with Allan. Flag combinations should not be tested in Parser, we discussed this and decided on it. Please let's revert these commits and do it from the ground up at the same time as #5525.

Blaisorblade added a commit to dotty-staging/dotty that referenced this pull request Jan 18, 2019
Scalac sometimes *forgets* the final bytecode flag, and sometimes one cares, so
people even *recommend* always writing *final object* instead of object. That's
bad, since we started warning about it in scala#4973.

scala/bug#11094 (comment)
https://nrinaudo.github.io/scala-best-practices/adts/final_case_objects.html

Why care?
=========

If we forget the final flag in bytecode, Java code might then extend the class.
Performance might or might not be affected - some in scala/contributors
debated this for ~20 minutes (starting at
https://gitter.im/scala/contributors?at=5c423c449bfa375aab21f2af).
Blaisorblade added a commit to dotty-staging/dotty that referenced this pull request Jan 19, 2019
Scalac sometimes *forgets* the final bytecode flag, and sometimes one cares, so
people even *recommend* always writing *final object* instead of object. That's
bad, since we started warning about it in scala#4973.

scala/bug#11094 (comment)
https://nrinaudo.github.io/scala-best-practices/adts/final_case_objects.html

Why care?
=========

If we forget the final flag in bytecode, Java code might then extend the class.
Performance might or might not be affected - some in scala/contributors
debated this for ~20 minutes (starting at
https://gitter.im/scala/contributors?at=5c423c449bfa375aab21f2af).
Blaisorblade added a commit to dotty-staging/dotty that referenced this pull request Jan 19, 2019
Scalac sometimes *forgets* the final bytecode flag, and sometimes one cares, so
people even *recommend* always writing *final object* instead of object. That's
bad, since we started warning about it in scala#4973.

scala/bug#11094 (comment)
https://nrinaudo.github.io/scala-best-practices/adts/final_case_objects.html

Why care?
=========

If we forget the final flag in bytecode, Java code might then extend the class.
Performance might or might not be affected - some in scala/contributors
debated this for ~20 minutes (starting at
https://gitter.im/scala/contributors?at=5c423c449bfa375aab21f2af).
Blaisorblade added a commit that referenced this pull request Jan 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sealed final abstract case object Foo
6 participants