Skip to content

Commit d848717

Browse files
committed
Fix #14289: Accept Ident refs to js.native in native member rhs.
1 parent c9c95d4 commit d848717

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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,20 @@ class RegressionTestScala3 {
9090

9191
assertEquals(5, Issue16173.bar1())
9292
}
93+
94+
@Test def nonSelectJSNativeRHSIssue14289(): Unit = {
95+
js.eval("""
96+
var RegressionTestScala3_Issue14289 = {
97+
"a": function() { return "foo"; },
98+
"b": function() { return 5; },
99+
"c": function() { return true; }
100+
};
101+
""")
102+
103+
assertEquals("foo", Issue14289.Container.a())
104+
assertEquals(5, Issue14289.Container.b())
105+
assertEquals(true, Issue14289.Container.c())
106+
}
93107
}
94108

95109
object RegressionTestScala3 {
@@ -174,6 +188,20 @@ object RegressionTestScala3 {
174188
@JSGlobal("RegressionTestScala3_Issue16173_bar")
175189
def bar1(): 5 = js.native
176190
}
191+
192+
object Issue14289 {
193+
import scala.scalajs.js.native
194+
import scala.scalajs.{js => renamedjs}
195+
import scala.scalajs.js.{native => renamednative}
196+
197+
@js.native
198+
@js.annotation.JSGlobal("RegressionTestScala3_Issue14289")
199+
object Container extends js.Object {
200+
def a(): String = native
201+
def b(): Int = renamedjs.native
202+
def c(): Boolean = renamednative
203+
}
204+
}
177205
}
178206

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

0 commit comments

Comments
 (0)