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
[Diagnostics] Introduce argument-to-parameter mismatch #27063
Conversation
This is still a draft, 10+ tests are failing, mainly due to changes related to |
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.
The new diagnostics are looking much better overall. Excellent work!
8fd606c
to
d5996ea
Compare
0bd7b73
to
68994e4
Compare
@swift-ci please test |
@swift-ci please test source compatibility |
Build failed |
Build failed |
Please test with following pull request: @swift-ci please test |
@shahmishal Doesn't look source compatibility suite failure in
|
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 is fantastic!
func f19997471(_ x: String) {} | ||
func f19997471(_ x: Int) {} | ||
func f19997471(_ x: String) {} // expected-note {{candidate expects value of type 'String' at position #0}} | ||
func f19997471(_ x: Int) {} // expected-note {{candidate expects value of type 'Int' at position #0}} |
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.
NICE!
|
||
func someGeneric19997471<T>(_ x: T) { | ||
takeVoidVoidFn { | ||
f19997471(x) // expected-error {{cannot invoke 'f19997471' with an argument list of type '(T)'}} | ||
// expected-note @-1 {{overloads for 'f19997471' exist with these partially matching parameter lists: (Int), (String)}} | ||
f19997471(x) // expected-error {{no exact matches in call to global function 'f19997471'}} |
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.
Doesn't to be this pull request, but it would be really nice if we reminded the user of the types of the arguments here.
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.
Do you think it would be better to attach arguments to this diagnostic or to each note?
// Once argument-to-parameter mismatch diagnostics are moved to the new diagnostic framework, we'll be able to restore | ||
// original contextual conversion failure diagnostic here. Note that this only happens in Swift 4 mode. | ||
elems.deinitialize(count: self.value) // expected-error {{ambiguous reference to member 'deinitialize(count:)'}} | ||
elems.deinitialize(count: self.value) // expected-error {{cannot convert value of type 'UInt' to expected argument type 'Int'}} |
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.
Great!
Build failed |
Please test with following pull request: @swift-ci please test |
Ugh, have to resolve a conflict in |
No specialized diagnostics yet, just a basic infrastructure to produce generic a `cannot convert X to expected argument type Y` message.
…s a `Bool` in argument position
… down Since this is the most generic failure, we need to make sure that it doesn't interfere with other more specific fixes.
… due to missing conformance
…ions Most of the fix-its associated with contextual failures are also appropriate for argument-to-parameter conversion mismatches.
…sitions There is logic in `matchTypes` which would unwrap l-value if other type is not an `inout`, which is not great for cases where parameter type is a pointer and argument is an l-value which requires explicit `&` to be converted.
… be resolved Currently in cases where dependent member types cannot be resolved properly due to invalid base type they do not fail comparison, but instead result in a new "inactive" constraint which is incorrect.
… of invalid expressions If expression is incorrect it most likely wouldn't be able to satisfy `Equatable` or other requirements of `~=` operator overloads, but at the same time the main problem is related to `case` expression itself so let's not diagnose missing conformances.
In cases when all of the fixed solutions have only one problem in common - different overloads of a certain operator, let's produce a tailored diagnostic and suggest matching partial overloads along side diagnostic notes which point to each choice.
…in diagnostic mode Some spots of constraint simplification logic are too eager to fail right away without giving repair logic to run in diagnostic mode and attempt to fix the problem. Failing early in diagnostic mode means solver wouldn't be able to reach some possible solutions which leads to subpar diagnostics.
…missing conformance If missing conformance is between two stdlib defined types which are used in operator invocation, let's produce a generic diagnostic about operator reference and a note about missing conformance.
…meter is a collection This allows better diagnostics in cases where collection element is a generic parameter which is supposed to be inferred from argument e.g. ```swift func foo<T>(_: [T]) {} foo(1) // Missing brackets, so error should be about [Int] vs. Int ```
…extual Impact is higher if the base is expected to be inferred from context, because a failure to find a member ultimately means that base type is not a match in this case.
…ameter mismatches
…elated to generic subscripts
… diagnostic location If one of the arguments to binary operator is invalid, let's verify that diagnostic points directly to it.
dc70a3c
to
1bd4bb9
Compare
Please test with following pull request: @swift-ci please test |
W00t! Merge it! |
Alright, let's run the tests one more time and |
Please test with following pull request: @swift-ci please test |
This PR aims to port argument-to-parameter conversion failures in their most general form
cannot convert X to expected argument Y
and some port tailored diagnostics related to them, lift some of the restrictions on use of requirement failures and remove now obsolete logic from CSDiag.Resolves: rdar://problem/54613698
Resolves: rdar://problem/55254652
Resolves: rdar://problem/51262694
Resolves: rdar://problem/52334290
Resolves: rdar://problem/17647738
Resolves: rdar://problem/18624434
Resolves: rdar://problem/19979645
Resolves: rdar://problem/21032147
Resolves: rdar://problem/22042549
Resolves: rdar://problem/25639952
Resolves: rdar://problem/28047208
Resolves: rdar://problem/28555798
Resolves: rdar://problem/28675189
Resolves: rdar://problem/29214149
Resolves: rdar://problem/31785308
Resolves: rdar://problem/32390841
Resolves: rdar://problem/33914446
Resolves: rdar://problem/41303412
Resolves: rdar://problem/35420209
Resolves: rdar://problem/21948825
Resolves: SR-11388
Resolves: SR-4795