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

Cannot use Dynamic with native Scala.js class / trait #19528

Closed
OndrejSpanel opened this issue Jan 24, 2024 · 1 comment · Fixed by #19536
Closed

Cannot use Dynamic with native Scala.js class / trait #19528

OndrejSpanel opened this issue Jan 24, 2024 · 1 comment · Fixed by #19536
Assignees
Milestone

Comments

@OndrejSpanel
Copy link
Member

Compiler version

3.3.1

Minimized code

import scala.language.dynamics
import scala.scalajs.js
import scala.scalajs.js.annotation._

object Main {
  @js.native
  @JSGlobal("MyDynamic")
  class MyDynamic extends js.Any with Dynamic {
    @JSBracketAccess
    def selectDynamic(name: String): js.Any = js.native
    @JSBracketAccess
    def updateDynamic(name: String)(value: js.Any): Unit = js.native
  }

  def main(args: Array[String]): Unit = {
    val d = new MyDynamic
    println(d.one)
    println(d.two)
  }
}

This is Scala.js - complete project available at https://github.com/OndrejSpanel/ScalaJsDynamic

Output

When using run in sbt, I get:

[error] scala.Dynamic (of kind Interface) is not a valid interface implemented by Main$MyDynamic (of kind NativeJSClass)
[error]   called from Main$MyDynamic
[error]   called from Main$.main([java.lang.String)void
[error]   called from static Main.main([java.lang.String)void
[error]   called from core module module initializers
[error] involving instantiated classes:
[error]   Main$

Expectation

The code should run. The same code works fine with Scala 2.13.12

Note

When posted as https://stackoverflow.com/q/77874549/16673, @sjrd advised to report it as a bug.

@OndrejSpanel OndrejSpanel added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 24, 2024
@sjrd sjrd self-assigned this Jan 24, 2024
sjrd added a commit to dotty-staging/dotty that referenced this issue Jan 26, 2024
… classes.

One boolean value was the wrong way around for native JS classes
and traits. That caused `scala.Dynamic` not to be removed from the
super-interfaces of native JS classes at the IR level, causing the
linking error.
@Gedochao Gedochao added area:scala.js and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 30, 2024
nicolasstucki added a commit that referenced this issue Jan 30, 2024
…ses. (#19536)

One boolean value was the wrong way around for native JS classes and
traits. That caused `scala.Dynamic` not to be removed from the
super-interfaces of native JS classes at the IR level, causing the
linking error.
@OndrejSpanel
Copy link
Member Author

I confirm this as fixed for my project with 3.4.1-RC1-bin-20240130-7a5cb6e-NIGHTLY

@Kordyjan Kordyjan added this to the 3.4.1 milestone Feb 14, 2024
OndrejSpanel pushed a commit to OndrejSpanel/scala3 that referenced this issue Mar 19, 2024
… classes.

One boolean value was the wrong way around for native JS classes
and traits. That caused `scala.Dynamic` not to be removed from the
super-interfaces of native JS classes at the IR level, causing the
linking error.

(cherry picked from commit 59ebb85)
WojciechMazur pushed a commit that referenced this issue Jun 28, 2024
…ses.

One boolean value was the wrong way around for native JS classes
and traits. That caused `scala.Dynamic` not to be removed from the
super-interfaces of native JS classes at the IR level, causing the
linking error.

[Cherry-picked 59ebb85]
WojciechMazur added a commit that referenced this issue Jul 1, 2024
…ve JS classes." to LTS (#20866)

Backports #19536 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
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.

4 participants