Skip to content

Commit ce60b14

Browse files
committed
Handle weak reference that can be reset by the GC
owningState weak reference can be reset to null. This was observed when compiling scalatest.
1 parent 68b711c commit ce60b14

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4396,13 +4396,13 @@ object Types {
43964396
private var myInst: Type = NoType
43974397

43984398
private[core] def inst: Type = myInst
4399-
private[core] def inst_=(tp: Type): Unit = {
4399+
private[core] def inst_=(tp: Type): Unit =
44004400
myInst = tp
4401-
if (tp.exists && (owningState ne null)) {
4402-
owningState.get.ownedVars -= this
4403-
owningState = null // no longer needed; null out to avoid a memory leak
4404-
}
4405-
}
4401+
if tp.exists && owningState != null then
4402+
val owningState1 = owningState.get
4403+
if owningState1 != null then
4404+
owningState1.ownedVars -= this
4405+
owningState = null // no longer needed; null out to avoid a memory leak
44064406

44074407
/** The state owning the variable. This is at first `creatorState`, but it can
44084408
* be changed to an enclosing state on a commit.

0 commit comments

Comments
 (0)