Skip to content

Commit 9235e11

Browse files
authored
Merge pull request #4904 from armanbilge/topic/undefOr2jsAny
Move `undefOr2jsAny` implicit conversion to `js.Any` companion
2 parents 0d19d98 + 3fe44dd commit 9235e11

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

library/src/main/scala-new-collections/scala/scalajs/js/Any.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ object Any extends LowPrioAnyImplicits {
7979
@inline implicit def fromString(s: String): js.Any =
8080
s.asInstanceOf[js.Any]
8181

82+
/* This one is not very "in the spirit" of the union type, but it used to be
83+
* available for `js.UndefOr[A]`, so we keep it for backward source
84+
* compatibility. It is not really harmful, and has some perks in certain
85+
* interoperability scenarios.
86+
*/
87+
implicit def undefOr2jsAny[A](value: js.UndefOr[A])(
88+
implicit ev: A => js.Any): js.Any = {
89+
value.map(ev).asInstanceOf[js.Any]
90+
}
91+
8292
/* The following overload makes sure that the developer does not
8393
* inadvertently convert a Long to a Double to fit it in a js.Any.
8494
*/

library/src/main/scala-old-collections/scala/scalajs/js/Any.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ object Any extends js.LowPrioAnyImplicits {
7777
@inline implicit def fromString(s: String): js.Any =
7878
s.asInstanceOf[js.Any]
7979

80+
/* This one is not very "in the spirit" of the union type, but it used to be
81+
* available for `js.UndefOr[A]`, so we keep it for backward source
82+
* compatibility. It is not really harmful, and has some perks in certain
83+
* interoperability scenarios.
84+
*/
85+
implicit def undefOr2jsAny[A](value: js.UndefOr[A])(
86+
implicit ev: A => js.Any): js.Any = {
87+
value.map(ev).asInstanceOf[js.Any]
88+
}
89+
8090
/* The following overload makes sure that the developer does not
8191
* inadvertently convert a Long to a Double to fit it in a js.Any.
8292
*/

library/src/main/scala/scala/scalajs/js/Union.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ object | { // scalastyle:ignore
113113
* compatibility. It is not really harmful, and has some perks in certain
114114
* interoperability scenarios.
115115
*/
116-
implicit def undefOr2jsAny[A](value: js.UndefOr[A])(
116+
@deprecated("Relocated to js.Any.undefOr2jsAny", "1.14.0")
117+
def undefOr2jsAny[A](value: js.UndefOr[A])(
117118
implicit ev: A => js.Any): js.Any = {
118119
value.map(ev).asInstanceOf[js.Any]
119120
}

sbt-plugin/src/sbt-test/scala3/basic/Main.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ object Main {
2222

2323
// Testing the library resolved with %%% + withDottyCompat
2424
assert(Types.IntType.show() == "int")
25+
26+
// Testing the undefOr2jsAny implicit conversion
27+
val x: js.Any = js.defined("")
2528
}
2629
}

0 commit comments

Comments
 (0)