Skip to content
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

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

Closed
oyvindberg opened this issue Oct 12, 2022 · 1 comment · Fixed by #16184
Closed

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

oyvindberg opened this issue Oct 12, 2022 · 1 comment · Fixed by #16184
Assignees
Milestone

Comments

@oyvindberg
Copy link

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?

@oyvindberg oyvindberg added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 12, 2022
@sjrd sjrd self-assigned this Oct 12, 2022
@sjrd
Copy link
Member

sjrd commented Oct 12, 2022

Thanks for the report. I'll have a look at it.

@Kordyjan Kordyjan added area:scala.js and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 12, 2022
sjrd added a commit to dotty-staging/dotty that referenced this issue Oct 14, 2022
sjrd added a commit to dotty-staging/dotty that referenced this issue Oct 14, 2022
…tive`.

Use `tpt.isInstanceOf[InferredTypeTree]` instead of relying on the
span being synthetic.
sjrd added a commit to dotty-staging/dotty that referenced this issue Oct 14, 2022
…tive`.

Use `tpt.isInstanceOf[InferredTypeTree]` instead of relying on the
span being synthetic.
szymon-rd pushed a commit to dotty-staging/dotty that referenced this issue Oct 28, 2022
…tive`.

Use `tpt.isInstanceOf[InferredTypeTree]` instead of relying on the
span being synthetic.
@Kordyjan Kordyjan added this to the 3.2.2 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants