Skip to content

[Sema] Check for let vs var bindings of the same variable name in multiple case patterns #15488

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
Mar 30, 2018

Conversation

gregomni
Copy link
Contributor

@gregomni gregomni commented Mar 24, 2018

Resolves SR-7261 | rdar://problem/38800528 .

@gregomni
Copy link
Contributor Author

@swift-ci Please smoke test and merge.

@gregomni
Copy link
Contributor Author

Not sure why the checks never reported back status, so try this again:
@swift-ci Please smoke test and merge.

@@ -2920,6 +2920,9 @@ ERROR(fallthrough_into_case_with_var_binding,none,
ERROR(unnecessary_cast_over_optionset,none,
"unnecessary cast over raw value of %0", (Type))

ERROR(mutability_mismatch_multiple_pattern_list,none,
"pattern variable is '%select{var|let}0', "
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: phrasing.

[var/let] pattern binding must match previous [var/let] pattern binding

@gregomni
Copy link
Contributor Author

Sure, that sounds good. Changed to use @CodaFi 's suggested diagnostic wording, squashed.

@swift-ci Please smoke test and merge.

@gregomni
Copy link
Contributor Author

@shahmishal Hi! Any suggestions on how to unstick swift-ci here?

@shahmishal
Copy link
Member

@gregomni Can you try @swift-ci Please smoke test and merge. again?

@gregomni
Copy link
Contributor Author

@swift-ci Please smoke test and merge

@shahmishal
Copy link
Member

Looking into why its not triggering for you

@gregomni
Copy link
Contributor Author

@shahmishal Sure thing! I think when I first asked swift-ci (5 days ago) it was during a period when the CI servers were hung, and maybe there's something cached somewhere that tests for this pull are already "in progress"?

@gregomni
Copy link
Contributor Author

(It's probably a thing where I could just close this and re-make a new pull, so if it's not useful for debugging swift-ci feel free to tell me to just do that.)

@shahmishal
Copy link
Member

Try again, looking at logs.

@gregomni
Copy link
Contributor Author

@swift-ci Please smoke test and merge

@shahmishal
Copy link
Member

@gregomni Thanks!!

@gregomni
Copy link
Contributor Author

@shahmishal Thank you!

// Would be nice to have a fixit in the following line if we detect that all bindings in the same pattern have the same problem.
case let (a, b) where a < 5, var (a, b) where a > 10: // expected-error 2{{'var' pattern binding must match previous 'let' pattern binding}}{{none}}
break
case (let a, var b) where a < 5, (let a, let b) where a > 10: // expected-error {{'let' pattern binding must match previous 'var' pattern binding}}{{44-47=var}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add a test case with three patterns?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jrose-apple Ah, good call, with three patterns and two wrong, invalidating the first pattern variable when comparing with the 2nd caused a spurious diagnostic about the type of the 3rd not matching error-type. Fixed now!

@gregomni
Copy link
Contributor Author

@swift-ci Please smoke test and merge

@shahmishal
Copy link
Member

@gregomni We have seen issue with force push, where GitHub sha does dont get updated. I recommend asking again if you dont see results with in 2mins.

@shahmishal
Copy link
Member

@swift-ci Please smoke test and merge

@swift-ci swift-ci merged commit 2e862a2 into swiftlang:master Mar 30, 2018
@gregomni gregomni deleted the switchy-var branch August 18, 2020 23:13
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.

5 participants