Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-13882] oldValue in didSet is reported as nil by debugger #4326

Closed
idrougge opened this issue Nov 20, 2020 · 3 comments
Closed

[SR-13882] oldValue in didSet is reported as nil by debugger #4326

idrougge opened this issue Nov 20, 2020 · 3 comments
Assignees
Labels
bug Something isn't working LLDB for Swift

Comments

@idrougge
Copy link

Previous ID SR-13882
Radar rdar://problem/71677710
Original Reporter @idrougge
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 12, Xcode 12.1

Additional Detail from JIRA
Votes 0
Component/s LLDB for Swift
Labels Bug
Assignee @adrian-prantl
Priority Medium

md5: 665d70b7dd908130d8aa01a7703f067f

Issue Description:

`oldValue` in a `didSet` property observer is represented as `nil` when setting a breakpoint inside the `didSet` observer, when printing the local variables using `(lldb) frame variable` or using Xcode's "Variables" debugger view. `po oldValue` will however print out a non-nil value.

This behaviour only seems to occur when the property observed is a struct (not a class) containing an optional value of a certain type, such as `Date`.

A code example follows:

```
import Foundation

struct Slot: Equatable {
    let time: Date?
}

class Handler {
    var slot: Slot? {
        didSet {
            guard
                slot != oldValue // breakpoint here
            else {
                return
            }
        }
    }
    
    init() {
        self.slot = .init(time: Date()) // slot is set already in init, so oldValue cannot be nil when breakpoint is triggered
    }
}

let handler = Handler()
handler.slot = .init(time: .distantFuture)
handler.slot = .init(time: .distantPast)
```
@typesanitizer
Copy link

@swift-ci create

@augusto2112
Copy link

@adrian-prantl this bug occurs on lldb shipped with macOS, but is already fixed on the main branch. Can we close it?

@adrian-prantl
Copy link
Member

According Augusto's comment this is already fixed!

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working LLDB for Swift
Projects
None yet
Development

No branches or pull requests

4 participants