Skip to content

[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
merged 18 commits into from
Jun 3, 2020

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Jun 1, 2020

Instead of having these diagnostics be a part of ContextualFailure extract them into
their own distinct diagnostic classes which allows to produce better fix-its.

Also move logic from attempt methods into repairFailures and use new fix logic
to diagnose assignment, contextual and argument-to-parameter conversion failures.

xedin added 14 commits May 27, 2020 17:26
… 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`.
…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.
…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`.
@xedin xedin requested a review from hborla June 1, 2020 22:23
@xedin
Copy link
Contributor Author

xedin commented Jun 1, 2020

@swift-ci please smoke test

Copy link
Member

@hborla hborla left a 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!

@xedin
Copy link
Contributor Author

xedin commented Jun 3, 2020

@swift-ci please smoke test

@xedin
Copy link
Contributor Author

xedin commented Jun 3, 2020

All of the suggestions have been addressed, merging.

@xedin xedin merged commit 651503b into swiftlang:master Jun 3, 2020
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.

2 participants