forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Scala.js unions extra methods via implicit conversion
The companion of `js.|` contains the following widely used implicit conversion to a value class: /** Provides an [[Option]]-like API to [[js.UndefOr]]. */ implicit def undefOr2ops[A](value: js.UndefOr[A]): js.UndefOrOps[A] = new js.UndefOrOps(value) (where `UndefOr[A]` dealiases to `A | Unit`). Since we re-interpret Scala.js unions as real unions, this companion is not in the implicit scope of `A | Unit`, we work around this by injecting a new `UnitOps` with the implicit conversion we want in the implicit scope of `Unit` (we could have directly injected the object `js.|`, but that contains other implicits we do not need). This finally lets us compile and run the sjsJUnitTests after the previous two commits.
- Loading branch information
Showing
4 changed files
with
20 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package scala.scalajs.js.internal | ||
|
||
import scala.scalajs.js | ||
|
||
/** Under -scalajs, this object is part of the implicit scope of `scala.Unit` */ | ||
object UnitOps: | ||
implicit def unitOrOps[A](x: A | Unit): js.UndefOrOps[A] = | ||
new js.UndefOrOps(x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters