Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Move undefOr2jsAny implicit conversion to js.Any companion #4904

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

Merged
merged 1 commit into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions library/src/main/scala-new-collections/scala/scalajs/js/Any.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ object Any extends LowPrioAnyImplicits {
@inline implicit def fromString(s: String): js.Any =
s.asInstanceOf[js.Any]

/* This one is not very "in the spirit" of the union type, but it used to be
* available for `js.UndefOr[A]`, so we keep it for backward source
* compatibility. It is not really harmful, and has some perks in certain
* interoperability scenarios.
*/
implicit def undefOr2jsAny[A](value: js.UndefOr[A])(
implicit ev: A => js.Any): js.Any = {
value.map(ev).asInstanceOf[js.Any]
}

/* The following overload makes sure that the developer does not
* inadvertently convert a Long to a Double to fit it in a js.Any.
*/
Expand Down
10 changes: 10 additions & 0 deletions library/src/main/scala-old-collections/scala/scalajs/js/Any.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ object Any extends js.LowPrioAnyImplicits {
@inline implicit def fromString(s: String): js.Any =
s.asInstanceOf[js.Any]

/* This one is not very "in the spirit" of the union type, but it used to be
* available for `js.UndefOr[A]`, so we keep it for backward source
* compatibility. It is not really harmful, and has some perks in certain
* interoperability scenarios.
*/
implicit def undefOr2jsAny[A](value: js.UndefOr[A])(
implicit ev: A => js.Any): js.Any = {
value.map(ev).asInstanceOf[js.Any]
}

/* The following overload makes sure that the developer does not
* inadvertently convert a Long to a Double to fit it in a js.Any.
*/
Expand Down
3 changes: 2 additions & 1 deletion library/src/main/scala/scala/scalajs/js/Union.scala
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ object | { // scalastyle:ignore
* compatibility. It is not really harmful, and has some perks in certain
* interoperability scenarios.
*/
implicit def undefOr2jsAny[A](value: js.UndefOr[A])(
@deprecated("Relocated to js.Any.undefOr2jsAny", "1.14.0")
def undefOr2jsAny[A](value: js.UndefOr[A])(
implicit ev: A => js.Any): js.Any = {
value.map(ev).asInstanceOf[js.Any]
}
Expand Down
3 changes: 3 additions & 0 deletions sbt-plugin/src/sbt-test/scala3/basic/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@ object Main {

// Testing the library resolved with %%% + withDottyCompat
assert(Types.IntType.show() == "int")

// Testing the undefOr2jsAny implicit conversion
val x: js.Any = js.defined("")
}
}