Skip to content

[Diagnostics] Diagnose conflicting pattern variables #59210

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 3 commits into from
Jun 14, 2022

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Jun 1, 2022

Diagnose situations where pattern variables with the same name
have conflicting types:

 enum E {
 case a(Int)
 case b(String)
 }

 func fn(_: () -> Void) {}

 func test(e: E) {
   fn {
     switch e {
     case .a(let x), .b(let x): ...
     }
   }
 }

In this example x is bound to Int and String at the same
time which is incorrect.

@xedin xedin requested a review from hborla June 1, 2022 21:54
@xedin xedin force-pushed the conflicting-patterns-in-case branch from 914b2e7 to 7ce6fa6 Compare June 1, 2022 21:57
@xedin xedin force-pushed the conflicting-patterns-in-case branch from 7ce6fa6 to 117ae23 Compare June 1, 2022 23:52
xedin added 3 commits June 3, 2022 16:31
The fix indentifies the conflicting variables and the expected
"join" type e.g. `case .a(let x), .b(let x)` where `a(Int)` and
`b(String)`.
Diagnose situations where pattern variables with the same name
have conflicting types:

```swift
enum E {
case a(Int)
case b(String)
}

func test(e: E) {
  switch e {
  case .a(let x), .b(let x): ...
  }
}
```

In this example `x` is bound to `Int` and `String` at the same
time which is incorrect.
… statements

Avoid mutating case label items while solving, instead let's use types
recorded in the constraint system for each pattern variable and use
that for var reference in the case body. This also helps to detect
and diagnose type conflicts while solving.
@xedin xedin force-pushed the conflicting-patterns-in-case branch from 117ae23 to 9c8bebe Compare June 3, 2022 23:35
@xedin
Copy link
Contributor Author

xedin commented Jun 8, 2022

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Jun 14, 2022

@swift-ci please smoke test

@xedin
Copy link
Contributor Author

xedin commented Jun 14, 2022

@swift-ci please smoke test Linux platform

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.

3 participants