Files
swift-mirror/test/Generics/materializable_restrictions.swift
gregomni 2b301938e0 [SR-69][Sema] Improved quality of diagnoses messages
In the specific case of sr-69, and in a bunch of other code where
errors arise involving generic function application, better type
constraint failure diagnoses are being masked by the overly
conservative implementation in evaluateCloseness(). If the actual arg
types didn’t exactly match the parameter types, we’d always diagnose a
non-specific arguments-don’t-match error instead of allowing discovery
of better errors from the constraint system.

This commit adds more cases where evaluateCloseness will return
CC_ExactMatch, specifically in application of functions with one or
more arguments of a single archetype, like `func min<T: Comparable>(T,
T) -> T`. It verifies that the actual argument type
isSubstitutableFor() the archetype, and that all such arguments are of
the same type. Anything more complicated than that still has the
previous behavior of not matching at all.

I think the final answer here ought to be to make a constraint system
with type variables for any archetypes, add appropriate constraints to
the actual args and then see if the system can solve all the argument
constraints at once. That’s because the next most complicated set of
things to handle in the stdlib are things like `func -<T:
Strideable>(lhs: T, rhs: T.Stride)` where generic argument types depend
on each other. I tried attacking that, but it was too big of a bite for
me to manage all at once. But there are FIXME’s here to try that again
at some point.

New tests for SR-69 are at the end of deduction.swift, and the rest of
the test changes are generally improved deduced diagnoses. I think the
changed diagnoses in materializable_restrictions.swift is the only one
which is worse instead of better, and that’s just because the previous
general message mentioned `inout` basically accidentally. Opportunity
for further improvement (a new diagnosis maybe) there.

Validation tests run and passed.
2016-01-21 23:48:54 -08:00

25 lines
618 B
Swift

// RUN: %target-parse-verify-swift
func test15921520() {
var x: Int = 0
func f<T>(x: T) {} // expected-note{{in call to function 'f'}}
f(&x) // expected-error{{generic parameter 'T' could not be inferred}}
}
func test20807269() {
var x: Int = 0
func f<T>(x: T) {}
f(1, &x) // expected-error{{extra argument in call}}
}
func test15921530() {
struct X {}
func makef<T>() -> (T) -> () { // expected-note {{in call to function 'makef'}}
return {
x in ()
}
}
var _: (inout X) -> () = makef() // expected-error{{generic parameter 'T' could not be inferred}}
}