Skip to content

Commit 0d0531a

Browse files
committed
Remove the unexpectedMutatedFields logic.
Now that vals mixed in from Scala2 traits are properly marked as Mutable, there is no more occurrences of immutable fields being assigned to outside of constructors.
1 parent 0dcbcfb commit 0d0531a

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

src/dotty/tools/backend/sjs/JSCodeGen.scala

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ class JSCodeGen()(implicit ctx: Context) {
7070
*/
7171
private val mutableLocalVars = new ScopedVar[mutable.Set[Symbol]]
7272
private val mutatedLocalVars = new ScopedVar[mutable.Set[Symbol]]
73-
private val unexpectedMutatedFields = new ScopedVar[mutable.Set[Symbol]]
7473
/*
7574
private val paramAccessorLocals = new ScopedVar(Map.empty[Symbol, js.ParamDef])
7675
*/
@@ -185,8 +184,7 @@ class JSCodeGen()(implicit ctx: Context) {
185184

186185
if (!isPrimitive && !isRawJSImplClass) {
187186
withScopedVars(
188-
currentClassSym := sym,
189-
unexpectedMutatedFields := mutable.Set.empty
187+
currentClassSym := sym
190188
) {
191189
val tree = if (isRawJSType(sym)) {
192190
/*assert(!isRawJSFunctionDef(sym),
@@ -559,8 +557,6 @@ class JSCodeGen()(implicit ctx: Context) {
559557
} yield {
560558
implicit val pos: Position = f.pos
561559

562-
val mutable =
563-
suspectFieldMutable(f) || unexpectedMutatedFields.contains(f)
564560
val name =
565561
/*if (isExposed(f)) js.StringLiteral(jsNameOf(f))
566562
else*/ encodeFieldSym(f)
@@ -602,7 +598,7 @@ class JSCodeGen()(implicit ctx: Context) {
602598
}
603599
}*/
604600

605-
js.FieldDef(name, irTpe, mutable)
601+
js.FieldDef(name, irTpe, f.is(Mutable))
606602
}).toList
607603
}
608604

@@ -984,14 +980,13 @@ class JSCodeGen()(implicit ctx: Context) {
984980
lhs match {
985981
case lhs: Select =>
986982
val qualifier = lhs.qualifier
987-
val ctorAssignment = (
983+
def ctorAssignment = (
988984
currentMethodSym.get.name == nme.CONSTRUCTOR &&
989985
currentMethodSym.get.owner == qualifier.symbol &&
990986
qualifier.isInstanceOf[This]
991987
)
992-
if (!ctorAssignment && !suspectFieldMutable(sym)) {
993-
ctx.debuglog(s"Assigning to immutable field ${sym.fullName} at $pos")
994-
unexpectedMutatedFields += sym
988+
if (!sym.is(Mutable) && !ctorAssignment) {
989+
throw new FatalError(s"Assigning to immutable field ${sym.fullName} at $pos")
995990
}
996991

997992
val genQual = genExpr(qualifier)
@@ -1360,21 +1355,6 @@ class JSCodeGen()(implicit ctx: Context) {
13601355
private def genClassConstant(tpe: Type)(implicit pos: Position): js.Tree =
13611356
js.ClassOf(toReferenceType(tpe))
13621357

1363-
/** Tests whether a field is suspected to be mutable in the IR's terms.
1364-
*
1365-
* A field is mutable in the IR, if it is assigned to elsewhere than in
1366-
* the constructor of its class.
1367-
*
1368-
* Mixed-in fields from Scala2 traits are always mutable, since they will
1369-
* be assigned to in a trait initializer (rather than a constructor).
1370-
* TODO Only apply this to Scala2 traits.
1371-
*
1372-
* TODO Needed? Further, in 2.10.x fields used to implement lazy vals are
1373-
* not marked mutable (but assigned to in the accessor).
1374-
*/
1375-
private def suspectFieldMutable(sym: Symbol) =
1376-
sym.is(Mutable) || sym.is(MixedIn) // || sym.is(Lazy)
1377-
13781358
private def isStaticModule(sym: Symbol): Boolean =
13791359
sym.is(Module) && sym.isStatic
13801360

0 commit comments

Comments
 (0)