Skip to content

Conversation

sjrd
Copy link
Member

@sjrd sjrd commented Apr 2, 2020

No description provided.

doc/semantics.md Outdated
@@ -80,6 +80,20 @@ if strict-floats are enabled, or

otherwise.

### `getClass()` for values of primitive types
Copy link
Contributor

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
Copy link
Contributor

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]`.
Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep :) Thanks.

@sjrd sjrd force-pushed the document-primitive-getclass branch from 6cbfeab to 7386fda Compare April 2, 2020 11:48
@sjrd
Copy link
Member Author

sjrd commented Apr 2, 2020

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]`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Yep :) Thanks.

@gzm0 gzm0 merged commit 87e6a60 into scala-js:master Apr 2, 2020
@sjrd sjrd deleted the document-primitive-getclass branch April 2, 2020 12:48
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.

2 participants