Skip to content

scala.Enumeration requires reflection #38

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

Closed
jonas opened this issue Nov 24, 2013 · 2 comments
Closed

scala.Enumeration requires reflection #38

jonas opened this issue Nov 24, 2013 · 2 comments
Labels
invalid Contains a factual error which makes the report invalid. Closed.

Comments

@jonas
Copy link
Contributor

jonas commented Nov 24, 2013

This snippet that was posted on the mailing list has been integrated into the proposed test suite for Scala.js. The initial issue mentioned in the post was that Integer.reverseBytes was unimplemented.

object HelpLevel extends Enumeration {
  type HelpLevel = Value
  val None, Basic, Medium, Full = Value
}

val h = HelpLevel.None

It turns out that scala.Enumeration also requires reflection to work properly and thus must be handled by Scala.js in a special way, if we want to support it.

Here's the stack trace from the test:

TypeError: Cannot find function getDeclaredFields__ALjava_lang_reflect_Field in object class scala.EnumerationTest$$anonfun$1$$anonfun$apply$mcV$sp$1$HelpLevel$2. in /opt/scala-js/test/target/streams/test/externalDependencyClasspath/$global/package-js/extracted-jars/scalajs-library_2.10.jar--6a954585/scala/0002-Enumeration.js (line 125)
[info]  at /opt/scala-js/test/target/streams/test/externalDependencyClasspath/$global/package-js/extracted-jars/scalajs-library_2.10.jar--6a954585/scala/0002-Enumeration.js:125 (anonymous)
[info]  at /opt/scala-js/test/target/streams/test/externalDependencyClasspath/$global/package-js/extracted-jars/scalajs-library_2.10.jar--6a954585/scala/0003-Enumeration$$anonfun$scala$Enumeration$$nameOf$1.js:10 (anonymous)
[info]  at /opt/scala-js/test/target/streams/test/externalDependencyClasspath/$global/package-js/extracted-jars/scalajs-library_2.10.jar--6a954585/scala/0003-Enumeration$$anonfun$scala$Enumeration$$nameOf$1.js:14 (anonymous)
[info]  at /opt/scala-js/test/target/streams/test/externalDependencyClasspath/$global/package-js/extracted-jars/scalajs-library_2.10.jar--6a954585/scala/collection/0001-MapLike$class.js:20 (anonymous)
[info]  at /opt/scala-js/test/target/streams/test/externalDependencyClasspath/$global/package-js/extracted-jars/scalajs-library_2.10.jar--6a954585/scala/collection/0004-AbstractMap.js:20 (anonymous)
[info]  at /opt/scala-js/test/target/streams/test/externalDependencyClasspath/$global/package-js/extracted-jars/scalajs-library_2.10.jar--6a954585/scala/0002-Enumeration.js:138 (anonymous)
[info]  at /opt/scala-js/test/target/streams/test/externalDependencyClasspath/$global/package-js/extracted-jars/scalajs-library_2.10.jar--6a954585/scala/0003-Enumeration$Val.js:17 (anonymous)
[info]  at /opt/scala-js/test/target/streams/test/externalDependencyClasspath/$global/package-js/extracted-jars/scalajs-library_2.10.jar--6a954585/scalajs-corejslib.js:574 (anonymous)
[info]  at /opt/scala-js/test/target/scala-2.10/test-classes/scala/0004-EnumerationTest$$anonfun$1$$anonfun$apply$mcV$sp$1.js:22 (anonymous)
[info]  at /opt/scala-js/test/target/scala-2.10/test-classes/scala/0004-EnumerationTest$$anonfun$1$$anonfun$apply$mcV$sp$1.js:17 (anonymous)
[info]  at /opt/scala-js/test/target/scala-2.10/test-classes/scala/0004-EnumerationTest$$anonfun$1$$anonfun$apply$mcV$sp$1.js:25 (anonymous)
[info]  at /opt/scala-js/test/target/scala-2.10/test-classes/scala/scalajs/test/0002-ScalaJSTest.js:17 (anonymous)
[info]  at /opt/scala-js/test/target/scala-2.10/test-classes/jasmine.js:1087 (anonymous)
[info]  at /opt/scala-js/test/target/scala-2.10/test-classes/jasmine.js:2119 (anonymous)
[info]  at /opt/scala-js/test/target/scala-2.10/test-classes/jasmine.js:2072 (anonymous)
[info]  at /opt/scala-js/test/target/scala-2.10/test-classes/jasmine.js:2399 (anonymous)
[info]  at /opt/scala-js/test/target/scala-2.10/test-classes/jasmine.js:2119 (anonymous)
[info]  at /opt/scala-js/test/target/scala-2.10/test-classes/jasmine.js:2072 (anonymous)
[info]  at /opt/scala-js/test/target/scala-2.10/test-classes/jasmine.js:2544 (anonymous)
[info]  at /opt/scala-js/test/target/scala-2.10/test-classes/jasmine.js:2119 (anonymous)
[info]  at /opt/scala-js/test/target/scala-2.10/test-classes/jasmine.js:2072 (anonymous)
[info]  at /opt/scala-js/test/target/scala-2.10/test-classes/jasmine.js:2166 (anonymous)
[info]  at /opt/scala-js/test/target/scala-2.10/test-classes/jasmine.js:825 (anonymous)
[info]  at /opt/scala-js/test/target/scala-2.10/test-classes/main.js:27
@sjrd
Copy link
Member

sjrd commented Nov 24, 2013

I'll play the bad guy here and just answer: "won't fix".

Use explicit naming of alternatives of the enumeration instead:

  val None = Value("None")
  val Basic = Value("Basic")
  val Medium = Value("Medium")
  val Full = Value("Full")

unless we somehow turn the argument-less Value function into a macro that, much like settingKey in sbt, automagically constructs its argument from the name of the val it is assigned to.

@jonas
Copy link
Contributor Author

jonas commented Nov 24, 2013

Ok, I understand. I will update the test suite to use explicit naming.
Maybe this caveat should be documented somewhere on the website though.

@jonas jonas closed this as completed Nov 24, 2013
jonas added a commit to jonas/scala-js that referenced this issue Nov 24, 2013
@gzm0 gzm0 added the invalid Contains a factual error which makes the report invalid. Closed. label Sep 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid Contains a factual error which makes the report invalid. Closed.
Projects
None yet
Development

No branches or pull requests

3 participants