Skip to content

Compiler rejects native default constructor parameters when compiling Scala.js native classes #11592

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
russwyte opened this issue Mar 3, 2021 · 2 comments · Fixed by #11857
Assignees
Milestone

Comments

@russwyte
Copy link

russwyte commented Mar 3, 2021

3.0.0-RC1

Minimized code

@js.native
@JSGlobal
class SharedWorker(stringUrl: String, name: js.UndefOr[String] = js.native)
    extends webworkers.AbstractWorker {
  def port: MessagePort = js.native
}

Output

[info] compiling 53 Scala sources to /Users/rwhite/projects/scala-js-dom/target/scala-3.0.0-RC1/classes ...
[error] -- Error: /Users/rwhite/projects/scala-js-dom/src/main/scala/org/scalajs/dom/experimental/sharedworkers/SharedWorker.scala:33:65 
[error] 33 |class SharedWorker(stringUrl: String, name: js.UndefOr[String] = js.native)
[error]    |                                                                 ^^^^^^^^^
[error]    |       js.native may only be used as stub implementation in facade types
[error] one error [found](url)
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

Expectation

This should compile without error.

See [https://github.com/scala-js/scala-js-dom/pull/446]

@russwyte
Copy link
Author

russwyte commented Mar 3, 2021

For reference - implementing that class with an overloaded constructor works:

@js.native
@JSGlobal
class SharedWorker(stringUrl: String, name: js.UndefOr[String])
    extends webworkers.AbstractWorker {
  def this(stringUrl: String) = this(stringUrl, js.native)

  def port: MessagePort = js.native
}

@russwyte
Copy link
Author

russwyte commented Mar 4, 2021

Looks like the same issue as #10841

nicolasstucki added a commit that referenced this issue Mar 23, 2021
…n-js-native-class-ctor

Fix #11592: Scala.js: Handle default params of native JS classes.
@sjrd sjrd added this to the 3.0.0-RC2 milestone Mar 23, 2021
odersky pushed a commit to dotty-staging/dotty that referenced this issue Mar 24, 2021
…ams-in-js-native-class-ctor

Fix scala#11592: Scala.js: Handle default params of native JS classes.
@Kordyjan Kordyjan modified the milestones: 3.0.0-RC2, 3.0.0 Aug 2, 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