Skip to content

Commit a3d6992

Browse files
authored
[Observation] Reduce the scope of the observation shouldNotifyObservers to only apply to observation and not side effects of accessors like willSet or didSet (#79518)
1 parent f89472e commit a3d6992

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

lib/Macros/Sources/ObservationMacros/ObservableMacro.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,13 @@ public struct ObservationTrackedMacro: AccessorMacro {
361361
}
362362
"""
363363

364+
// the guard else case must include the assignment else
365+
// cases that would notify then drop the side effects of `didSet` etc
364366
let setAccessor: AccessorDeclSyntax =
365367
"""
366368
set {
367369
guard shouldNotifyObservers(_\(identifier), newValue) else {
370+
_\(identifier) = newValue
368371
return
369372
}
370373
withMutation(keyPath: \\.\(identifier)) {

0 commit comments

Comments
 (0)