Skip to content

Fix #14289: Accept Ident refs to js.native in native member rhs. #16185

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

Merged
merged 1 commit into from
Oct 31, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down