Skip to content

Commit e4e2399

Browse files
Fix snapshots of optional references. (#100)
Co-authored-by: Brandon Williams <[email protected]>
1 parent 0a4efc7 commit e4e2399

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

Sources/Sharing/Internal/Reference.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ extension _OptionalReference: MutableReference, Equatable where Base: MutableRef
674674
line: UInt,
675675
column: UInt
676676
) {
677-
guard base.snapshot != nil else { return }
677+
guard base.wrappedValue != nil else { return }
678678
base.takeSnapshot(value, fileID: fileID, filePath: filePath, line: line, column: column)
679679
}
680680

Tests/SharingTests/SharedChangeTrackerTests.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,22 @@ import Testing
103103
$count.withLock { $0 += 1 }
104104
}
105105
}
106+
107+
@Test func unwrappedShared() {
108+
let optionalShared = Shared<Int?>(value: 1)
109+
let unwrappedShared = Shared(optionalShared)!
110+
111+
withKnownIssue {
112+
do {
113+
let tracker = SharedChangeTracker()
114+
tracker.track {
115+
unwrappedShared.withLock { $0 += 1 }
116+
}
117+
}
118+
} matching: {
119+
$0.description == """
120+
Issue recorded: Tracked unasserted changes to 'Shared<Int?>(value: Optional(2))': Optional(1) → Optional(2)
121+
"""
122+
}
123+
}
106124
}

0 commit comments

Comments
 (0)