File tree 2 files changed +9
-6
lines changed
compiler/src/dotty/tools/backend/sjs
2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -793,6 +793,9 @@ class JSCodeGen()(using genCtx: Context) {
793
793
name.name
794
794
}.toSet
795
795
796
+ val staticNames = moduleClass.companionClass.info.allMembers
797
+ .collect { case d if d.name.isTermName && d.symbol.isScalaStatic => d.name }.toSet
798
+
796
799
val members = {
797
800
moduleClass.info.membersBasedOnFlags(required = Flags .Method ,
798
801
excluded = Flags .ExcludedForwarder ).map(_.symbol)
@@ -815,6 +818,7 @@ class JSCodeGen()(using genCtx: Context) {
815
818
|| hasAccessBoundary
816
819
|| isOfJLObject
817
820
|| m.hasAnnotation(jsdefn.JSNativeAnnot ) || isDefaultParamOfJSNativeDef // #4557
821
+ || staticNames(m.name)
818
822
}
819
823
820
824
val forwarders = for {
@@ -4769,7 +4773,7 @@ class JSCodeGen()(using genCtx: Context) {
4769
4773
}
4770
4774
4771
4775
private def isMethodStaticInIR (sym : Symbol ): Boolean =
4772
- sym.is(JavaStatic )
4776
+ sym.is(JavaStatic ) || sym.isScalaStatic
4773
4777
4774
4778
/** Generate a Class[_] value (e.g. coming from classOf[T]) */
4775
4779
private def genClassConstant (tpe : Type )(implicit pos : Position ): js.Tree =
Original file line number Diff line number Diff line change @@ -13,9 +13,8 @@ object Bar:
13
13
object Test :
14
14
def main (args : Array [String ]): Unit =
15
15
assert(Foo .foo == " foo" )
16
- assert(classOf [Foo ].getMethod(" foo" ).invoke(null ) == " foo" ) // static
17
- assert(Foo .getClass.getMethod(" foo" ).invoke(Foo ) == " foo" ) // instance, on module class
18
-
19
16
assert(Bar .bar == " bar" )
20
- assert(classOf [Bar ].getMethod(" bar" ).invoke(null ) == " bar" )
21
- assert(Bar .getClass.getMethod(" bar" ).invoke(Bar ) == " bar" )
17
+
18
+ import scala .reflect .Selectable .reflectiveSelectable
19
+ assert(Foo .asInstanceOf [{ def foo : String }].foo == " foo" )
20
+ assert(Bar .asInstanceOf [{ def bar : String }].bar == " bar" )
You can’t perform that action at this time.
0 commit comments