Skip to content

Scala.js: Literal types not accepted for JS native methods/values #16173

Closed
@oyvindberg

Description

@oyvindberg

Compiler version

3.2.0

Minimized code

import scala.scalajs.js

@js.annotation.JSGlobal("a")
@js.native
def string: String = js.native // ok

@js.annotation.JSGlobal("a")
@js.native
def a: "a" = js.native // error: The type of a must be explicitly specified because it is JS native.
// same with `var`/`val`

Output

The type of a must be explicitly specified because it is JS native.

Expectation

The type is specified, so it should be accepted.

I see this in the implementation of the check:

      if (tree.tpt.span.isSynthetic)
        report.error(i"The type of ${tree.name} must be explicitly specified because it is JS native.", tree)

Perhaps it is the case that the literal type tree is considered synthetic somehow?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions