File tree 3 files changed +35
-6
lines changed
compiler/src/dotty/tools/backend
tests/sjs-junit/test/org/scalajs/testsuite/compiler
3 files changed +35
-6
lines changed Original file line number Diff line number Diff line change @@ -139,6 +139,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
139
139
// See `tests/run/given-var.scala`
140
140
//
141
141
142
+ // !!! Part of this logic is duplicated in JSCodeGen.genCompilationUnit
142
143
claszSymbol.info.decls.foreach { f =>
143
144
if f.isField && ! f.name.is(LazyBitMapName ) then
144
145
f.setFlag(JavaStatic )
Original file line number Diff line number Diff line change @@ -198,6 +198,23 @@ class JSCodeGen()(using genCtx: Context) {
198
198
}
199
199
val allTypeDefs = collectTypeDefs(cunit.tpdTree)
200
200
201
+ /* #13221 Set JavaStatic on all the Module fields of static module classes.
202
+ * This is necessary for `desugarIdent` not to crash in some obscure
203
+ * scenarios.
204
+ *
205
+ * !!! Part of this logic is duplicated in BCodeSkelBuilder.genPlainClass
206
+ *
207
+ * However, here we only do this for Module fields, not all fields.
208
+ */
209
+ for (typeDef <- allTypeDefs) {
210
+ if (typeDef.symbol.is(ModuleClass )) {
211
+ typeDef.symbol.info.decls.foreach { f =>
212
+ if (f.isField && f.is(Module ))
213
+ f.setFlag(JavaStatic )
214
+ }
215
+ }
216
+ }
217
+
201
218
val (anonJSClassTypeDefs, otherTypeDefs) =
202
219
allTypeDefs.partition(td => td.symbol.isAnonymousClass && td.symbol.isJSType)
203
220
@@ -1957,12 +1974,7 @@ class JSCodeGen()(using genCtx: Context) {
1957
1974
val args = tree.args
1958
1975
val sym = tree.fun.symbol
1959
1976
1960
- val fun = tree.fun match {
1961
- case fun : Ident => desugarIdent(fun)
1962
- case fun => fun
1963
- }
1964
-
1965
- fun match {
1977
+ tree.fun match {
1966
1978
case _ if sym.isJSDefaultParam =>
1967
1979
js.Transient (UndefinedParam )
1968
1980
Original file line number Diff line number Diff line change @@ -39,6 +39,11 @@ class RegressionTestScala3 {
39
39
@ Test def defaultAccessorBridgesIssue12572 (): Unit = {
40
40
new MyPromiseIssue12572 [Int ](5 )
41
41
}
42
+
43
+ @ Test def desugarIdentCrashIssue13221 (): Unit = {
44
+ assertEquals(1 , X_Issue13221 .I .i)
45
+ assertEquals(1 , X_Issue13221 .blah)
46
+ }
42
47
}
43
48
44
49
object RegressionTestScala3 {
@@ -76,6 +81,17 @@ object RegressionTestScala3 {
76
81
???
77
82
}
78
83
}
84
+
85
+ object X_Issue13221 extends Y_Issue13221 {
86
+ object I {
87
+ def i = 1
88
+ }
89
+ }
90
+
91
+ abstract class Y_Issue13221 { self : X_Issue13221 .type =>
92
+ import I ._
93
+ def blah = i
94
+ }
79
95
}
80
96
81
97
// This class needs to be at the top-level, not in an object, to reproduce the issue
You can’t perform that action at this time.
0 commit comments