Commit Graph

22 Commits

Author SHA1 Message Date
Max Moiseev
40b1a0b7e0 [stdlib] all sorts of require renamed back to precondition 2016-02-19 18:21:29 -08:00
Max Moiseev
3a3984877a Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-15 15:43:34 -08:00
Doug Gregor
42bb2528dd [Overload resolution] Prefer functions with fewer defaulted/variadic arguments.
When comparing two functions for overload resolution, break apart the
parameter lists to compare individual parameters rather than comparing
the tuples. This allows us to prefer functions with fewer arguments to
ones with more, defaulted or variadic arguments. That preference was
already encoded in the constraint optimizer, which led to some strange
behavior where the preference was expressed for function calls but not
for calls to initializers. Fixes rdar://problem/24128153.

The standard library change tweaks the anachronistic, unavailable
"print" variants somewhat. The only behavior change here is a slight
regression for cases like:

  print(a: 1, b: 2)

where we used to produce a diagnostic:

  Please wrap your tuple argument in parentheses: 'print((...))'

but we now get:

  argument labels '(a:, b:)' do not match any available overloads

However, this regression will happen at some point *anyway*, if
SE-0029 (or anything else that removes the implicit tuple splat
operation) goes through.
2016-02-05 11:41:01 -08:00
Max Moiseev
61c837209b Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-04 16:13:39 -08:00
Chris Lattner
0619e57a61 Switch the stdlib to use #file instead of __FILE__, and deprecate the __FILE__ identifiers.
This also updates the tests that would otherwise fail.
2016-02-04 15:08:31 -08:00
Alex Hoppen
b54976baba [Sema] Fix SR-590 Passing two parameters to a function that takes one argument of type Any crashes the compiler 2016-01-26 22:47:14 +01:00
Max Moiseev
f51e708a8f Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-01-04 12:25:25 -08:00
ken0nek
3ac60b13f5 Add spaces before and after closure arrow in test 2015-12-23 04:38:46 +09:00
Maxim Moiseev
f2f50d6a9d precondition => require 2015-12-16 17:16:08 -08:00
Chris Lattner
4b8ccacf63 Fix <rdar://problem/22243469> QoI: Poor error message with throws, default arguments, & overloads
and probably others.

When we're type-checking a failed ApplyExpr that has an overload set that
prevents getting a specific type to feed into the initial typechecking of
the argument list, ranking can often narrow down the list of candidates
further, to the point where there is only one candidate left or where all
candidates agree that one argument is wrong.

In this case, re-type-check the subexpr with the expected type.  In the case of
rdar://problem/22243469 we now produce:

t.swift:6:11: error: invalid conversion from throwing function of type '() throws -> ()' to non-throwing function type '() -> Void'
  process {
          ^

instead of:

t.swift:6:3: error: cannot invoke 'process' with an argument list of type '(() throws -> ())'
  process {
  ^
t.swift:6:3: note: overloads for 'process' exist with these partially matching parameter lists: (UInt, fn: () -> Void)
  process {
  ^

Which is a heck of a lot less specific.  Similarly, in the testcase from rdar://23550816, instead
of producing:

  takeTwoFuncsWithDefaults { $0 + 1 }
error: cannot invoke 'takeTwoFuncsWithDefaults' with an argument list of type '((Int -> Int)?)'
note: expected an argument list of type '(f1: (Int -> Int)?, f2: (String -> String)?)'

we now produce:
error: cannot convert value of type '_ -> Int' to expected argument type '(String -> String)?'

which is a lot closer to what we want to complain about.
2015-11-17 20:27:47 -08:00
Chris Lattner
c652c62f88 When sorting through a list of candidates in a call overload set, introduce the
notion of a "near miss" for an argument type mismatch.  This allows us to prune
the candidate set down in some cases.  For example, in the testcase in
rdar://22243469 we are able to go from:

t.swift:6:3: error: cannot invoke 'process' with an argument list of type '(() throws -> ())'
  process {
  ^
t.swift:6:3: note: overloads for 'process' exist with these partially matching parameter lists: (UInt, fn: () -> Void), (UInt)

down to:
t.swift:6:3: note: expected an argument list of type '(UInt, () -> Void)'

This paves the way for producing a better error in cases like this, but there are
other bits of weirdness that need to be untangled first.
2015-11-15 20:50:05 -08: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
adccd0a1cd Fix <rdar://problem/19962010> QoI: argument label mismatches produce not-great diagnostic
by wiring visitApplyExpr up to diagnose argument label mismatches with the existing
diagnoseArgumentLabelError mechanics.




Swift SVN r31791
2015-09-08 23:57:27 +00:00
Chris Lattner
d94674b69d some testcases for diagnostics that are still not good enough.
Swift SVN r31760
2015-09-08 05:52:42 +00:00
Chris Lattner
cbf145482a This diagnostic improved causing the validation test to fail. Instead of nuking the
error lines outright, move it to the non-validation suite.


Swift SVN r31749
2015-09-07 23:26:41 +00:00
Chris Lattner
580315d9ee fix <rdar://problem/17652759> Default arguments cause crash with tuple permutation
This just deletes some code out of matchCallArguments to make sure that CSApply
and CSSimplify do the same argument matching.  This code presumably
dated to a period of time when the stuff after it was just for error recovery,
but now we do argument reordering matching stuff after this point.


Swift SVN r28670
2015-05-17 01:12:47 +00:00
Joe Groff
c0a2994564 AST: Start printing function types with @convention instead of old attributes.
And update tests to match.

Swift SVN r27262
2015-04-13 22:51:34 +00:00
Dmitri Hrybenko
3b04d1b013 tests: reorganize tests so that they actually use the target platform
Most tests were using %swift or similar substitutions, which did not
include the target triple and SDK.  The driver was defaulting to the
host OS.  Thus, we could not run the tests when the standard library was
not built for OS X.

Swift SVN r24504
2015-01-19 06:52:49 +00:00
Chris Lattner
8c6b2b6b5f adjust testsuite to put @autoclosure on decls instead of types, and remove a
couple of soon-to-be-invalid cases.



Swift SVN r24074
2014-12-22 20:14:11 +00:00
Chris Lattner
bc481f0fe1 implement <rdar://problem/16859927> remove the underscore in "auto_closure"
autoclosure is one work, not two.



Swift SVN r20253
2014-07-21 15:23:50 +00:00
Ted Kremenek
fad874708e Adjust test cases.
Swift SVN r17964
2014-05-12 22:01:52 +00:00
Doug Gregor
d7e0e15090 Add a helper function to determine whether a particular constraint
system has been "solved", meaning that all type variables have been
bound to concrete types or are completely free. Add the solvedness of
a particular system to the debug output.

Start adding some simple test cases.



Swift SVN r2706
2012-08-22 00:26:01 +00:00