Open rssh opened 2 weeks ago
Repro with Scala CLI:
//> using platform js
//> using options -Ycheck:all
package x
import scala.util.*
import scala.scalajs.js.{JavaScriptException, Thenable}
import scalajs.*
case class JSPromiseWrapper[A](val jsPromise: js.Promise[Either[A,JSPromiseWrapper[A]]]) {
def flatMapTry[B](f: Try[A] => JSPromiseWrapper[B]): JSPromiseWrapper[B] = {
JSPromiseWrapper(
jsPromise.`then`[Either[B,JSPromiseWrapper[B]]](
onFulfilled = {
case Left(a) =>
evalOp(f(Success(a)))
case Right(wa) =>
Right(wa.flatMapTry(f))
},
onRejected = { (e: Any) =>
e match
case ex: Throwable =>
evalOp(f(Failure(ex)))
case other =>
evalOp(f(Failure(JavaScriptException(other))))
}
)
)
}
}
def evalOp[T](op: => JSPromiseWrapper[T]): Either[T, JSPromiseWrapper[T]] = {
???
}
Compiler version
3.4.2 3.5.0-RC2
Minimized code
(note, that scalajs should be enabled and -Ycheck:all is essential)
Next build.sbt:
Output (click arrow to expand)