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
[ConstraintSystem] Detect and diagnose missing generic arguments #25149
Conversation
…locator points to one
Emit separate notes for generic parameters found in operator, initializer and function declarations. As well as clarify types of `declared in type` note.
… member to `Any` As part of the `DefineBasedOnUse` fix introduced in places where there is a reference to non-existent member, let's also add constraints which allow to default any generic parameters found in base type to `Any`.
Introduce a fix to detect and diagnose situations when omitted generic arguments couldn't be deduced by the solver based on the enclosing context. Example: ```swift struct S<T> { } _ = S() // There is not enough context to deduce `T` ``` Resolves: rdar://problem/51203824
…uments with new diagnostic
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 stuff!
@@ -102,7 +102,7 @@ func longArray() { | |||
var _=["1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1"] | |||
} | |||
|
|||
[1,2].map // expected-error {{expression type '((Int) throws -> _) throws -> [_]' is ambiguous without more context}} | |||
[1,2].map // expected-error {{generic parameter 'T' could not be inferred}} |
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!
@@ -79,7 +79,8 @@ func badDiagnostic2() { | |||
func takesAny(_ a: Any) {} | |||
|
|||
func badDiagnostic3() { | |||
takesAny(Deli.self) // expected-error {{argument type 'Deli<_>.Type' does not conform to expected type 'Any'}} |
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!
// expected-error@-1 {{generic parameter 'A' could not be inferred}} | ||
_ = Claws.Fangs<NotADog>() | ||
// expected-error@-1 {{generic parameter 'A' could not be inferred}} | ||
// expected-error@-2 {{referencing initializer 'init()' on 'Claws.Fangs' requires that 'NotADog' conform to 'ExpressibleByDogLiteral'}} |
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!
let _ : D = D<Int, Int, Float>(a: 1, b: 2) | ||
// expected-error@-1 {{generic parameter 'T3' could not be inferred}} |
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!
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.
Sorry I do have a couple of minor comments :)
|
||
_ = Pair< // expected-error {{generic parameter 'Foo' could not be inferred}} | ||
_ = Pair< | ||
FullyGeneric, |
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.
@slavapestov I think the biggest improvement here is actually related to couple of examples down here, which we now diagnostic relative to TypeRepr and suggest all of the missing signatures.
This is great! Would it be possible to show the declaration name in the diagnostic? For some of these cases, I think it'd be easier to understand if the diagnostic could point at the declaration the generic argument comes from, e.g.:
since in some cases there may be multiple generic declarations involved in an expression. |
@jckarter Yes, absolutely, also I'll also cover more cases in the note, it currently only covers functions and initializes. |
@swift-ci please test |
@swift-ci please test source compatibility |
Build failed |
Build failed |
Introduce a fix to detect and diagnose situations when omitted
generic arguments couldn't be deduced by the solver based on
the enclosing context.
Example:
Resolves: rdar://problem/51203824