-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[PropertyWrappers] Mark the property as invalid when there is a mismatch with wrappedValue type #27995
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
Conversation
@swift-ci please smoke test |
@swift-ci please smoke test |
@DougGregor can you take a quick look at this? I'd like to merge this before tomorrow's cutoff. Thank you! |
…to match the type of the wrappedValue property Otherwise, we will end up producing wrong diagnostics as well as crashing later on in certain cases
…e is an argument type mismatch in synthesized wrappedValue init This is because we already emit a diagostic to tell the user that the property's type does not match the wrappedValue type, so this diagnostic can be a bit confusing especially because the initializer is synthesized
…pe::get()) as setInvalid automatically does that
I just noticed that this fixes compiler crasher SR-11600 as well. Great! The diagnostics can definitely be improved for wrapper composition though (mostly its the diagnostics around the synthesised wrappedValue init that needs a bit of special-casing/tweaking). |
@swift-ci please smoke test |
Thank you! |
When the property's type does not match the
wrappedValue
property's type, mark the property as invalid. Otherwise, we will end up producing a bunch of incorrect diagnostics later on as well as crashing in certain cases.For example, this little snippet crashes the compiler:
because we're trying to synthesise a setter that assigns a value of type
Int?
into a storage of typeInt
. We also end up emitting a bunch of incorrect diagnostics, such as suggesting the user to force unwrap the property declaration or provide a default value (which isn't possible/make sense).In addition, we emit another diagnostic about failing to convert the argument type, for the synthesised
wrappedValue
initializer. This diagnostic isn't valuable because (1) we already inform the user about the type mismatch between the property's type and thewrappedValue
type and (2) the diagnostic is attached to the synthesised init, but appears on the property and can be confusing to the user. This diagnostic is now disabled for a synthesisedwrappedValue
init.Resolves SR-11684
Resolves SR-11600
Resolves rdar://problem/56785162
Resolves rdar://problem/56345248
Resolves rdar://problem/56190606