Skip to content

Commit 9c68fd7

Browse files
authored
Fix #14289: Accept Ident refs to js.native in native member rhs. (#16185)
2 parents a8ee53c + 5111fee commit 9c68fd7

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

compiler/src/dotty/tools/dotc/transform/sjs/PrepJSInterop.scala

+2
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,8 @@ class PrepJSInterop extends MacroTransform with IdentityDenotTransformer { thisP
974974
tree.rhs match {
975975
case sel: Select if sel.symbol == jsdefn.JSPackage_native =>
976976
// ok
977+
case rhs: Ident if rhs.symbol == jsdefn.JSPackage_native =>
978+
// ok
977979
case _ =>
978980
val pos = if (tree.rhs != EmptyTree) tree.rhs.srcPos else tree.srcPos
979981
report.error(s"$longKindStr may only call js.native.", pos)

tests/sjs-junit/test/org/scalajs/testsuite/compiler/RegressionTestScala3.scala

+28
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,20 @@ class RegressionTestScala3 {
131131
}
132132
}
133133
}
134+
135+
@Test def nonSelectJSNativeRHSIssue14289(): Unit = {
136+
js.eval("""
137+
var RegressionTestScala3_Issue14289 = {
138+
"a": function() { return "foo"; },
139+
"b": function() { return 5; },
140+
"c": function() { return true; }
141+
};
142+
""")
143+
144+
assertEquals("foo", Issue14289.Container.a())
145+
assertEquals(5, Issue14289.Container.b())
146+
assertEquals(true, Issue14289.Container.c())
147+
}
134148
}
135149

136150
object RegressionTestScala3 {
@@ -248,6 +262,20 @@ object RegressionTestScala3 {
248262
final val finalValField = "finalVal"
249263
}
250264
}
265+
266+
object Issue14289 {
267+
import scala.scalajs.js.native
268+
import scala.scalajs.{js => renamedjs}
269+
import scala.scalajs.js.{native => renamednative}
270+
271+
@js.native
272+
@js.annotation.JSGlobal("RegressionTestScala3_Issue14289")
273+
object Container extends js.Object {
274+
def a(): String = native
275+
def b(): Int = renamedjs.native
276+
def c(): Boolean = renamednative
277+
}
278+
}
251279
}
252280

253281
// This class needs to be at the top-level, not in an object, to reproduce the issue

0 commit comments

Comments
 (0)