File tree Expand file tree Collapse file tree 3 files changed +35
-6
lines changed
compiler/src/dotty/tools/backend
tests/sjs-junit/test/org/scalajs/testsuite/compiler Expand file tree Collapse file tree 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 {
139139 // See `tests/run/given-var.scala`
140140 //
141141
142+ // !!! Part of this logic is duplicated in JSCodeGen.genCompilationUnit
142143 claszSymbol.info.decls.foreach { f =>
143144 if f.isField && ! f.name.is(LazyBitMapName ) then
144145 f.setFlag(JavaStatic )
Original file line number Diff line number Diff line change @@ -198,6 +198,23 @@ class JSCodeGen()(using genCtx: Context) {
198198 }
199199 val allTypeDefs = collectTypeDefs(cunit.tpdTree)
200200
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+
201218 val (anonJSClassTypeDefs, otherTypeDefs) =
202219 allTypeDefs.partition(td => td.symbol.isAnonymousClass && td.symbol.isJSType)
203220
@@ -1957,12 +1974,7 @@ class JSCodeGen()(using genCtx: Context) {
19571974 val args = tree.args
19581975 val sym = tree.fun.symbol
19591976
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 {
19661978 case _ if sym.isJSDefaultParam =>
19671979 js.Transient (UndefinedParam )
19681980
Original file line number Diff line number Diff line change @@ -39,6 +39,11 @@ class RegressionTestScala3 {
3939 @ Test def defaultAccessorBridgesIssue12572 (): Unit = {
4040 new MyPromiseIssue12572 [Int ](5 )
4141 }
42+
43+ @ Test def desugarIdentCrashIssue13221 (): Unit = {
44+ assertEquals(1 , X_Issue13221 .I .i)
45+ assertEquals(1 , X_Issue13221 .blah)
46+ }
4247}
4348
4449object RegressionTestScala3 {
@@ -76,6 +81,17 @@ object RegressionTestScala3 {
7681 ???
7782 }
7883 }
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+ }
7995}
8096
8197// 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