Skip to content

Commit 64f6020

Browse files
committed
Fix #14289: Accept Ident refs to js.native in native member rhs.
1 parent 62684d0 commit 64f6020

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
@@ -78,6 +78,20 @@ class RegressionTestScala3 {
7878
val f3 = { () => i += 1 }
7979
assertSame(f3, Thunk.asFunction0(f3()))
8080
}
81+
82+
@Test def nonSelectJSNativeRHSIssue14289(): Unit = {
83+
js.eval("""
84+
var RegressionTestScala3_Issue14289 = {
85+
"a": function() { return "foo"; },
86+
"b": function() { return 5; },
87+
"c": function() { return true; }
88+
};
89+
""")
90+
91+
assertEquals("foo", Issue14289.Container.a())
92+
assertEquals(5, Issue14289.Container.b())
93+
assertEquals(true, Issue14289.Container.c())
94+
}
8195
}
8296

8397
object RegressionTestScala3 {
@@ -148,6 +162,20 @@ object RegressionTestScala3 {
148162
val entries = js.Object.entries(obj)
149163
val js.Tuple2(k, v) = entries(0): @unchecked
150164
}
165+
166+
object Issue14289 {
167+
import scala.scalajs.js.native
168+
import scala.scalajs.{js => renamedjs}
169+
import scala.scalajs.js.{native => renamednative}
170+
171+
@js.native
172+
@js.annotation.JSGlobal("RegressionTestScala3_Issue14289")
173+
object Container extends js.Object {
174+
def a(): String = native
175+
def b(): Int = renamedjs.native
176+
def c(): Boolean = renamednative
177+
}
178+
}
151179
}
152180

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

0 commit comments

Comments
 (0)