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