@@ -680,9 +680,13 @@ class JSCodeGen()(implicit ctx: Context) {
680
680
methodName, jsParams, jstpe.NoType ,
681
681
Some (genStat(rhs)))(optimizerHints, None )
682
682
} else {
683
- val namespace =
683
+ val namespace = if (isMethodStaticInIR(sym)) {
684
+ if (sym.isPrivate) js.MemberNamespace .PrivateStatic
685
+ else js.MemberNamespace .PublicStatic
686
+ } else {
684
687
if (sym.isPrivate) js.MemberNamespace .Private
685
688
else js.MemberNamespace .Public
689
+ }
686
690
val resultIRType = toIRType(patchedResultType(sym))
687
691
genMethodDef(namespace, methodName,
688
692
params, resultIRType, rhs, optimizerHints)
@@ -874,16 +878,14 @@ class JSCodeGen()(implicit ctx: Context) {
874
878
genApplyDynamic(app)*/
875
879
876
880
case tree : This =>
877
- if (tree.symbol == currentClassSym.get) {
878
- genThis()
879
- } else {
880
- assert(tree.symbol.is(Module ),
881
- " Trying to access the this of another class: " +
882
- " tree.symbol = " + tree.symbol +
883
- " , class symbol = " + currentClassSym.get +
884
- " span:" + pos)
881
+ val currentClass = currentClassSym.get
882
+ val symIsModuleClass = tree.symbol.is(ModuleClass )
883
+ assert(tree.symbol == currentClass || symIsModuleClass,
884
+ s " Trying to access the this of another class: tree.symbol = ${tree.symbol}, class symbol = $currentClass" )
885
+ if (symIsModuleClass && tree.symbol != currentClass)
885
886
genLoadModule(tree.symbol)
886
- }
887
+ else
888
+ genThis()
887
889
888
890
case Select (qualifier, _) =>
889
891
val sym = tree.symbol
@@ -1841,7 +1843,9 @@ class JSCodeGen()(implicit ctx: Context) {
1841
1843
case _ => false
1842
1844
}
1843
1845
1844
- if (isJSType(sym.owner)) {
1846
+ if (isMethodStaticInIR(sym)) {
1847
+ genApplyStatic(sym, genActualArgs(sym, args))
1848
+ } else if (isJSType(sym.owner)) {
1845
1849
// if (!isScalaJSDefinedJSClass(sym.owner) || isExposed(sym))
1846
1850
genApplyJSMethodGeneric(tree, sym, genExprOrGlobalScope(receiver), genActualJSArgs(sym, args), isStat)
1847
1851
/* else
@@ -2112,9 +2116,12 @@ class JSCodeGen()(implicit ctx: Context) {
2112
2116
case t @ Ident (_) => (t, Nil )
2113
2117
}
2114
2118
val sym = fun.symbol
2119
+ val isStaticCall = isMethodStaticInIR(sym)
2115
2120
2116
2121
val qualifier = qualifierOf(fun)
2117
- val allCaptureValues = qualifier :: env
2122
+ val allCaptureValues =
2123
+ if (isStaticCall) env
2124
+ else qualifier :: env
2118
2125
2119
2126
val formalAndActualCaptures = allCaptureValues.map { value =>
2120
2127
implicit val pos = value.span
@@ -2143,9 +2150,13 @@ class JSCodeGen()(implicit ctx: Context) {
2143
2150
val (formalParams, actualParams) = formalAndActualParams.unzip
2144
2151
2145
2152
val genBody = {
2146
- val thisCaptureRef :: argCaptureRefs = formalCaptures.map(_.ref)
2147
- val call = genApplyMethodMaybeStatically(thisCaptureRef, sym,
2148
- argCaptureRefs ::: actualParams)
2153
+ val call = if (isStaticCall) {
2154
+ genApplyStatic(sym, formalCaptures.map(_.ref))
2155
+ } else {
2156
+ val thisCaptureRef :: argCaptureRefs = formalCaptures.map(_.ref)
2157
+ genApplyMethodMaybeStatically(thisCaptureRef, sym,
2158
+ argCaptureRefs ::: actualParams)
2159
+ }
2149
2160
box(call, sym.info.finalResultType)
2150
2161
}
2151
2162
@@ -2294,8 +2305,8 @@ class JSCodeGen()(implicit ctx: Context) {
2294
2305
/** Gen a call to a static method. */
2295
2306
private def genApplyStatic (method : Symbol , arguments : List [js.Tree ])(
2296
2307
implicit pos : Position ): js.Tree = {
2297
- js.ApplyStatic (js.ApplyFlags .empty, encodeClassRef (method.owner ),
2298
- encodeMethodSym(method), arguments)(
2308
+ js.ApplyStatic (js.ApplyFlags .empty.withPrivate (method.isPrivate ),
2309
+ encodeClassRef(method.owner), encodeMethodSym(method), arguments)(
2299
2310
toIRType(patchedResultType(method)))
2300
2311
}
2301
2312
@@ -2887,6 +2898,9 @@ class JSCodeGen()(implicit ctx: Context) {
2887
2898
}
2888
2899
}
2889
2900
2901
+ private def isMethodStaticInIR (sym : Symbol ): Boolean =
2902
+ sym.is(JavaStatic , butNot = JavaDefined )
2903
+
2890
2904
/** Generate a Class[_] value (e.g. coming from classOf[T]) */
2891
2905
private def genClassConstant (tpe : Type )(implicit pos : Position ): js.Tree =
2892
2906
js.ClassOf (toTypeRef(tpe))
0 commit comments