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

Unknown name for enum field with Scala.js #14488

Closed
plokhotnyuk opened this issue Feb 15, 2022 · 2 comments
Closed

Unknown name for enum field with Scala.js #14488

plokhotnyuk opened this issue Feb 15, 2022 · 2 comments

Comments

@plokhotnyuk
Copy link

Compiler version(s)

scalac 3.1.1 + scala.js 1.9.0

Minimized code

object LocationType extends Enumeration {
  type LocationType = Value

  val IP, GPS: LocationType = Value
}

LocationType.GPS.toString

Output

"<Unknown name for enum field #1 of class class scala.Enumeration$Val>"

Expectation

"GPS"
@plokhotnyuk plokhotnyuk added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 15, 2022
@sjrd
Copy link
Member

sjrd commented Feb 15, 2022

Ah, yes, Enumeration. We never ported the compiler support for scala.Enumeration to Scala 3. I guess I was hoping that they would have disappeared in favor of enums.

Work around: give explicit names to the fields:

object LocationType extends Enumeration {
  type LocationType = Value

  val IP: LocationType = Value("IP")
  val GPS: LocationType = Value("GPS")
}

@romanowski romanowski added area:scala.js and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 16, 2022
@sjrd
Copy link
Member

sjrd commented Feb 16, 2022

What would people think about releasing the support for Enumeration in a separate compiler for Scala 3? The use cases are rare, now that enum is there, and I hope we can eventually sunset it. Publishing it as a compiler plugin would reduce the maintenance burden, and compile-time performance for everyone that doesn't use Enumeration.

sjrd added a commit to dotty-staging/dotty that referenced this issue 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 added a commit to dotty-staging/dotty that referenced this issue 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 added a commit to dotty-staging/dotty that referenced this issue Jul 28, 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 added a commit to dotty-staging/dotty that referenced this issue Jul 28, 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 added a commit to dotty-staging/dotty that referenced this issue Jul 28, 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants