Skip to content

Commit

Permalink
Fix #14289: Accept Ident refs to js.native in native member rhs. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
sjrd authored Oct 31, 2022
2 parents a8ee53c + 5111fee commit 9c68fd7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
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

0 comments on commit 9c68fd7

Please sign in to comment.