Commit Graph

69 Commits

Author SHA1 Message Date
Max Moiseev
a49dab6bf8 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-29 12:08:52 -08:00
Daniel Duan
780b58a9a5 [Parser] update tests for 'inout' syntax adjustment 2016-02-26 01:33:22 -08:00
Max Moiseev
3a3984877a Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-15 15:43:34 -08:00
Chris Lattner
5bad3ba49a Warn about implicit tuple splat in a parameter list. 2016-02-09 14:01:50 -08:00
Max Moiseev
61c837209b Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-04 16:13:39 -08:00
gregomni
6b30695869 Extend callee diagnosis to complex args including generics, e.g. (Void) -> T
Correctly determine callee closeness for func/ops that include generics
as part of more complicated parameters, i.e. tuple or closure args
containing generics as elements or args/results. Still only handling
single archetypes.

Also added code to check generic substitutions already made in the callee
parameters, which further helps diagnosis.
2016-02-03 22:54:19 -08:00
gregomni
05ebb021ba Add a slightly less close than CC_OneArgumentMismatch closeness.
Producing single argument mismatches involving generics causes some
gross looking error messages if the generic mismatches get put into the
same closeness bucket as non-generic mismatches.

E.g. `var v71 = true + 1.0` used to produce `error: cannot convert
value of type 'Bool' to expected argument type 'Double’`, but would now
end up with `binary operator '+' cannot be applied to operands of type
'Bool' and 'Double’` `overloads for '+' exist with these partially
matching parameter lists: (Double, Double), (T, T.Stride), (T.Stride,
T)`.

Resolve this by adding CC_OneGenericArgumentNearMismatch and
CC_OneGenericArgumentMismatch, that are similar but ever so slightly
not as close as a mismatch involving non-generic functions. This gets
back the original error message in cases like the above, because there
is only one declaration of `+` which partially matches and is
non-generic, and the generic partial matches are now farther away.

But now single arg mismatches and nearness work for single-archetype
generic functions, as in the additions to the SR-69 test at the end of
deduction.swift.
2016-01-22 10:24:03 -08:00
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
Maxim Moiseev
2c95bb6d51 BooleanType => Boolean 2015-12-10 14:56:32 -08:00
Chris Lattner
96a1e96dea Improve printing of "too few" or "too many" arguments in generic or
overloaded argument list mismatches.  We printed them in simple cases
due to "Failure" detecting them in trivial situations.  Instead of
doing that, let CSDiags do it, which allows us to pick things out of
overload sets and handle the more complex cases well.

This is a progression across the board except for a couple of cases
where we now produce "cannot convert value of type 'whatever' to
expected argument type '(arglist)'", this is a known issue that I'll
fix in a subsequent commit.
2015-12-07 23:09:08 -08:00
Chris Lattner
6636bafadf Fix <rdar://problem/23272739> Poor diagnostic due to contextual constraint
Previously we erroneously complained:
  error: cannot invoke 'contains' with an argument list of type '(String)'
now we correctly complain:
  error: unexpected non-void return value in void function

This enhances CSDiags to use "getTypeOfMember" when analyzing method
candidates that are applied to a known base type.  Using it allows us to
substitute information about the base, resolving archetypes that exist in
subsequent argument positions.  In the testcase, this means that we use
information about Set<String> to know that the argument to "contains" is a
String.

This allows us to generate much better diagnostics in some cases, and works
around some limitations in the existing stuff for handling unresolved
archetypes.  One unfortunate change is the notes in Misc/misc_diagnostics.swift.
Because we don't track argument lists very well, we are flattening an argument
list that is actually ((Int,Int)) into (Int, Int) so we get a bogus looking
diagnostic.  This was possible before this patch though, it is just one
more case that triggers the issue.
2015-12-01 21:22:24 -08:00
Chris Lattner
85501b436e Remove some weird hacks that added special case behavior for operators. This
code had the effect of squishing the note that printed the overload candidate
set for the operators in question.  While these are not generally helpful given
how many overloads we have of (e.g.) the + operator, it doesn't do us any good
to have special cases like this, because methods can have tons of overloads as
well.
2015-11-15 21:24:57 -08:00
Chris Lattner
e47065b68c Dial back the specificity of these diagnostics a bit to not mention Float80 to avoid breaking test on targets that lack it.
Swift SVN r31892
2015-09-11 06:15:35 +00:00
Chris Lattner
96eaa14f3b Fix an arbitrary restriction where we would not propagate the result type of
call expression onto a callee when it was a binary expression.  Doing this
requires improving the diagnostics for when the contextual result type is
incompatible with all candidates, but that is general goodness all around.

This fixes:
<rdar://problem/22333090> QoI: Propagate contextual information in a call to operands

and improves a number of diagnostics where the problem is that an operator
is used in a context that expects a type that it cannot produce.



Swift SVN r31891
2015-09-11 06:12:05 +00:00
Chris Lattner
72c5c3e4fe Two changes:
- Enhance the branch new argument label overload diagnostic to just
   print the argument labels that are the problem, instead of printing
   the types inferred at the argument context.  This can lead to confusion
   particularly when an argument label is missing.  For example before:

error: argument labels '(Int)' do not match any available overloads
note: overloads for 'TestOverloadSets.init' exist with these partially matching parameter lists: (a: Z0), (value: Int), (value: Double)

after:

error: argument labels '(_:)' do not match any available overloads
note: overloads for 'TestOverloadSets.init' exist with these partially matching parameter lists: (a: Z0), (value: Int), (value: Double)


Second, fix <rdar://problem/22451001> QoI: incorrect diagnostic when argument to print has the wrong type
by specifically diagnosing the problem when you pass in an argument to a nullary function.  Before:

error: cannot convert value of type 'Int' to expected argument type '()'

after:
error: argument passed to call that takes no arguments
print(r22451001(5))
                ^




Swift SVN r31795
2015-09-09 00:26:37 +00:00
Chris Lattner
f571e64161 Enhance visitCallExpr in the face of a contextual type. Only perform the
forced conversion to "_ -> T" if it will refine the type otherwise found by
doing a non-contextual type check.  This allows us to diagnose calls to 
non-function values with more specificity, e.g. adding another case were we
recommend "do" when using bare braces.


Swift SVN r31726
2015-09-06 19:01:47 +00:00
Chris Lattner
34ae9bb9b6 Fix <rdar://problem/22584076> QoI: Using array literal init with dictionary produces bogus error
This includes a few changes:
 - Enhance diagnoseGeneralConversionFailure to not ignore constraints that are fully solved by
   CSDiags' heuristics.
 - Enhance dictionary/array literals diagnostics to handle non-compliance to their literal 
   protocols with a specific and custom error message.
 - Add specific QoI for turning accidental use of array literals in dictionary context into
   the right dictionary syntax (with a fixit).


Swift SVN r31696
2015-09-04 22:31:21 +00:00
Chris Lattner
d167dfbbfa When typechecking the callee of a CallExpr, and when we have a contextual type,
use that contextual type to guide typechecking of the callee.  This allows us to
propagate that type through generic constraints effectively, making us produce
much more useful diagnostics within closures taking methods like "map" (for 
example).

This fixes:
<rdar://problem/20491794> QoI closures: Error message does not tell me what the problem is
Specifically, running the testcase:

enum Color { case Unknown(description: String) }
let xs: (Int, Color) = [1,2].map({ ($0, .Unknown("")) })

produces: error: cannot convert call result type '[_]' to expected type '(Int, Color)'

Changing that to:
let xs: [(Int, Color)] = [1,2].map({ ($0, .Unknown("")) })

produces: error: missing argument label 'description:' in call
... with a fixit to introduce the label.

This also fixes most of 22333090, but we're only using this machinery for CallExprs
so far, not for operators yet.



Swift SVN r31484
2015-08-26 05:41:47 +00:00
Chris Lattner
186fa8e9d6 Eliminate the TCC_AllowUnresolved flag by having typeCheckChildIndependently
automatically pass down TypeCheckExprFlags::AllowUnresolvedTypeVariables 
IFF we have no contextual type.  This gives us UnresolvedTypes in more cases,
which improves diagnostics in various situations, and also simplifies
CSDiag.  The change to misc_diagnostics.swift is a particularly nice progression.



Swift SVN r31406
2015-08-22 05:41:28 +00:00
Chris Lattner
6358c3049d Now that we consistently propagate contextual type information when it
is available, use it to start producing useful diagnostics for contextually
typed member references.


Swift SVN r31362
2015-08-20 17:07:15 +00:00
Chris Lattner
458534f9d7 fix <rdar://problem/22320758> QoI: collection literals don't handle substitutions well in csdiag
Now we can propagate contextual types through collection literals even when they are generic, producing
specific diagnostics for elements within them.


Swift SVN r31327
2015-08-19 04:24:27 +00:00
Chris Willmore
8c57b7cde5 Improve diagnosis of implicit match expressions
When diagnosing failure to typecheck a binary '~=' expression that was
synthesized when typechecking an expression pattern, offer a message
that describes the failure more helpfully.

<rdar://problem/21995744> QoI: Binary operator '~=' cannot be applied to operands of type 'String' and 'String?'

Swift SVN r31286
2015-08-18 02:33:10 +00:00
Chris Lattner
ada5487153 add fixit tests to random other tests.
Swift SVN r31006
2015-08-04 20:35:36 +00:00
Chris Lattner
97e6a50148 Start using contextual information from function calls to diagnose issues in their
argument.  For now we start with some of the most simple cases: single argument 
calls.  This dramatically improves the QoI for error messages in argument lists,
typically turning a error+note combo into a single specific error message.

Some minor improvements coming (and also generalizing this to n-ary calls), but it 
is nice that all the infrastructure is starting to come together...



Swift SVN r30905
2015-08-01 04:37:52 +00:00
Chris Lattner
1a0a0315fe wordsmith a diagnostic, NFC otherwise.
Swift SVN r30731
2015-07-28 23:35:25 +00:00
Chris Lattner
06cc05daa9 reword a diagnostic, as suggested by Jordan
Swift SVN r30712
2015-07-28 04:03:25 +00:00
Chris Lattner
8c3e62d7c5 Provide contextually sensitive conversion failure messages for situations in
which we have a contextual type that was the failure reason.  These are a bit
longer but also more explicit than the previous diagnostics.



Swift SVN r30669
2015-07-26 23:06:40 +00:00
Chris Lattner
eb01d5de9d word-smith a diagnostic in preparation for it becoming a family.
Swift SVN r30668
2015-07-26 22:42:32 +00:00
Chris Lattner
467cd07968 Two changes:
- Improve handling of if_expr in a couple of ways: teach constraint simplification
   about IfThen/IfElse and teach CSDiags about the case when the cond expr doesn't match
   BooleanType.  This is rarely necessary, but CSDiags is all about cornercases, and this
   does fix a problem in a testcase.
 - Be a bit more specific about the constraint failure kind (e.g. say subtype) and when
   we have a protocol conformance failure, emit a specific diagnostic about it, instead of
   just saying that the types aren't convertible.




Swift SVN r30650
2015-07-26 05:31:12 +00:00
Chris Lattner
dff93b512b Now that we have the notion of an uncurry level, we can do a lot more
detailed analysis of callees, which give us overload sets in more cases,
producing notes more consistently, and producing much better diagnostics
for the curried cases in test/Constraints/diagnostics.swift.

This also allows us to eliminate getCalleeName, which simplifies things
in CSDiags.


Swift SVN r30491
2015-07-22 05:37:39 +00:00
Chris Lattner
5d3dc0d77b Now that sufficient complexity is pushed into the right corners of the compiler,
we can start taking advantage of ambiguously typed subexpressions in CSDiags.  We
start by validating the callee function of ApplyExprs, which substantially improves
our abilities to generate precise diagnostics about malformed calls.

This is the minimal introduction of this concept to CSDiags, a lot of refactoring
is yet to come, however, this is enough to resolve:

<rdar://problem/21080030> Bad diagnostic for invalid method call in boolean expression
<rdar://problem/21784170> Incongruous `unexpected trailing closure` error in `init` function which is cast and called without trailing closure.

one of the testcases from:
<rdar://problem/20789423> Unclear diagnostic for multi-statement closure with no return type

and a bunch of other places where we got weird "unexpected trailing closure" 
diagnostics that made no sense.  As usual, it is two steps forward and one step back,
as this exposed some other weird latent issues like:
<rdar://problem/21900971> QoI: Bogus conversion error in generics case




Swift SVN r30429
2015-07-21 01:06:55 +00:00
Chris Lattner
1b2941f49d start dialing back some of the arbitrariness with our overload notes,
producing them in more cases.



Swift SVN r30081
2015-07-10 19:30:20 +00:00
Chris Lattner
cd6715b7d0 start performing type candidate matching based on the independently type checked
argument list for a CallExpr instead of matching a gang of typevartypes against them.

This allows us to produce better matches in some cases.


Swift SVN r30065
2015-07-10 06:20:17 +00:00
Chris Lattner
63f99a486c Move CallExpr diagnostics over to the same overload candidate diagnosis
facilities used by operators etc.  This required a bunch of changes to make
the diagnostics changes strictly an improvement:

  - Teach the new path about calls to TypeExprs.
  - Teach evaluateCloseness some simple things about varargs.
  - Make the generic diagnosis logic produce a better error when there is 
    exactly one match.

Overall, the resultant diagnostics are a step forward: we now produce candidate
set notes more uniformly, and the messages about some existing ones are 
more specific.  This is just another stepping stone towards progress though.



Swift SVN r30057
2015-07-10 04:26:42 +00:00
Chris Lattner
acecd187a3 fix <rdar://problem/21553065> Spurious diagnostic: '_' can only appear in a pattern or on the left side of an assignment
... by reimplementing the DiscardAssignmentExpr checker in MiscDiagnostics 
instead of being in CSApply (which gets run on partial expression ASTs).

Also, when type checking and salvaging an expression fails, do not generate 
structural diagnostics in addition to the type checker diagnostics, they are 
just noise.



Swift SVN r29937
2015-07-07 05:52:17 +00:00
David Farler
438119d558 Fold ExtensibleCollectionType into RangeRaplaceableCollectionType
ExtensibleCollectionType's operations can all be represented by the
primitive range replacement operation, so fold it into
RangeReplaceableCollectionType.

In addition, provide default implementations of
RangeReplaceableCollectionType's methods.

- New tests added for combinations of (static, generic) calls and
  (default, custom) implementations.
- Mark free Swift functions as unavailable with a message to direct the
  developer to the protocol methods.
- Mark ExtensibleCollectionType as available with a message added to
  direct the developer to the right protocol.

rdar://problem/18220295

Swift SVN r29857
2015-07-01 22:33:04 +00:00
Chris Lattner
add4deef92 add special diagnostics handling for ParenExpr: without this, we would handle
them with diagnoseGeneralFailure() which would miss out on the common cases
where the subexpr of the ParenExpr is the issue.

For example, before we would produce:

t.swift:8:8: error: could not find an overload for '&' that accepts the supplied arguments
if !(x & 4.0) {}
    ~~~^~~~~~

now we produce:

t.swift:8:6: error: binary operator '&' cannot be applied to operands of type 'Int' and 'Double'
if !(x & 4.0) {}
     ^
t.swift:8:6: note: overloads for '&' exist with these partially matching parameter lists: (Int, Int)
if !(x & 4.0) {}
     ^

also, remove some special handling for lvalues and inout from overload
diagnostics, which can't matter anymore.


Swift SVN r29661
2015-06-25 06:30:27 +00:00
Dmitri Hrybenko
51e236c609 stdlib: rename Array's generic parameter from T to Element
Same for ArraySlice and ContiguousArray.

Part of rdar://21429126

Swift SVN r29618
2015-06-24 20:41:49 +00:00
Chris Lattner
3e3ff0bba7 add improved diagnostics for another bad return path. CSDiag is a maze to me,
this really fixes the case in rdar://14096697.


Swift SVN r29566
2015-06-23 06:09:07 +00:00
Chris Lattner
f25e14ecc9 fix <rdar://problem/14096697> QoI: Diagnostics for trying to return values from void functions
by propagating the 'is return expr' bit more carefully in sequence folding, and by
adding another path for handling the return diagnostics better.

This probably improves a number of cases where we complain about "this argument list 
is invalid" when the call is in the context of a return.



Swift SVN r29565
2015-06-23 05:53:24 +00:00
Chris Willmore
94805ba808 When type-checking ExprPattern, set MatchExpr even when typechecking
failed so the verifier knows to walk it instead of SubExpr.

<rdar://problem/20770032> Pattern matching ranges against tuples crashes the compiler

Swift SVN r29525
2015-06-19 21:39:01 +00:00
Chris Willmore
0e05470e5f Take care to preserve parentheses when opening generic types. Consider
lvalues when compiling list of partial-match overloads in diagnosis.
(This is a reapplication of commits r29462 and r29469.)

Also, fix the following tests:

    stdlib/FixedPointDiagnostics.swift.gyb
    stdlib/NumericDiagnostics.swift.gyb

<rdar://problem/17875634> can't append to array of tuples

Swift SVN r29493
2015-06-18 18:58:49 +00:00
Mark Lacey
f7ce9aab07 Revert "Take care to preserve parentheses when opening generic types. Consider lvalues when compiling list of partial-match overloads in diagnosis."
This reverts commit r29462 because it looks like it breaks the following
tests:
    Swift :: stdlib/FixedPointDiagnostics.swift.gyb
    Swift :: stdlib/NumericDiagnostics.swift.gyb

Swift SVN r29484
2015-06-18 06:51:34 +00:00
Mark Lacey
f3a86f6d57 Revert "Make sure the generic and non-generic argument acceptance semantics are the same, re 17875634."
This reverts commit r29469 because it conflicts with reverting r29462,
and it looks like that broke some tests.

Swift SVN r29483
2015-06-18 06:51:31 +00:00
Chris Willmore
ae06188a6a Make sure the generic and non-generic argument acceptance semantics are
the same, re 17875634.

Swift SVN r29469
2015-06-17 23:18:36 +00:00
Chris Willmore
8d4f70580f Take care to preserve parentheses when opening generic types. Consider
lvalues when compiling list of partial-match overloads in diagnosis.

<rdar://problem/17875634> can't append to array of tuples

Swift SVN r29462
2015-06-17 22:59:35 +00:00
Joe Pamer
e12cc2dcc0 Account for typeExprs as arguments when diagnosing CallExpr failures. This is surprisingly common, and accounts for (rdar://problem/19750901&19471376&19615313&19686369&19823567 and likely many more dupes I've yet to dig out.)
Swift SVN r28390
2015-05-10 00:31:09 +00:00
Joe Pamer
c6b30d9d8c Prioritize generalized conversion diagnostics over generalized overload diagnostics when diagnosing an error in a return expression. (rdar://problem/19735220)
Swift SVN r28389
2015-05-10 00:31:00 +00:00
Chris Lattner
e31b915f54 fix <rdar://problem/20800015> Fix error message for invalid if-let
Emitting an error message about a pattern the user didn't write isn't awesome,
complain about the type requirements of an if/let binding specifically.


Swift SVN r28119
2015-05-04 16:36:13 +00:00
Chris Lattner
31c01eab73 Change the meaning of "if let x = foo()" back to Xcode 6.4 semantics. The compiler
includes a number of QoI things to help people write the correct code.  I will commit
the testcase for it as the next patch.

The bulk of this patch is moving the stdlib, testsuite and validation testsuite to
the new syntax.  I moved a few uses of "as" patterns back to as? expressions in the 
stdlib as well.



Swift SVN r27959
2015-04-30 04:38:13 +00:00