@@ -70,7 +70,6 @@ class JSCodeGen()(implicit ctx: Context) {
70
70
*/
71
71
private val mutableLocalVars = new ScopedVar [mutable.Set [Symbol ]]
72
72
private val mutatedLocalVars = new ScopedVar [mutable.Set [Symbol ]]
73
- private val unexpectedMutatedFields = new ScopedVar [mutable.Set [Symbol ]]
74
73
/*
75
74
private val paramAccessorLocals = new ScopedVar(Map.empty[Symbol, js.ParamDef])
76
75
*/
@@ -185,8 +184,7 @@ class JSCodeGen()(implicit ctx: Context) {
185
184
186
185
if (! isPrimitive && ! isRawJSImplClass) {
187
186
withScopedVars(
188
- currentClassSym := sym,
189
- unexpectedMutatedFields := mutable.Set .empty
187
+ currentClassSym := sym
190
188
) {
191
189
val tree = if (isRawJSType(sym)) {
192
190
/* assert(!isRawJSFunctionDef(sym),
@@ -559,8 +557,6 @@ class JSCodeGen()(implicit ctx: Context) {
559
557
} yield {
560
558
implicit val pos : Position = f.pos
561
559
562
- val mutable =
563
- suspectFieldMutable(f) || unexpectedMutatedFields.contains(f)
564
560
val name =
565
561
/* if (isExposed(f)) js.StringLiteral(jsNameOf(f))
566
562
else*/ encodeFieldSym(f)
@@ -602,7 +598,7 @@ class JSCodeGen()(implicit ctx: Context) {
602
598
}
603
599
}*/
604
600
605
- js.FieldDef (name, irTpe, mutable )
601
+ js.FieldDef (name, irTpe, f.is( Mutable ) )
606
602
}).toList
607
603
}
608
604
@@ -984,14 +980,13 @@ class JSCodeGen()(implicit ctx: Context) {
984
980
lhs match {
985
981
case lhs : Select =>
986
982
val qualifier = lhs.qualifier
987
- val ctorAssignment = (
983
+ def ctorAssignment = (
988
984
currentMethodSym.get.name == nme.CONSTRUCTOR &&
989
985
currentMethodSym.get.owner == qualifier.symbol &&
990
986
qualifier.isInstanceOf [This ]
991
987
)
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" )
995
990
}
996
991
997
992
val genQual = genExpr(qualifier)
@@ -1360,21 +1355,6 @@ class JSCodeGen()(implicit ctx: Context) {
1360
1355
private def genClassConstant (tpe : Type )(implicit pos : Position ): js.Tree =
1361
1356
js.ClassOf (toReferenceType(tpe))
1362
1357
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
-
1378
1358
private def isStaticModule (sym : Symbol ): Boolean =
1379
1359
sym.is(Module ) && sym.isStatic
1380
1360
0 commit comments