@@ -9,7 +9,7 @@ import StdNames.nme
99import util .Property
1010import Names .Name
1111import util .Spans .Span
12- import Flags .Mutable
12+ import Flags ._
1313import NullOpsDecorator ._
1414import collection .mutable
1515
@@ -151,11 +151,7 @@ object Nullables with
151151 || { val sym = ref.symbol
152152 sym.is(Mutable )
153153 && sym.owner.isTerm
154- && ( sym.owner == curCtx.owner
155- || ! curCtx.owner.is(Flags .Lazy ) // not at the rhs of lazy ValDef
156- && sym.owner.enclosingMethod == curCtx.owner.enclosingMethod // not in different methods
157- // TODO: need to check by-name paramter
158- )
154+ && ! ref.usedOutOfOrder // todo: remove
159155 && sym.span.exists
160156 && curCtx.compilationUnit != null // could be null under -Ytest-pickler
161157 && curCtx.compilationUnit.assignmentSpans.contains(sym.span.start)
@@ -206,6 +202,24 @@ object Nullables with
206202 then infos
207203 else info :: infos
208204
205+ given refOps : extension (ref : TermRef ) with
206+
207+ def usedOutOfOrder (given Context ) =
208+ val refSym = ref.symbol
209+ val refOwner = refSym.owner
210+
211+ def enclosedInClosure (s : Symbol ): Boolean =
212+ s != NoSymbol
213+ && s != refOwner
214+ && (s.isOneOf(Lazy | Method ) // not at the rhs of lazy ValDef or in a method (or lambda)
215+ || s.isClass // not in a class
216+ // TODO: need to check by-name paramter
217+ || enclosedInClosure(s.owner))
218+
219+ refSym.is(Mutable )
220+ && refSym.owner.isTerm
221+ && enclosedInClosure(curCtx.owner)
222+
209223 given treeOps : extension (tree : Tree ) with
210224
211225 /* The `tree` with added nullability attachment */
0 commit comments