-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfproperty wrappersFeature: property wrappersFeature: property wrappers
Description
| Previous ID | SR-12202 |
| Radar | rdar://problem/52280477 |
| Original Reporter | @DevAndArtist |
| Type | Bug |
| Status | Resolved |
| Resolution | Done |
Environment
Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)
Additional Detail from JIRA
| Votes | 2 |
| Component/s | Compiler |
| Labels | Bug, PropertyWrappers |
| Assignee | @DevAndArtist |
| Priority | Medium |
md5: 8aaf5e4f262a6c145f3c7cad19fdf8c6
Issue Description:
This general property wrapper works as expected:
@propertyWrapper
struct W<T> { var wrappedValue: T }
struct S {
@W var value: Int
init(value: Int) {
// this works because, what the compiler will substitute
// the next line with `self._value = _W(wrappedValue: value)`
self.value = value
}
}This one from SwiftUI doesn't for some reason:
import SwiftUI
struct V: View {
@State var value: Int
init(value: Int) {
// error: 'self' used before all stored properties are initialized
// error: Return from initializer without initializing all stored properties
self.value = value
}
var body: Never {
fatalError()
}
}Expected behavior is that the compiler substitute the above line like with every other property wrapper, which would be `self._value = State(wrappedValue: value)`.
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselfproperty wrappersFeature: property wrappersFeature: property wrappers