Skip to content

[ResultBuilders] A couple pattern matching fixes to make it consistent with TypeCheckPattern #39458

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
Oct 4, 2021

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Sep 25, 2021

  • Preserve labels during splat situations in pattern matching context

Tuple splat/implosion is (still) allowed for patterns (with a warning in Swift 5)
so we need to use SingleApply while looking up members to make sure that e.g.
case test(x: Int, y: Int) gets the labels preserved when matched with
case let .test(tuple) and Compound when associated values form a tuple pattern.

  • Make solver behavior consistent with TypeCheckPattern for paren patterns

A single paren pattern becomes a labeled tuple pattern e.g. case .test(let value):
should be able to match case test(result: Int). Note that it also means that:
cast test(result: (String, Int)) would be matched against e.g. case .test((let x, let y))
but that fails during pattern coercion (behavior consistent with what happens in
TypeCheckPattern).

…ontext

Tuple splat/implosion is (still) allowed for patterns (with a warning in Swift 5)
so we need to use `SingleApply` while looking up members to make sure that e.g.
`case test(x: Int, y: Int)` gets the labels preserved when matched with
`case let .test(tuple)` and `Compound` when associated values form a tuple pattern.
…for paren patterns

A single paren pattern becomes a labeled tuple pattern
e.g. `case .test(let value):` should be able to match
`case test(result: Int)`. Note that it also means that:
`cast test(result: (String, Int))` would be matched against
e.g. `case .test((let x, let y))` but that fails during
pattern coercion (behavior consistent with what happens in
`TypeCheckPattern`).
@xedin xedin requested a review from hborla September 25, 2021 18:46
@xedin
Copy link
Contributor Author

xedin commented Sep 25, 2021

@swift-ci please test

@xedin
Copy link
Contributor Author

xedin commented Sep 25, 2021

@swift-ci please test source compatibility

@hborla
Copy link
Member

hborla commented Oct 1, 2021

@swift-ci please smoke test

@xedin xedin merged commit ed45116 into swiftlang:main Oct 4, 2021
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