Skip to content

move implementation of ordinal in enums to posttyper #13952

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 1 commit into from
Nov 15, 2021

Conversation

bishabosha
Copy link
Member

@bishabosha bishabosha commented Nov 15, 2021

It was identified by @odersky that the cause of #13554 was forcing of the enum class in desugaring (in isJavaEnum method). isJavaEnum is only used to provide an implementation of ordinal for singleton cases, so the whole thing can be deferred until later.

also add a check that ordinal is not implemented by the user in the body of an enum class, or mixed in by a trait - this is necessary as scala.deriving.Mirror.Sum delegates to ordinal method on an enum.

Note- before this PR enum cases would declare ordinal methods without an override flag, so refchecks would issue an override-without-override-modifier error anyway if the user declared their own.

fixes #13554

also add a check that ordinal is not implemented
by the user, or mixed in by a trait - this is
necessary as scala.deriving.Mirror.Sum
delegates to ordinal method on an enum.
Note that before this commit, as enum cases would
previously declare ordinal methods at desugaring (without
an override flag), refchecks would issue an
override-without-override-modifier error anyway.

Co-authored-by: Jamie Thompson <bishbashboshjt@gmail.com>
Co-authored-by: Martin Odersky <odersky@gmail.com>
@bishabosha bishabosha removed the request for review from odersky November 15, 2021 09:01
@bishabosha bishabosha added the area:desugar Desugaring happens after parsing but before typing, see desugar.scala label Nov 15, 2021
@smarter smarter enabled auto-merge November 15, 2021 09:17
@bishabosha
Copy link
Member Author

getting this error in community build:

Error:  -- [E069] Syntax Error: /__w/dotty/dotty/library/src/scala/IArray.scala:13:7 ---
Error:  13 |object IArray:
Error:     |       ^
Error:     |object IArray cannot have the same name as object IArray in package scala -- cannot define object member with the same name as a object member in self reference _.
Error:     |(Note: this can be resolved by using another name)

@odersky
Copy link
Contributor

odersky commented Nov 15, 2021

@bishabosha Moving things from desugar to post typer completely changes the rules of the game, and is not easy either. What you got is a hard problem which means that things get completed too early. I maintain my earlier sentiment that the tradeoff between benefit and complexity/fragility of this feature is negative.

@smarter
Copy link
Member

smarter commented Nov 15, 2021

Error: |object IArray cannot have the same name as object IArray in package scala -- cannot define object member with the same name as a object member in self reference _.

I don't think this is related to this PR, this error already happens on master but is ignored, I think it happens when scaladoc unpickles some classfile.

@smarter smarter merged commit d8f9f02 into scala:master Nov 15, 2021
@smarter smarter deleted the fix-13554-alt branch November 15, 2021 11:59
@bishabosha
Copy link
Member Author

bishabosha commented Nov 15, 2021

@odersky we need to implement ordinal but only when we do not extend java.lang.Enum (as ordinal is final in that class) - so I propose the other solution is to keep adding ordinal in desugaring, and delete the ordinal method from Java enums before TASTy/zinc phases

@michelou
Copy link
Contributor

@smarter Better error messages in neg tests 👍

@Kordyjan Kordyjan added this to the 3.1.2 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:desugar Desugaring happens after parsing but before typing, see desugar.scala
Projects
None yet
Development

Successfully merging this pull request may close these issues.

inner class of enum companion not visible from the enum, unless companion is declared after
5 participants