-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Sema] Extend callee diagnosis to complex args including generics, e.g. (Void) -> T #1160
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -71,6 +71,7 @@ i.wobble() // expected-error{{value of type 'Int' has no member 'wobble'}} | |
// Generic member does not conform. | ||
extension Int { | ||
func wibble<T: P2>(x: T, _ y: T) -> T { return x } | ||
func wubble<T>(x: Int -> T) -> T { return x(self) } | ||
} | ||
i.wibble(3, 4) // expected-error {{argument type 'Int' does not conform to expected type 'P2'}} | ||
|
||
|
@@ -82,6 +83,15 @@ let a = A() | |
for j in i.wibble(a, a) { // expected-error {{type 'A' does not conform to protocol 'SequenceType'}} | ||
} | ||
|
||
// Generic as part of function/tuple types | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add tests involving typealiases and ensure the diagnostics are still useful and we don't fall back to the general path, and that the diagnostic involves the sugared typealias type and not what it points to |
||
func f6<T:P2>(g: Void -> T) -> (c: Int, i: T) { | ||
return (c: 0, i: g()) | ||
} | ||
func f7() -> (c: Int, v: A) { | ||
let g: Void -> A = { return A() } | ||
return f6(g) // expected-error {{cannot convert return expression of type '(c: Int, i: A)' to return type '(c: Int, v: A)'}} | ||
} | ||
|
||
// <rdar://problem/19658691> QoI: Incorrect diagnostic for calling nonexistent members on literals | ||
1.doesntExist(0) // expected-error {{value of type 'Int' has no member 'doesntExist'}} | ||
[1, 2, 3].doesntExist(0) // expected-error {{value of type '[Int]' has no member 'doesntExist'}} | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
hasTypeVariable() means the type contains a GenericTypeParamType or a DependentMemberType. I don't believe that can happen here since these are contextual types (written in terms of archetypes) and not interface types (written in terms of type parameters).
Maybe try changing that to an assert. If you're seeing both interface and contextual types here, there might be something else to look at.
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.
Actually, I think you mean hasTypeParameter(). hasTypeVariable() is for if the type contains a TypeVariableType that gets inserted by the constraint system. By the time the solver is done there should be none left, but since this is in the couldn't-solve-it path, they can still exist.
This seems rare, but it does happen, like in test/Constraints/diagnostics.swift:644:
where rArgType (when checking the trailing closure param) is:
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.
Yes, I meant hasTypeParameter(), thanks.