-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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-13069] Crash when using autoclosure escaping in property wrappers #55515
Comments
@swift-ci create |
2 possible workarounds: 1. Provide a default argument for the second initializer parameter: public init(wrappedValue: @autoclosure @escaping () -> Value, _ key: String = "") {
value = wrappedValue
} 2. Provide both property wrapper initializer arguments in the wrapper attribute: @Stored(wrappedValue: "", "test")
var storedProperty: String |
Comment by John Estropia (JIRA) Commenting here as this also broke CoreStore on Swift 5.3 (Xcode 12 beta 4) |
This is fixed by #32866 Could you please verify using the latest master snapshot from https://swift.org/download/#snapshots ? Thank you! |
Comment by John Estropia (JIRA) @hborla |
johnestropia (JIRA User) Unfortunately no, the fix couldn't be cherry-picked to Swift 5.3. However, there are two workarounds that I mentioned above if either of those work for your case |
Comment by John Estropia (JIRA) That's unfortunate, but thanks. Since I need it for an open-source library, what I'd do for now is something like public init(
wrappedValue: @autoclosure @escaping () -> Value,
_ key: String = { fatalError("key is required. This is a workaround for SR-13069") }()) {
...
} Though unfortunately it's a runtime check, and might be overlooked during compilation. |
Attachment: Download
Environment
Apple Swift version 5.3 (swiftlang-1200.0.16.9 clang-1200.0.22.5)
Target: x86_64-apple-darwin19.5.0
Additional Detail from JIRA
md5: 5b6c6380de232e4234f38ab9912541e0
is duplicated by:
Issue Description:
When declaring a property wrapper with an autoclosure escaping block as the wrapped value like the following:
the swift compiler included in the Xcode 12 beta 1 (Apple Swift version 5.3 (swiftlang-1200.0.16.9 clang-1200.0.22.5) Target: x86_64-apple-darwin19.5.0) crashes with the following stack trace:
The compiler doesn't crash if the autoclosure is not escaping, or if the second parameter in the init is removed.
Attached:
The sample swift file
Stack dump when running `swift crash.swift`
A "reproducer" while running "swift" interactively directly from the command line
The text was updated successfully, but these errors were encountered: