Skip to content

Commit

Permalink
Fix scala#19528: Actually remove Dynamic from interfaces of native JS…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
sjrd committed Jan 26, 2024
1 parent 453658b commit 59ebb85
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ class JSCodeGen()(using genCtx: Context) {
kind,
None,
superClass,
genClassInterfaces(sym, forJSClass = false),
genClassInterfaces(sym, forJSClass = true),
None,
jsNativeLoadSpec,
Nil,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.scalajs.testsuite.jsinterop

import scala.language.dynamics

import org.junit.Assert.*
import org.junit.Test

import scala.scalajs.js
import scala.scalajs.js.annotation.*

class CustomDynamicTestScala3 {
import CustomDynamicTestScala3.*

@Test
def testCustomDynamicClass_Issue19528(): Unit = {
val obj = new CustomDynamicClass()

assertEquals(false, obj.hasOwnProperty("foo"))
obj.foo = "bar"
assertEquals("bar", obj.foo)
assertEquals(true, obj.hasOwnProperty("foo"))
}

@Test
def testCustomDynamicTrait_Issue19528(): Unit = {
val obj = new js.Object().asInstanceOf[CustomDynamicTrait]

assertEquals(false, obj.hasOwnProperty("foo"))
obj.foo = "bar"
assertEquals("bar", obj.foo)
assertEquals(true, obj.hasOwnProperty("foo"))
}
}

object CustomDynamicTestScala3 {
@js.native
@JSGlobal("Object")
class CustomDynamicClass 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

@JSBracketCall
def applyDynamic(name: String)(args: js.Any*): js.Any = js.native
}

@js.native
trait CustomDynamicTrait 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

@JSBracketCall
def applyDynamic(name: String)(args: js.Any*): js.Any = js.native
}
}

0 comments on commit 59ebb85

Please sign in to comment.