Skip to content

[DNM] [Sema] Check whether wrappedValue initializer exists when generating … #68571

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mininny
Copy link
Contributor

@mininny mininny commented Sep 17, 2023

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, the init(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 as type of expression is ambiguous without a type annotation.

I think either one of these is possible:

  • use init(projectedValue:) if init(wrappedValue:) doesn't exist but the initializer parameter type is identical.
  • show a better diagnostic by recording a CSFix?
  • leave it as 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.

  • Am I allowed to produce the diagnostic by creating a CSFix like RemoveProjectedValueArgument?
  • Or should I use some other pass of the compiler to produce the diagnostic, e.g. when typing checking the expression?

Resolves #68570

}

func testParameterWithoutWrappedValueInit(@ProjectionOnlyWrapper value: String) {}
_ = testParameterWithoutWrappedValueInit(value: "") // expected-error {{type of expression is ambiguous without a type annotation}}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new line, please.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new line, please.

@mininny mininny marked this pull request as ready for review October 9, 2023 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Sema] Compiler crash when using a property wrapper parameter without wrapped value initializer
3 participants