@@ -175,61 +175,61 @@ class Devalify extends Optimisation {
175
175
def isImmutableCaseAccessor = t.symbol.is(CaseAccessor ) && ! t.symbol.is(Mutable )
176
176
177
177
dropCasts(t) match {
178
- case Typed (exp, _) => readingOnlyVals(exp)
179
-
180
- case TypeApply (fun @ Select (rec, _), List (tp)) =>
181
- if ((fun.symbol eq defn.Any_asInstanceOf ) && rec.tpe.derivesFrom(tp.tpe.classSymbol))
182
- readingOnlyVals(rec)
183
- else false
184
-
185
- case Apply (Select (rec, _), Nil ) =>
186
- if (isGetterOfAImmutableField || isAccessingProductField || isImmutableCaseAccessor)
187
- readingOnlyVals(rec)
188
- else false
189
-
190
- case Select (rec, _) if t.symbol.is(Method ) =>
191
- if (isGetterOfAImmutableField)
192
- readingOnlyVals(rec) // Getter of an immutable field
193
- else if (isAccessingProductField) {
194
- def isImmutableField = {
195
- val fieldId = t.symbol.name.toString.drop(1 ).toInt - 1
196
- ! t.symbol.owner.caseAccessors(ctx)(fieldId).is(Mutable )
197
- }
198
- if (isImmutableField) readingOnlyVals(rec) // Accessing a field of a product
178
+ case Typed (exp, _) => readingOnlyVals(exp)
179
+
180
+ case TypeApply (fun @ Select (rec, _), List (tp)) =>
181
+ if ((fun.symbol eq defn.Any_asInstanceOf ) && rec.tpe.derivesFrom(tp.tpe.classSymbol))
182
+ readingOnlyVals(rec)
199
183
else false
200
- } else if (isImmutableCaseAccessor)
201
- readingOnlyVals(rec)
202
- else false
203
-
204
- case Select (qual, _) if ! t.symbol.is(Mutable ) =>
205
- if (t.symbol == defn.SystemModule ) {
206
- // System.in is static final fields that, for legacy reasons, must be
207
- // allowed to be changed by the methods System.setIn...
208
- // https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.5.4
209
- false
210
- } else
211
- readingOnlyVals(qual)
212
-
213
- case t : Ident if ! t.symbol.is(Mutable | Method ) && ! t.symbol.info.dealias.isInstanceOf [ExprType ] =>
214
- desugarIdent(t) match {
215
- case Some (t) => readingOnlyVals(t)
216
- case None => true
217
- }
218
184
219
- case t : This => true
220
- // null => false, or the following fails devalify:
221
- // trait I {
222
- // def foo: Any = null
223
- // }
224
- // object Main {
225
- // def main = {
226
- // val s: I = null
227
- // s.foo
228
- // }
229
- // }
230
- case Literal (Constant (null )) => false
231
- case t : Literal => true
232
- case _ => false
185
+ case Apply (Select (rec, _), Nil ) =>
186
+ if (isGetterOfAImmutableField || isAccessingProductField || isImmutableCaseAccessor)
187
+ readingOnlyVals(rec)
188
+ else false
189
+
190
+ case Select (rec, _) if t.symbol.is(Method ) =>
191
+ if (isGetterOfAImmutableField)
192
+ readingOnlyVals(rec) // Getter of an immutable field
193
+ else if (isAccessingProductField) {
194
+ def isImmutableField = {
195
+ val fieldId = t.symbol.name.toString.drop(1 ).toInt - 1
196
+ ! t.symbol.owner.caseAccessors(ctx)(fieldId).is(Mutable )
197
+ }
198
+ if (isImmutableField) readingOnlyVals(rec) // Accessing a field of a product
199
+ else false
200
+ } else if (isImmutableCaseAccessor)
201
+ readingOnlyVals(rec)
202
+ else false
203
+
204
+ case Select (qual, _) if ! t.symbol.is(Mutable ) =>
205
+ if (t.symbol == defn.SystemModule ) {
206
+ // System.in is static final fields that, for legacy reasons, must be
207
+ // allowed to be changed by the methods System.setIn...
208
+ // https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.5.4
209
+ false
210
+ } else
211
+ readingOnlyVals(qual)
212
+
213
+ case t : Ident if ! t.symbol.is(Mutable | Method ) && ! t.symbol.info.dealias.isInstanceOf [ExprType ] =>
214
+ desugarIdent(t) match {
215
+ case Some (t) => readingOnlyVals(t)
216
+ case None => true
217
+ }
218
+
219
+ case t : This => true
220
+ // null => false, or the following fails devalify:
221
+ // trait I {
222
+ // def foo: Any = null
223
+ // }
224
+ // object Main {
225
+ // def main = {
226
+ // val s: I = null
227
+ // s.foo
228
+ // }
229
+ // }
230
+ case Literal (Constant (null )) => false
231
+ case t : Literal => true
232
+ case _ => false
233
233
}
234
234
}
235
235
}
0 commit comments