Skip to content

dotty scalajs toplevel object import compilation failure #9755

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

Closed
aappddeevv opened this issue Sep 8, 2020 · 5 comments · Fixed by #9951
Closed

dotty scalajs toplevel object import compilation failure #9755

aappddeevv opened this issue Sep 8, 2020 · 5 comments · Fixed by #9951

Comments

@aappddeevv
Copy link

Reference: scala-js/scala-js#4183

Minimized code

package test1
//...imports
@js.native
@JSImport("node-fetch", JSImport.Default)
def fetch2(url: String, arg: js.Dynamic): js.Promise[Response] = js.native

Output

fails with

[error] 19 |def fetch2(url: String, arg: js.Dynamic): js.Promise[Response] = js.native
[error]    |                                                                 ^^^^^^^^^
[error]    |       js.native may only be used as stub implementation in facade types
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

Expectation

It should compile.

Note

However, the more traditional way of writing it works:

@js.native
@JSImport("node-fetch", JSImport.Default)
object fetch extends js.Any:
    def apply(url: String, arg: js.Dynamic): js.Promise[Response] = js.native
@sjrd
Copy link
Member

sjrd commented Sep 8, 2020

The title mentions a package object, but the snippet seems to use a top-level definition instead. Which one is it?

@sjrd sjrd self-assigned this Sep 8, 2020
@aappddeevv
Copy link
Author

It's toplevel. I'm still getting used to the vocab change.

@aappddeevv aappddeevv changed the title dotty scalajs package object import compilation failure dotty scalajs toplevel object import compilation failure Sep 8, 2020
@aappddeevv
Copy link
Author

There may be other toplevel issues. I'm seeing a problem where a @JSImport at the top level is not emitting a require/import js clause in the output as well.

I'll open that separately once I confirm that its a toplevel issue, if it is.

@aappddeevv
Copy link
Author

It looks like #9725 did not address this issue. You did not claim that it did of course since this is an older PR, but would you have expected this to be fixed by #9725?

@sjrd
Copy link
Member

sjrd commented Sep 18, 2020

Not necessarily. I had not tested with top-level vals and defs yet.

@sjrd sjrd closed this as completed in #9951 Oct 6, 2020
sjrd added a commit that referenced this issue Oct 6, 2020
Fix #9755: Add tests for Scala.js top-level native members
@sjrd sjrd assigned adpi2 and unassigned sjrd Oct 6, 2020
@sjrd sjrd added this to the 3.0.0-M1 milestone Oct 6, 2020
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