Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sema] Add a fixit for label-mismatch tuple patterns in for-each stat…
…ement. rdar://25671800 In the following code example, compiler emits an error of "cannot express tuple conversion...". However, this is trivially fixable by adding multiple labels in the tuple pattern of the for-each statement. This commit adds such fixit. func foo(array : [(some: Int, (key: Int, value: String))]) { for (i, (k, v)) in array { } }
- Loading branch information
Showing
6 changed files
with
110 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// RUN: %target-swift-frontend -parse -verify %s | ||
|
||
func foo(a : [(some: Int, (key: Int, value: String))]) -> String { | ||
for (i , (j, k)) in a { // expected-error {{cannot express tuple conversion '(some: Int, (key: Int, value: String))' to '(Int, (Int, String))'}}{8-8=some: }} {{13-13=key: }} {{16-16=value: }} | ||
if i == j { return k } | ||
} | ||
} |
0b50648
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Xi,
This is adding a bunch of complexity to the interface of coerceTupleToTuple. Would it be possible to derive this from the locator it already has?
0b50648
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Chris,
Jordan and I discussed this before implementing the fixit and we considered multiple options to pass down the tuple pattern. Using locator seems to be hard here because our locators tightly bind to exprs, which is possibly a design glitch at the first place. Passing down the patterns, which seems ugly for sure, seems the only feasible way to make this happen.