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

Fix #19528: Actually remove Dynamic from interfaces of native JS classes. #19536

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
Loading