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-7212] Regression from 4.0: didSet {} called on property read if property type is protocol containing array #49760

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

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-7212
Radar https://bugreport.apple.com/web/?problemID=38514252
Original Reporter paddlefish (JIRA User)
Type Bug
Status Resolved
Resolution Done

Attachment: Download

Environment

Xcode Version 9.3 beta 4 (9Q127n)
macOS 10.13.3 (17D102)
Model Name: MacBook Pro
Model Identifier: MacBookPro11,5

Additional Detail from JIRA
Votes 9
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: c9837c3c331cb29ff8595b6ce1439c11

is duplicated by:

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

Issue Description:

Summary:
In Xcode 9.3 Beta 4, the following code emits the string "Bug! didSet {} called on read" to the console. No property read should trigger the didSet call.

Steps to Reproduce:
Paste this Swift code into the swift command-line REPL:
protocol ProtocolWithArray {
var arrayOfInt: [Int] { get set }
}

var questionSet: ProtocolWithArray? {
didSet {
print("Bug! didSet {} called on read.")
}
}

func fiddle() -> Int? {
return questionSet?.arrayOfInt[0]
}

print("Starting")
fiddle()
print("Done")

Expected Results (as seen with Xcode 9.2):

Welcome to Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)

...

Starting
Done

Actual Results (as seen with Xcode 9.3 Beta 4):

Welcome to Apple Swift version 4.1 (swiftlang-902.0.43 clang-902.0.37.1).

...

Starting
Bug! didSet {} called on read.
Done

@swift-ci
Copy link
Collaborator Author

swift-ci commented Aug 5, 2018

Comment by Andrew Rahn (JIRA)

I tested Xcode 10.0 Beta. The bug no longer happens using the attached script "didSetCompilerBug.swift".

Hoping the fix lands here soon, too!

@belkadan
Copy link
Contributor

Oops, this should be fixed as of Swift 4.2 / Xcode 10.

@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
Projects
None yet
Development

No branches or pull requests

2 participants