diff --git a/compiler/src/dotty/tools/dotc/transform/sjs/PrepJSInterop.scala b/compiler/src/dotty/tools/dotc/transform/sjs/PrepJSInterop.scala index e75769147f80..48e6802e0f6c 100644 --- a/compiler/src/dotty/tools/dotc/transform/sjs/PrepJSInterop.scala +++ b/compiler/src/dotty/tools/dotc/transform/sjs/PrepJSInterop.scala @@ -974,6 +974,8 @@ class PrepJSInterop extends MacroTransform with IdentityDenotTransformer { thisP tree.rhs match { case sel: Select if sel.symbol == jsdefn.JSPackage_native => // ok + case rhs: Ident if rhs.symbol == jsdefn.JSPackage_native => + // ok case _ => val pos = if (tree.rhs != EmptyTree) tree.rhs.srcPos else tree.srcPos report.error(s"$longKindStr may only call js.native.", pos) diff --git a/tests/sjs-junit/test/org/scalajs/testsuite/compiler/RegressionTestScala3.scala b/tests/sjs-junit/test/org/scalajs/testsuite/compiler/RegressionTestScala3.scala index f3183bc4fef4..de260f3481ed 100644 --- a/tests/sjs-junit/test/org/scalajs/testsuite/compiler/RegressionTestScala3.scala +++ b/tests/sjs-junit/test/org/scalajs/testsuite/compiler/RegressionTestScala3.scala @@ -131,6 +131,20 @@ class RegressionTestScala3 { } } } + + @Test def nonSelectJSNativeRHSIssue14289(): Unit = { + js.eval(""" + var RegressionTestScala3_Issue14289 = { + "a": function() { return "foo"; }, + "b": function() { return 5; }, + "c": function() { return true; } + }; + """) + + assertEquals("foo", Issue14289.Container.a()) + assertEquals(5, Issue14289.Container.b()) + assertEquals(true, Issue14289.Container.c()) + } } object RegressionTestScala3 { @@ -248,6 +262,20 @@ object RegressionTestScala3 { final val finalValField = "finalVal" } } + + object Issue14289 { + import scala.scalajs.js.native + import scala.scalajs.{js => renamedjs} + import scala.scalajs.js.{native => renamednative} + + @js.native + @js.annotation.JSGlobal("RegressionTestScala3_Issue14289") + object Container extends js.Object { + def a(): String = native + def b(): Int = renamedjs.native + def c(): Boolean = renamednative + } + } } // This class needs to be at the top-level, not in an object, to reproduce the issue