[DNM] [Sema] Check whether wrappedValue initializer exists when generating … #68571
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, CSGen assumes that
init(wrappedValue:)
exists in the definition of property wrapper parameter's type.This is true when there's no other initializer in the definition as one will be synthesized. However, if there's
init(projectedValue:)
in the definition, theinit(wrappedValue:)
will not be synthesized.Since the current code assumes that the
init(wrappedValue:)
exists, the compiler continues to apply the constraints. However, because it is missing, the compiler crashes at https://github.com/apple/swift/blob/94c2be87da7d17b94fa2c1f1418ea6d90f9af4b9/lib/Sema/CSApply.cpp#L6149C29-L6149C52 since the property wrapper itself is visible, but doesn't have an initializer that was actually applied.Changes in this PR will fail the CSGen process if the
init(wrappedValue:)
is missing. However, without proper diagnostic, the error message is just shown astype of expression is ambiguous without a type annotation
.I think either one of these is possible:
init(projectedValue:)
ifinit(wrappedValue:)
doesn't exist but the initializer parameter type is identical.type of expression is ambiguous without a type annotation
since the compiler at least doesn't crash.I want to show some better diagnostics like
cannot use property wrapper argument because 'init(wrappedValue:)' doesn't exist.
RemoveProjectedValueArgument
?Resolves #68570