File tree 1 file changed +15
-2
lines changed
compiler/src/dotty/tools/dotc/transform
1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -187,8 +187,21 @@ class LazyVals extends MiniPhaseTransform with IdentityDenotTransformer {
187
187
def mkNonThreadSafeDef (target : Tree , flag : Tree , rhs : Tree )(implicit ctx : Context ) = {
188
188
val setFlag = flag.becomes(Literal (Constants .Constant (true )))
189
189
val flagSet = setFlag :: Nil
190
- val targetSet = if (isWildcardArg(rhs)) flagSet else target.becomes(rhs) :: flagSet
191
- val init = Block (targetSet, target.ensureApplied)
190
+
191
+ val init = evalOnce(rhs) { rhsRef =>
192
+ val targetSet = if (isWildcardArg(rhs)) flagSet else target.becomes(rhsRef) :: flagSet
193
+ val checkValidity =
194
+ tpd.If (
195
+ target.select(defn.Any_!= ).appliedTo(tpd.defaultValue(target.tpe.widenDealias)).select(defn.Boolean_&& ).
196
+ appliedTo(
197
+ target.select(defn.Any_!= ).appliedTo(rhsRef)
198
+ ),
199
+ tpd.Throw (tpd.New (ctx.requiredClass(" java.lang.IllegalStateException" ).namedType, Nil )),
200
+ tpd.EmptyTree
201
+ )
202
+ Block (checkValidity :: targetSet, rhsRef)
203
+ }
204
+
192
205
If (flag.ensureApplied, target.ensureApplied, init)
193
206
}
194
207
You can’t perform that action at this time.
0 commit comments