-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Diagnostics] Refactor diagnostics related to raw representable types #32128
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… init Diagnose an attempt to initialize raw representable type or convert to it a value of some other type that matches its `RawValue` type. ```swift enum E : Int { case a, b, c } let _: E = 0 ``` `0` has to be wrapped into `E(rawValue: 0)` and either defaulted via `??` or force unwrapped to constitute a valid binding.
…table` Do the verification during constraint repair and provide fix itself with raw representative type and its raw value to be used for diagnostics.
…alization This makes logic in `ContextualFailure::tryRawRepresentableFixIts` partially obsolete.
…struction Since both raw representable and value types originated in constraint system they can have type variables which need to be resolved before types could be used in a diagnostic and fix-it.
…ontruct raw representable Introduce `repairByExplicitRawRepresentativeUse` which is used for assignment, argument-to-parameter conversions and contextual mismatches. It checks whether `to` side is a raw representable type and tries to match `from` side to its `rawValue`.
…RawRepresentableFixIts`
…into `AbstractRawRepresentableFailure`
…instead of its raw value Diagnose an attempt to pass raw representable type where its raw value is expected instead. ```swift enum E : Int { case one = 1 } let _: Int = E.one ``` `E.one` has to use `.rawValue` to match `Int` expected by pattern binding.
…entable fix/diagnostics
…Value` Introduce `repairByUsingRawValueOfRawRepresentableType` which is used for assignment, argument-to-parameter conversions and contextual mismatches. It checks whether `from` side is a raw representable type and tries to match `to` side to its `rawValue`. Also extract logic common for `repairByUsingRawValueOfRawRepresentableType` and `repairByExplicitRawRepresentativeUse` into `isValueOfRawRepresentable`.
@swift-ci please smoke test |
hborla
reviewed
Jun 1, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few nit picks, mostly about naming, but otherwise looks good!
…`AbstractRawRepresentableFailure`
@swift-ci please smoke test |
All of the suggestions have been addressed, merging. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Instead of having these diagnostics be a part of
ContextualFailure
extract them intotheir own distinct diagnostic classes which allows to produce better fix-its.
Also move logic from
attempt
methods intorepairFailures
and use new fix logicto diagnose assignment, contextual and argument-to-parameter conversion failures.