Open swift-ci opened 4 years ago
Comment by Noah Gilmore (JIRA)
Interestingly, this seems to be localized to the Foundation version of Published. The following compiles just fine for me:
@propertyWrapper
struct Published<Value> {
var wrappedValue: Value
init(wrappedValue: Value) {
self.wrappedValue = wrappedValue
}
}
@propertyWrapper
struct Wrapper {
var wrappedValue: String {
get { "" }
set { }
} init(wrappedValue: String) {
// do nothing
}
}
class Test {
@Published
@Wrapper
var string: String = ""
}
Comment by Owen Voorhees (JIRA)
For anyone looking into this further, I was able to reproduce this without the Foundation import by adding an _enclosingInstance subscript to the outer wrapper:
@propertyWrapper struct Wrapper {
var wrappedValue: String {
get { "" }
set { }
}
init(wrappedValue: String) {
// do nothing
}
}
@propertyWrapper struct Published<T> {
var storage: T?
var wrappedValue: T {
get { storage! }
set { }
}
init(wrappedValue: T) {
// do nothing
}
static subscript<EnclosingSelf>(
_enclosingInstance observed: EnclosingSelf,
wrapped wrappedKeyPath: ReferenceWritableKeyPath<EnclosingSelf, T>,
storage storageKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Self>
) -> T {
get {
observed[keyPath: storageKeyPath].storage!
}
set {
observed[keyPath: storageKeyPath].storage! = newValue
}
}
}
class Test {
@Published
@Wrapper
var string: String = ""
}
cc @hborla@DougGregor
On master, I get an error: key path value type 'String' cannot be converted to contextual type 'Wrapper'
, although it has no source location and the code no longer crashes. So, I'd say the crash is fixed, but the diagnostic could probably be improved.
We still have the poor diagnostic on main
@swift-ci create
Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, DiagnosticsQoI, PropertyWrappers, TypeChecker | |Assignee | None | |Priority | Medium | md5: 63bf602a60242938e94b3c2e998c7f8eIssue Description:
(Swift 5.2.2, Xcode 11.4.1)
Using Published (from Foundation) nested with another property wrapper reliably causes a segfault. The minimal reproduction example I've managed to find is:
This causes a segfault with the following stacktrace:
Please let me know if I can provide more info! Happy to discuss further