scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

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

Open sjrd opened this issue 3 years ago • 6 comments

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 avatar Jul 27 '22 17:07 sjrd

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!?

sjrd avatar Jul 27 '22 22:07 sjrd

@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

SethTisue avatar Jul 27 '22 22:07 SethTisue

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

dwijnand avatar Jul 28 '22 08:07 dwijnand

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?

sjrd avatar Jul 28 '22 08:07 sjrd

Yep, or at least to me it is.

dwijnand avatar Jul 28 '22 09:07 dwijnand

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 avatar Jul 28 '22 12:07 sjrd

Ping @dwijnand ?

sjrd avatar Aug 15 '22 12:08 sjrd

Yep, will do, sorry.

dwijnand avatar Aug 15 '22 13:08 dwijnand

Thanks 🙏

sjrd avatar Aug 15 '22 21:08 sjrd