Error when upgrading from ScalaJS 1.13.2 to 1.14.0 due to ambiguous implicit extension methods

Using clone() on an array:

import scala.scalajs.js

trait Point extends js.Object :
  val n: Int = js.native
  val s: js.Array[Double] = js.native

object Point :
  def clone(point: Point): Point = 
    val s = point.s.clone()
    val n = point.n
    js.Dynamic.literal(n = n, s = s).asInstanceOf[Point]

compiles without problems under Scala 3.4.0 / ScalaJS 1.13.2, but with ScalaJS 1.14.0 (and 1.15.0) we get the error:

[error] -- [E007] Type Mismatch Error: .../src/main/scala/clone.scala:10:20 
[error] 10 |      val s = point.s.clone()
[error]    |              ^^^^^^^
[error]    |Found:    (point.s : scalajs.js.Array[Double])
[error]    |Required: ?{ clone: ? }
[error]    |Note that implicit extension methods cannot be applied because they are ambiguous;
[error]    |both method undefOr2jsAny in object Any and method wrapArray in trait LowPrioAnyImplicits provide an extension method `clone` on (point.s : scalajs.js.Array[Double])

Unfortunately it is not possible to show this in Scastie, for you cannot set the ScalaJS version independently (which would be a good addition btw!).

Okay, first the problem can be simply cured by explicitly wrapping the array using js.WrappedArray, so it is not a big deal. And, second, it is mentioned in the release notes of ScalaJS 1.14.0 that

It is not entirely backward source compatible: it is not guaranteed that a codebase will compile as is when upgrading from 1.13.x

But on the other hand, the problem is not be entirely trivial and a am not sure if this kind of error was intended here, so i though it was worth mentioning. Comments?

Looks like it came from

Not sure whether we can do something about it.

1 Like