8000 Merge pull request #4110 from sjrd/fix-gcc-crash · renowncoder/scala-js@fba4b7b · GitHub
[go: up one dir, main page]

Skip to content

Commit fba4b7b

Browse files
authored
Merge pull request scala-js#4110 from sjrd/fix-gcc-crash
Fix scala-js#4098: Avoid `let`/`const` when building the ASTs for GCC.
2 parents 5fd61f2 + 42dd238 commit fba4b7b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

linker/jvm/src/main/scala/org/scalajs/linker/backend/closure/ClosureAstTransformer.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,17 @@ private class ClosureAstTransformer(featureSet: FeatureSet,
8080
case Let(ident, mutable, optRhs) =>
8181
val node = transformName(ident)
8282
optRhs.foreach(rhs => node.addChildToFront(transformExpr(rhs)))
83-
new Node(if (mutable) Token.LET else Token.CONST, node)
83+
/* #4098 The following line should be
84+
* new Node(if (mutable) Token.LET else Token.CONST, node)
85+
* however, due to an unknown bug in how we build GCC trees or inside
86+
* GCC itself, using `let`s and `const`s can result in a crash deep
87+
* inside GCC in some obscure cases.
88+
* As a workaround, we always emit `var`s instead. This has no visible
89+
* semantic change because the Emitter never relies on the specific
90+
* semantics of `let`s and `const`s.
91+
* TODO We should properly fix this at the root (filed as #4109).
92+
*/
93+
new Node(Token.VAR, node)
8494
case Skip() =>
8595
new Node(Token.EMPTY)
8696
case Block(stats) =>

test-suite/shared/src/test/scala/org/scalajs/testsuite/compiler/RegressionTest.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,13 @@ class RegressionTest {
837837
assertEquals(6, `class`.foo(5))
838838
}
839839

840+
@Test def gcc_crash_with_let_const_issue_4098(): Unit = {
841+
val set = new java.util.HashSet[String]()
842+
set.remove("")
843+
set.remove("1") // only if remove is called twice
844+
assertEquals(0, set.size())
845+
}
846+
840847
}
841848

842849
object RegressionTest {

0 commit comments

Comments
 (0)
0