Skip to content

Add compatibility tests for implicit (un)tupling in patterns. #26397

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 1 commit into from
Jul 30, 2019
Merged

Add compatibility tests for implicit (un)tupling in patterns. #26397

merged 1 commit into from
Jul 30, 2019

Conversation

varungandhi-apple
Copy link
Contributor

Resolves SR-11212. See the issue description on JIRA for an explanation behind the test cases.

@varungandhi-apple
Copy link
Contributor Author

@swift-ci please smoke test

case tpair((Int, Int))
}

func sr11212_content_tupled_pattern_untupled(t: Tupled) -> (Int, Int) {
Copy link
Contributor

@jrose-apple jrose-apple Jul 29, 2019

Choose a reason for hiding this comment

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

Do we already have test cases for the other two forms?

Can you add test cases for the generic one you've been working on, even if they don't work yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't understand which test cases you're referring to in "other two forms" and "generic one"? The table has 4 entries for code which shouldn't compile but still do (on master) -- I've added one function for each such entry. The SR-11160 fix fails two of those tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right: there should be 12 functions here: all four forms on all three kinds of enum (Untupled, Tupled, and Generic).

@varungandhi-apple
Copy link
Contributor Author

@swift-ci please smoke test

@jrose-apple
Copy link
Contributor

So, hang on, if these all already work, what's different about SR-11160?

@varungandhi-apple
Copy link
Contributor Author

varungandhi-apple commented Jul 30, 2019

Good point! Case 1

switch Optional<(Int, Int)>((5, 6)) { 
case .some(let b): print(b) 
case .none:        print(-1)
}

compiles fine but the supposedly equivalent code Case 2

switch Optional<(Int, Int)>((5, 6)) { 
case let b?: print(b) 
case .none:  print(-1)
}

does not.

The reason this is happening is because the pattern decomposition is incorrect (this is the 3-line fix around conArgSpace in the SR-11160 PR):

_: Optional<(Int, Int)> --> DISJOIN(.none | .some(_: Int, _: Int)) // wrong on master

On master, there is another bug (which I just found out during this investigation), where projecting .some(let b) gives .some(_: Int, _: Int). I will fix this in the SR-11160 PR.

In Case 1, the two bugs cancel out as the overall operation becomes

_: Optional<(Int, Int)> - DISJOIN(.none | .some(_: Int, _: Int))

In Case 2, the pattern that gets formed for let b? is the correct one (because the desugaring does the right thing) so you end up subtracting DISJOIN(.none | .some(let b: (_: Int, _: Int))).

When we try to subtract that from _: Optional<(Int, Int)> we get an error.

@jrose-apple
Copy link
Contributor

Oh wow, so SR-11160 really is specific to the Optional sugar syntax, even if accidentally. Okay, thanks for the explanation, and this looks good to merge!

@jrose-apple
Copy link
Contributor

No wonder we didn't catch it earlier.

@varungandhi-apple
Copy link
Contributor Author

I think the SR-11160 PR is actually introducing another error because it is allowing illegal subtractions instead of fixing the wrong pattern projection. Investigating that right now.

@varungandhi-apple varungandhi-apple merged commit 5177b96 into swiftlang:master Jul 30, 2019
@varungandhi-apple varungandhi-apple deleted the vg-add-tuple-pattern-compat-tests branch July 30, 2019 17:57
@okla
Copy link

okla commented Feb 13, 2020

Hello! I have following warning in Xcode 11.4b1 and not sure what does it mean.

Screen Shot 2020-02-13 at 15 47 15

$0 is of type Result<(username: String, sessionKey: String), Error>

What exactly should I fix in this code?

@varungandhi-apple
Copy link
Contributor Author

@okla you can fix it by writing

.success((username, sessionKey))

Sorry for the trouble. We have PR #28076 up for improving the diagnostic but we haven't merged that yet.

@okla
Copy link

okla commented Feb 13, 2020

Now I understand, thanks!

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