Skip to content

Commit 59ebb85

Browse files
committed
Fix #19528: Actually remove Dynamic from interfaces of native JS 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.
1 parent 453658b commit 59ebb85

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ class JSCodeGen()(using genCtx: Context) {
643643
kind,
644644
None,
645645
superClass,
646-
genClassInterfaces(sym, forJSClass = false),
646+
genClassInterfaces(sym, forJSClass = true),
647647
None,
648648
jsNativeLoadSpec,
649649
Nil,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package org.scalajs.testsuite.jsinterop
2+
3+
import scala.language.dynamics
4+
5+
import org.junit.Assert.*
6+
import org.junit.Test
7+
8+
import scala.scalajs.js
9+
import scala.scalajs.js.annotation.*
10+
11+
class CustomDynamicTestScala3 {
12+
import CustomDynamicTestScala3.*
13+
14+
@Test
15+
def testCustomDynamicClass_Issue19528(): Unit = {
16+
val obj = new CustomDynamicClass()
17+
18+
assertEquals(false, obj.hasOwnProperty("foo"))
19+
obj.foo = "bar"
20+
assertEquals("bar", obj.foo)
21+
assertEquals(true, obj.hasOwnProperty("foo"))
22+
}
23+
24+
@Test
25+
def testCustomDynamicTrait_Issue19528(): Unit = {
26+
val obj = new js.Object().asInstanceOf[CustomDynamicTrait]
27+
28+
assertEquals(false, obj.hasOwnProperty("foo"))
29+
obj.foo = "bar"
30+
assertEquals("bar", obj.foo)
31+
assertEquals(true, obj.hasOwnProperty("foo"))
32+
}
33+
}
34+
35+
object CustomDynamicTestScala3 {
36+
@js.native
37+
@JSGlobal("Object")
38+
class CustomDynamicClass extends js.Any with Dynamic {
39+
@JSBracketAccess
40+
def selectDynamic(name: String): js.Any = js.native
41+
@JSBracketAccess
42+
def updateDynamic(name: String)(value: js.Any): Unit = js.native
43+
44+
@JSBracketCall
45+
def applyDynamic(name: String)(args: js.Any*): js.Any = js.native
46+
}
47+
48+
@js.native
49+
trait CustomDynamicTrait extends js.Any with Dynamic {
50+
@JSBracketAccess
51+
def selectDynamic(name: String): js.Any = js.native
52+
@JSBracketAccess
53+
def updateDynamic(name: String)(value: js.Any): Unit = js.native
54+
55+
@JSBracketCall
56+
def applyDynamic(name: String)(args: js.Any*): js.Any = js.native
57+
}
58+
}

0 commit comments

Comments
 (0)