-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[Sema] Implement SE-0110 #4102
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
[Sema] Implement SE-0110 #4102
Conversation
|
@swift-ci test |
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.
This looks like it's going to need a singular and plural %select for were/was.
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.
I tried to use %switch but couldn't find it in the code base, therefore I use %select instead.
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.
My bad. You're correct.
|
I noticed that this pull request seems to be digging out the underlying pointer from the type structures it's using. You shouldn't have to do that. Instead, try to either use the invariants of the surrounding conditions and their types or use |
|
I've updated the code by the good suggestions. Using |
test/Constraints/closures.swift
Outdated
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.
Did this diagnostic not change?
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.
For the case where contextual type having empty parameter list (ex: () -> Int), I added a constraint where the number of elements has to be greater than or equal to 2. (at TypeCheckConstraints.cpp:1537). The rational behind is because in the case of () -> Int, the parameter would be derived as a TupleType with 0 elements but not ParenType, and for the case of (Int) -> Int it would be a sugared ParenType. And for the case empty tuple it would fall through and catched by TypeCheckPattern.cpp:1573, I cannot handle the case of empty tuple and early return is because it is still likely the closure has zero input, and that would be best delegated to coerceParameterListToType
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.
I mean the were/was distinction. This should be in the singular.
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.
This diagnostic is from closure_argument_list_tuple where I didn't touch (only use it). What I added was closure_argument_list_single_tuple. I think it is a minor bug sticking with closure_argument_list_tuple where it didn't use %select for {was|were}. Do you think the best way would be to put it in this commit? or have a separate bug fixing commit instead?
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.
It's up to you whether you'd like to fix it here or not - it is relevant to the changes you're making. If you choose not to let me know so I can file a JIRA starterbug about it.
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.
I've made the change. I decided to change in this pull request since I realized that the case of singular was would only be triggered by the change in this pull request. Before the change, all of the parameters would be treated as one single tuple and assigned to the single parameter of closure.
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.
Could you add some test cases for this error?
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.
For the singular was case, it has been covered by test/expr/closure/default_args.swift:6 and 7. For the plural case, it was covered by test/Constraints/closures.swift:118, 121, 127, 130, 135. Is there anything I missed or a better way to organize the tests?
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.
I don't see expected-error that includes try add extra parenthesis around the single tuple argument.
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.
my bad. I mis-read your comment as the change on line:2488 since they are quoted as one green block. I would add it, thanks!
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.
Grammar nit: "try adding extra parentheses"
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.
I've added a test case on test/Constraints/closures.swift:326 and corrected the grammar. :)
lib/Sema/TypeCheckPattern.cpp
Outdated
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.
Just to be future-proof: Invert the select and make the P->size() > 1 into P->size() == 1 so we can report 0 in the (bizarre) plural correctly.
This commit built upon the work of Pull Request 3895. Apart from the
work to make the following work
```swift
let f: (Int, Int) -> Void = { x in } // this is now an error
```
This patch also implement the part 2 mentioned in the swiftlang#3895
```swift
let g: ((Int, Int)) -> Void = { y in } // y should have type (Int, Int)
```
|
This is looking fantastic. @swift-ci please smoke test. |
|
@swift-ci please smoke test Linux platform. |
|
hmm, not sure the root of cause of smoke test failure on Linux. One of the failure Traceback |
|
That's not your fault and you don't have to worry about it. Your patch passed our tests. |
|
Now that LLDB has been dealt with, let's land this sucker. @swift-ci please smoke test and merge. |
|
Hrm. So, we're past the point where we can make source changes to Swift 3. We'll need to gate this feature on an as-yet-undesigned version flag. |
|
I can help on that, but it would be great to have a reference commit on how to gate a feature so that I can figure out how to do it easily. |
What's in this pull request?
[Sema] Implement SE-0010
This commit built upon the work of Pull Request 3895 by @dduan. Apart from the work to make the following work
This patch also implement the part 2 mentioned in the #3895
Resolved bug number: (SR-2008)
Before merging this pull request to apple/swift repository:
Triggering Swift CI
The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:
Smoke Testing
A smoke test on macOS does the following:
device standard libraries are not built.
version of these tests are not run.
A smoke test on Linux does the following:
tests are not run.
Validation Testing
Lint Testing
Note: Only members of the Apple organization can trigger swift-ci.
This commit built upon the work of Pull Request 3895. Apart from the
work to make the following work
This patch also implement the part 2 mentioned in the #3895