Skip to content

js.await(promise) does not compile in Scala 3.8.x when the type of promise is js.Promise[Unit] #25342

Description

@DanielMoss

Compiler version

3.8.1, 3.8.2

Minimized code

Scastie

import scala.scalajs.js

// Does not compile in Scala 3.8.x, but does compile in Scala 2.13.8
js.async(
  js.await(js.Promise.resolve[Unit](()))
)

// Compiles in both Scala 3.8.x and 2.13.8
js.async(
  js.await(js.Promise.resolve[Int](5))
)

Output

        js.await(js.Promise.resolve[Unit](()))
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Illegal use of js.await().
It can only be used inside a js.async {...} block, without any lambda,
by-name argument or nested method in-between.
If you compile for WebAssembly, you can allow arbitrary js.await()
calls by adding the following import:
import scala.scalajs.js.wasm.JSPI.allowOrphanJSAwait

Expectation

Consistent behaviour between Scala 2 and Scala 3 when using js.async/js.await.

Potentially related PRs:

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions