Commit Graph

1092 Commits

Author SHA1 Message Date
Chris Lattner
4ebb461d63 Fix: <rdar://problem/23670252> QoI: Misleading error message when assigning a value from [String : AnyObject]
This teaches SubscriptExpr diagnostics to substitute the base type of a
subscript expr through the generic argument types, resolving achetypes in
common situations to concrete types.  We previously complained:

  error: cannot subscript a value of type '[String : AnyObject]' with an index of type 'String'

which is completely wrong, we now produce the correct error:

  error: cannot assign value of type 'AnyObject?' to type 'String?'
2015-12-07 17:28:16 -08:00
Dmitri Gribenko
31598d41bf Rename GeneratorType to IteratorProtocol 2015-12-07 17:08:32 -08:00
Leo Shimonaka
70e66973ee Fix spelling error in documentation / comments / method name 2015-12-05 00:28:08 -05:00
Chris Lattner
5b1f42cab9 Generalize some code to be based on SelfApplyExpr instead of its two
derived classes, NFC.
2015-12-01 21:40:35 -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
b8c8844850 Improve UncurriedCandidate::dump to include the type information for a candidate,
NFC since this is just a debugging aid.
2015-12-01 16:19:05 -08:00
Chris Lattner
c7c180f8d8 Fix <rdar://problem/23700031> QoI: Terrible diagnostic in tuple assignment
When inferring a contextual type for the input expression to an assignment,
use getRValueType() to strip lvalues from tuple types in recursive positions,
this allows us to produce a sensible diagnostic of:

error: binary operator '%' cannot be applied to two 'T' operands

instead of:

error: cannot assign value of type 'T' to type '@lvalue _'

because we don't have a weird lvalue type in the way.
2015-11-30 20:54:14 -08:00
Chris Lattner
0958f67c19 Fix <rdar://problem/22058555> QoI: unhelpful type error "cannot invoke 'withCString' with an argument list of type '((_) -> _)'"
The original issue has long since been fixed, but we were now producing:
error: cannot subscript a value of type 'UnsafePointer<Int8>'

which is pretty obviously wrong.  The problem is that when ranking subscript
decl candidates, CSDiags was using TC.isConvertibleTo to evaluate whether the
actual base type is compatible with the base type of a subscript decl.  This
was failing when the base was generic, because the logic isn't opening
archetypes.  Instead of incorrectly deciding that they are incompatible, just
decide we don't know if an archetype is present.  This allows us to generate
good errors in situation like this.
2015-11-29 22:31:08 -08:00
Chris Lattner
f4fc002fe2 Fix <rdar://problem/23433271> Swift compiler segfault in failure diagnosis
A crash in CSDiag that happened when we were unconditionally looking at the
getter of a subscript.  This failed on UnsafeMutablePointer because it only
has addressors, not getter/setters.
2015-11-29 22:09:58 -08:00
Nadav Rotem
97a793b04f Fix a warning in CSDiag.
The function return value is bool but we were returning a nullptr.
2015-11-29 08:10:45 -08:00
Chris Lattner
714dcd5ba5 Fix <rdar://problem/23202128> QoI: Poor diagnostic with let vs. var passed to C function
This improves the error message when attempting an array to UnsafeMutablePointer
conversion but where the element type of the array is incorrect or where the array itself
is immutable.

As a bonus fix, this dramatically improves the diagnostic when you pass "&array" to
a function that takes an UnsafePointer.  We decided to not require & in this case, so
we can just provide a nice fixit to rip it off when this common error happens.
2015-11-28 22:13:49 -08:00
Chris Lattner
568ed0420e fix <rdar://problem/23271868> QoI: Non-descriptive error message in Swift when passing immutable unsafe pointer instead of mutable
Making diagnostics more specific when using & in a call argument as part of an
Unsafe*Pointer conversion.
2015-11-28 21:38:56 -08:00
Chris Lattner
df9d57219e Fix <rdar://problem/22602657> better diagnostics for closures w/o "in" clause
improving the message when too-many arguments are used in a closureexpr with
a known contextual type.
2015-11-17 21:31:53 -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
6bbcdd0322 Start keeping track of the argument that failed when filtering a candidate
produces a list that differs in a consistent argument.  NFC since this isn't
used yet.
2015-11-16 23:09:24 -08:00
Chris Lattner
3cbd67dbb3 Refactor handling of 'hasTrailingClosure' in CalleeCandidateInfo. This is a
statically determinable property of a given call site, so pass it into the
ctor for CalleeCandidateInfo instead of computing it when filtering.  NFC.
2015-11-16 22:22:08 -08:00
Ben Langmuir
50cc79c7f2 Fix crash code-completing after 1 + [0]
A literal in a sub-expression of the right-most expression in a sequence
could accidentally still have an error-type when going through CSApply.

rdar://problem/23488528
2015-11-16 11:35:13 -08:00
Chris Lattner
80abe99ea3 remove the OutOfOrderArgument failure mode now that CSDiag subsumes it. 2015-11-15 23:15:23 -08:00
Chris Lattner
b7b6af9c95 Improve some incorrect label diagnostics, and pull the logic for it into CSDiag's core.
This also rearranges the logic for diagnosing faulty ApplyExprs to group the logic
for a single candidate together in one place.  Nothing really earth shattering here,
just yak shaving.
2015-11-15 23:03:08 -08:00
Chris Lattner
5b433cc06d Rearrange a bunch of code to make way for progress, NFC. 2015-11-15 22:03:23 -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
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
2f04cb13f1 Fix <rdar://problem/23550816> QoI: Poor diagnostic in argument list of "print" (varargs related)
When passing a contextual type to a call, if we have a scalar element
initializing a varargs parameter list, we need to use the varargs element type
contextually.  Fixing this improves some confusing diagnostics.
2015-11-15 15:13:21 -08:00
Chris Lattner
6f931ca8c0 Add some debugging dump() support, NFC. 2015-11-15 14:51:19 -08:00
Chris Lattner
13792f915e Fix <rdar://problem/23086402> Swift compiler crash in CSDiag 2015-11-15 14:13:23 -08:00
Dmitri Hrybenko
2e51d23875 Un-ifdef object literals
Swift SVN r32880
2015-10-25 07:50:53 +00:00
Chris Willmore
6d7d45a0a4 When clearing type data for failure diagnosis, reset the lvalue access kind too.
That way, re-typechecking doesn't complain about the lvalue access kind
bit already having been set.

<rdar://problem/23185177> Compiler crashes in Assertion failed: ((AllowOverwrite || !E->hasLValueAccessKind()) && "l-value access kind has already been set"), function visit

Swift SVN r32854
2015-10-24 00:44:23 +00:00
David Farler
29004fa9b2 Fix -Wnull-conversion warning in diagnoseCalleeResultContextualConversionError
Swift SVN r31896
2015-09-11 17:42:41 +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
f8c6e46e03 remove the Failure::IsNotOptional failure mode, as CSDiags does a better job
of providing contextual diagnostics (e.g. producing the warning in 
Constraints/dynamic_lookup.swift).  This drops a specific diagnostic about
force casting the result of as! which was added in the Swift 1.2 timeframe
to explain the change in cast semantics.  Now that as! has been around for
a long time, it is more confusing than helpful.



Swift SVN r31887
2015-09-11 04:40:13 +00:00
Chris Lattner
ebe67f30ea fix <rdar://problem/22490787> QoI: Poor error message iterating over property with non-sequence type that defines a Generator type alias
which is a case where the only problem lurking in the constraint system is a disjunction
between two impossible to solve conversion constraints.  Arbitrarily pick the first one
so that we complain about *something*, instead of just calling the reference to path 
ambiguous.


Swift SVN r31886
2015-09-11 04:16:47 +00:00
Jordan Rose
dbe1230d31 When an assignment fails, check isSettable instead of asking for a setter.
Otherwise, we'll hit an assertion failure (or produce the wrong message)
when a property has an addressor instead of a getter and setter.

rdar://problem/22363304

Swift SVN r31865
2015-09-10 22:33:48 +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
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
a171e29120 Reimplement evaluateCloseness in terms of the existing
decomposeArgParamType/matchCallArguments logic used by the rest of
sema, instead of doing its own home grown (and really bad) argument
matching stuff.

NFC since the later argument remapping logic doesn't make use of the same
approach yet, and we're not doing anything with CC_ArgumentLabelMismatch
in visitApplyExpr.


Swift SVN r31759
2015-09-08 05:52:25 +00:00
Chris Lattner
4526cf7716 fix a few validation test failures introduced by r31745
Swift SVN r31750
2015-09-07 23:30:11 +00:00
Chris Lattner
3a50dfa56c improve the diagnostic a bit around non-lvalue exprs that are not lvalues because
of the conversions involved.


Swift SVN r31748
2015-09-07 23:22:49 +00:00
Chris Lattner
b598e8381f don't print @lvalue in a diagnostic.
Swift SVN r31746
2015-09-07 22:51:37 +00:00
Chris Lattner
6d87ec37cf Merge handling of all ApplyExprs into a single visitApplyExpr routine, instead of
handling unary and binary ops specially.  NFC on the testsuite with the other stuff
that went in.


Swift SVN r31745
2015-09-07 22:50:24 +00:00
Chris Lattner
c9b6ece16c add a somewhat gross hack to CSDiag's to tell it to not retypecheck
OverloadedDeclRefExpr or OverloadedMemberRefExpr when there is no
contextual type information available.  The problem is that CSRanking
will take a look at the various solutions formed by picking each member
of the set, and will arbitrarily rank them against each other based on
how specific the candidates are.  The problem with this is that the
constraints on the candidates are being resolved by UnresolvedType, which
means that we end up accidentally pruning the overload set too early.

This can lead to incorrect diagnostics that *should* have been ambiguity
diagnostics, such as the example in TypeCoercion/overload_noncall.swift.
It also is causing me other grief as I'm trying to make the call analysis
diagnostics more specific and the lack of the proper candidates is 
triggering badness.

The actual change to the testsuite here is minor, but not all good.  It will
be re-won by later changes.



Swift SVN r31744
2015-09-07 22:41:10 +00:00
Chris Lattner
ce7bcc3bea One second thought: keep the interface to computeTupleShuffle consistent:
change its implementation to take a list of TupleTypeElt for both the
from/to tuple type, but provider a convenience wrapper that takes the
from/to tuple type as TupleType's.


Swift SVN r31733
2015-09-06 22:23:25 +00:00
Chris Lattner
21acbd42a0 refactor constraints::computeTupleShuffle() to take its first tuple as
an exploded list of elements, which is more convenient for at least one
caller.  NFC.



Swift SVN r31731
2015-09-06 22:17:22 +00:00
Chris Lattner
bab9b62c87 reimplement the "function produces expected type 'XYZ'; did you mean to call it with '()'?"
fixit hint in CSDiags instead of being a FixKind.  This resolves a number of issues with
it, particularly that it didn't actually check to see if the function in question takes
a () argument or not.  

This fixes:
<rdar://problem/21692808> QoI: Incorrect 'add ()' fixit with trailing closure

among other issues.



Swift SVN r31728
2015-09-06 20:41:21 +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
e7a86e00b9 Finish up the last bit of work I plan on
<rdar://problem/22333281> QoI: improve diagnostic when contextual type of closure disagrees with arguments

In the common case where someone doesn't care about the argument 
list to a closure, we now generate a tailored error message with a 
fixit to introduce the necessary "_,_ in " nonsense at the start 
of the closure.  IMO ideally we wouldn't require this, but until we
fix that type checker issue, we should at least give people the
obvious fix.


Swift SVN r31720
2015-09-05 22:37:55 +00:00
Chris Lattner
1439bba142 move the special case closure diagnostics to CSDiag out of TypeCheckPattern,
since the logic is specific to it and about to get more-so. NFC.


Swift SVN r31719
2015-09-05 22:13:49 +00:00
Chris Lattner
44b35a85f8 remove a bunch more Failure conditions that CSDiags ignores.
Swift SVN r31718
2015-09-05 21:53:08 +00:00
Chris Lattner
86b47b8186 remove the TupleSizeMismatch failure mode and diagnose the problem in the mainline
expr diagnosis stuff, giving us much better diagnostics on the cases in
expr/closure/closures.swift.  This is part #2 of resolving
<rdar://problem/22333281> QoI: improve diagnostic when contextual type of closure disagrees with arguments



Swift SVN r31717
2015-09-05 21:38:06 +00:00
Chris Lattner
877fa0bf84 remove some dead "Failure" cases that CSDiags already ignores because it handles them
better in its expression-driven system.


Swift SVN r31716
2015-09-05 21:09:02 +00:00
Chris Lattner
364cdc37ea fix <rdar://problem/22308330> QoI: CSDiags doesn't handle array -> pointer impl conversions well
Swift SVN r31712
2015-09-05 05:21:55 +00:00