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-7647] Property observer called when accessing optional property that conforms to a protocol #50188

Closed
swift-ci opened this issue May 10, 2018 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 4.1

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-7647
Radar rdar://problem/38514252
Original Reporter mittenimraum (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Xcode Version 9.3 (9E145)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 4.1Regression
Assignee None
Priority Medium

md5: ac1cdb69a3a823a91e8553cf1ea6a251

duplicates:

  • SR-7335 Mutating struct when accessing read only member through subscript

relates to:

  • SR-7335 Mutating struct when accessing read only member through subscript

Issue Description:

protocol BarProtocol {
    var bar: Int?  { get set }
}

protocol FooProtocol {
    var foo: BarProtocol? { get set }
}

struct TestProperty: FooProtocol {
    
    var foo: BarProtocol?
}

class TestClass {
    
    var property: FooProtocol? {
        didSet {
            debugPrint("didSet")
            
            doSomething()
        }
    }
    
    func doSomething() {
        property?.foo?.bar // causes didSet to be triggered, which causes an infinity loop
    }
}

let instance = TestClass()
instance.property = TestProperty()

The above example will cause didSet to be called infinitely. This behavior is new and did not appear in previous Swift versions or at least in Swift 4.0.

@belkadan
Copy link
Contributor

Probably the same as SR-7335.

@swift-ci create

@belkadan
Copy link
Contributor

JoeG says yes.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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 A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself regression swift 4.1
Projects
None yet
Development

No branches or pull requests

3 participants