Skip to content

Scala.js facades - native default arguments do not compile #10841

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
joschua-fink opened this issue Dec 17, 2020 · 3 comments
Closed

Scala.js facades - native default arguments do not compile #10841

joschua-fink opened this issue Dec 17, 2020 · 3 comments

Comments

@joschua-fink
Copy link

Minimized code

@js.native
@JSImport("three", "Vector3")
class Vector3(var x: Double = js.native,
              var y: Double = js.native,
              var z: Double = js.native) extends js.Object

// or simplified - behavior identical

@js.native
@JSImport("three", "Vector3")
class Vector3(var x: Double = js.native) extends js.Object

@js.native
@JSGlobal
class Vector3(var x: Double = js.native) extends js.Object

Output

compilation fails with

js.native may only be used as stub implementation in facade types

Expectation

Successful compilation, like Scala 2.13.4 does

Note

#9755 seems related. I'm using Scala 3.0.0-M3 with Scala.js 1.3.1

@sjrd
Copy link
Member

sjrd commented Dec 17, 2020

Thanks for the report.

As a workaround, you can probably declare overloaded constructors.

@sjrd sjrd self-assigned this Dec 17, 2020
@joschua-fink
Copy link
Author

You're welcome! Your suggested workaround compiles and produces plausible JavaScript. For anyone else having this issue, an example that appears to work:

@js.native
@JSGlobal
class Vector3(var x: Double, 
              var y: Double, 
              var z: Double) extends js.Object {

  def this() =
    this(js.native, js.native, js.native)

}

@sjrd
Copy link
Member

sjrd commented Sep 16, 2021

This was fixed in #11857. See also #11592.

@sjrd sjrd closed this as completed Sep 16, 2021
@sjrd sjrd added this to the 3.0.0-RC2 milestone Sep 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants