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

Fix #14488: Scala.js: Add compiler support for scala.Enumeration. #15770

Merged
merged 1 commit into from
Aug 15, 2022

Conversation

sjrd
Copy link
Member

@sjrd sjrd commented Jul 27, 2022

This is the same logic that is used in the Scala.js compiler plugin for Scala 2.

We catch ValDefs of the forms

  val SomeField = Value
  val SomeOtherField = Value(5)

and rewrite them as

  val SomeField = Value("SomeField")
  val SomeOtherField = Value(5, "SomeOtherField")

For calls to Value and new Val without name that we cannot rewrite, we emit warnings.

@sjrd
Copy link
Member Author

sjrd commented Jul 27, 2022

Play JSON actually actively tests for the presence of the bug:
https://github.com/dotty-staging/play-json/blob/f65a409f4dc129f7adc72f048abbfbfc937a740f/play-json/js/src/test/scala-3/play/api/libs/json/EnumSpec.scala#L14-22
What am I supposed to do with that!?

@SethTisue
Copy link
Member

@sjrd perhaps you could

set `play-json`.js / Test / unmanagedSources / excludeFilter := HiddenFileFilter || "EnumSpec.scala"`

a little trick I've employed about a million times in the Scala 2 community build

@sjrd sjrd force-pushed the sjs-enumeration branch 2 times, most recently from e954ac3 to b419bca Compare July 28, 2022 08:21
@dwijnand
Copy link
Member

Change the test, I'd say, as it's tracking progression rather than spec or regression.

@sjrd
Copy link
Member Author

sjrd commented Jul 28, 2022

set `play-json`.js / Test / unmanagedSources / excludeFilter := HiddenFileFilter || "EnumSpec.scala"`

a little trick I've employed about a million times in the Scala 2 community build

Thanks, I'm trying that now.

Change the test, I'd say, as it's tracking progression rather than spec or regression.

I guess that's also a possibility. But that means it's a commit in our fork that is neither a cherry-pick from upstream, nor something I can PR back upstream anytime soon. Is that OK?

@dwijnand
Copy link
Member

Yep, or at least to me it is.

This is the same logic that is used in the Scala.js compiler plugin
for Scala 2.

We catch ValDefs of the forms

  val SomeField = Value
  val SomeOtherField = Value(5)

and rewrite them as

  val SomeField = Value("SomeField")
  val SomeOtherField = Value(5, "SomeOtherField")

For calls to `Value` and `new Val` without name that we cannot
rewrite, we emit warnings.
// scalajs: --skip --pending
// scalajs: --skip
Copy link
Member Author

Choose a reason for hiding this comment

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

This test uses extends Val without explicit name, which is not supported (and was never supported in Scala 2 either).

@sjrd
Copy link
Member Author

sjrd commented Jul 28, 2022

Yep, or at least to me it is.

Alright, that worked as well.

@dwijnand Would you mind reviewing this PR, perhaps? It's mostly a port of the Enum-related aspect of
https://github.com/scala-js/scala-js/blob/v1.10.1/compiler/src/main/scala/org/scalajs/nscplugin/PrepJSInterop.scala

@sjrd sjrd requested a review from dwijnand July 28, 2022 12:10
@sjrd
Copy link
Member Author

sjrd commented Aug 15, 2022

Ping @dwijnand ?

@dwijnand

This comment was marked as resolved.

@dwijnand dwijnand merged commit 9ff4fae into scala:main Aug 15, 2022
@dwijnand dwijnand deleted the sjs-enumeration branch August 15, 2022 20:07
@sjrd
Copy link
Member Author

sjrd commented Aug 15, 2022

Thanks 🙏

@Kordyjan Kordyjan added this to the 3.2.1 milestone Aug 1, 2023
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.

4 participants