-
Notifications
You must be signed in to change notification settings - Fork 147
Document the boxed classes of primitive types. #491
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
Conversation
doc/semantics.md
Outdated
@@ -80,6 +80,20 @@ if strict-floats are enabled, or | |||
|
|||
otherwise. | |||
|
|||
### `getClass()` for values of primitive types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll have to update the introductory text that says "three exceptions".
Also, if you touch that, it'd be nice to link to a definition of what primitive types are (I assume it's JVM primitive types? or is it IR primitive types? or is it Scala primitive types (is there such a thing))?
doc/semantics.md
Outdated
@@ -80,6 +80,20 @@ if strict-floats are enabled, or | |||
|
|||
otherwise. | |||
|
|||
### `getClass()` for values of primitive types |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
having "primitive types" in the title seems redundant. The entire section is about primitive data types.
Moreover, for `()` (unit), the result will be `classOf[java.lang.Void]` instead of `classOf[scala.runtime.BoxedUnit]` like the JVM. | ||
`scala.runtime.BoxedUnit` is an implementation detail of Scala on the JVM, which Scala.js does not emulate. | ||
Instead, it uses the more sensible `java.lang.Void`, as `Void` is the boxed class corresponding to the `void` primitive type, which is `scala.Unit`. | ||
This also manifests itself in `Array[Unit]` which is effectively `Array[java.lang.Void]` at run-time, instead of `Array[scala.runtime.BoxedUnit]`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be helpful to add a sentence explaining that on the JVM, jl.Void
is uninstantiable and Scala.js has made the choice to violate this part of the JDK spec in favor of not needing sr.BoxedUnit
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added
This means that while
java.lang.Void
is not instantiable on the JVM, in Scala.js it has a singleton instance, namely()
.
Does that correspond to what you were asking?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep :) Thanks.
6cbfeab
to
7386fda
Compare
Updated. |
Moreover, for `()` (unit), the result will be `classOf[java.lang.Void]` instead of `classOf[scala.runtime.BoxedUnit]` like the JVM. | ||
`scala.runtime.BoxedUnit` is an implementation detail of Scala on the JVM, which Scala.js does not emulate. | ||
Instead, it uses the more sensible `java.lang.Void`, as `Void` is the boxed class corresponding to the `void` primitive type, which is `scala.Unit`. | ||
This also manifests itself in `Array[Unit]` which is effectively `Array[java.lang.Void]` at run-time, instead of `Array[scala.runtime.BoxedUnit]`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep :) Thanks.
No description provided.