Skip to content

remove scala.runtime.EnumValues #9628

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 4 commits into from
Aug 28, 2020

Conversation

bishabosha
Copy link
Member

@bishabosha bishabosha commented Aug 24, 2020

generates an array of the constants immediately after the last enum case

@bishabosha bishabosha requested review from smarter, sjrd and odersky August 24, 2020 15:07
@bishabosha bishabosha force-pushed the topic/enum-lookup-methods branch 4 times, most recently from 22f8dd4 to f9207e2 Compare August 24, 2020 15:43
@bishabosha bishabosha force-pushed the topic/enum-lookup-methods branch 2 times, most recently from b201183 to 9790f98 Compare August 25, 2020 12:01
@bishabosha bishabosha force-pushed the topic/enum-lookup-methods branch from 9790f98 to bb0cc13 Compare August 27, 2020 08:18
@bishabosha
Copy link
Member Author

bishabosha commented Aug 27, 2020

so it seems that TASTy does not distinguish between SeqLiteral and JavaSeqLiteral so that is unusable
@smarter @sjrd

@sjrd
Copy link
Member

sjrd commented Aug 27, 2020

That is disappointing. Is it intended? If yes, I'm afraid you'll have to revert to the the code that generates the Apply.apply(...) call. But in that case, I wonder how TASTy would persist a call to a Java varargs method ... Maybe there's a deeper problem here.

@bishabosha bishabosha force-pushed the topic/enum-lookup-methods branch from bb0cc13 to 7303278 Compare August 27, 2020 09:18
@bishabosha
Copy link
Member Author

bishabosha commented Aug 27, 2020

@sjrd looks like phase elimRepeated uses expected type of a java varargs method to transform SeqLiteral to JavaSeqLiteral

@bishabosha bishabosha force-pushed the topic/enum-lookup-methods branch 4 times, most recently from 4dbc6e8 to 11a582c Compare August 27, 2020 10:24
@smarter
Copy link
Member

smarter commented Aug 27, 2020

I think it would make sense to support pickling/unpickling JavaSeqLiteral.

@bishabosha bishabosha force-pushed the topic/enum-lookup-methods branch from 11a582c to c36af53 Compare August 27, 2020 12:33
@bishabosha bishabosha force-pushed the topic/enum-lookup-methods branch from c36af53 to 5dfcd6d Compare August 27, 2020 12:36
@bishabosha
Copy link
Member Author

bishabosha commented Aug 27, 2020

@smarter @sjrd not sure what to do here for this example:

class Outer {
  val thunk = { () =>
    enum E { case A }
    E.A
  }
}

@main def Test =
  assert(Outer().thunk().toString == "A")

if I create the $values array with Ident("A"), then this code works, but causes the init checker to complain about access to A, but if I use Select(companionRef, "A") then the init checker does not complain, but then accessing the companion object through selection causes a runtime stack overflow in constructor of E

@sjrd
Copy link
Member

sjrd commented Aug 27, 2020

I guess you could make it a lazy val to break the cycle in the constructor of E?

@bishabosha
Copy link
Member Author

I'll make it lazy when the owner of the enum is not static

@bishabosha
Copy link
Member Author

bishabosha commented Aug 28, 2020

this works and can be merged, but should be updated in the future based on how #9664 is resolved

@bishabosha bishabosha requested a review from sjrd August 28, 2020 09:43
@bishabosha bishabosha merged commit 733b57c into scala:master Aug 28, 2020
@bishabosha bishabosha deleted the topic/enum-lookup-methods branch August 28, 2020 10:00
bishabosha added a commit to dotty-staging/dotty that referenced this pull request Aug 28, 2020
This patches a regression introduced in scala#9628,
instead of checking if the owner of an enum is static before making
values lazy, the enum itself is checked to be static.
bishabosha added a commit to dotty-staging/dotty that referenced this pull request Aug 28, 2020
This patches a regression introduced in scala#9628 where
defining an enum local to a method can cause an infinite loop
at initialisation of its companion.

Instead, we select enum values from "this" and not the companion,
which avoids forcing initialisation of the companion. We then
ascribe the values array with unchecked annotation to avoid
complaints from the init checker.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants