Commit Graph

20 Commits

Author SHA1 Message Date
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
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
d91f5861d2 Change diagnoseFailure() for unavoidable failures to stop doing anything with
conversion failures, making a bunch of diagnostics more specific and useful.

UnavoidableFailures can be very helpful, but they can also be the first constraint
failure that the system happened to come across... which is not always the most
meaningful one.  CSDiag's expr processing machinery has a generally better way of
narrowing down which ones make the most sense.


Swift SVN r30647
2015-07-26 04:09:34 +00:00
Chris Lattner
0001dc27bb remove support for the experiemental "character literals" feature.
Swift SVN r30509
2015-07-22 22:35:19 +00:00
Chris Lattner
5cc32383dd Teach the diagnostics machinery another special case for
RebindSelfInConstructorExpr, which gets issues related to
self.init and super.init onto the CallExpr best path, instead
of in the generic overload constraint failure morass.


Swift SVN r30067
2015-07-10 06:44:47 +00:00
Chris Lattner
6c980c033a When complaining about overload failures involving init methods, print the class name,
satisfying the request of <rdar://problem/20409366> Diagnostics for init calls should print the class name

I'm keeping that radar open though, because the case in it should get better still.



Swift SVN r30029
2015-07-09 18:02:44 +00:00
Chris Lattner
be906493ac Teach CSDiag how to recursively walk into an arbitrary expression, to produce
its diagnostics in post-order.  Notably, this picks up support for if-expr, which
gives up much better diagnostics in ternary operators.  For example, rdar://17224804
used to produce:

error: could not find an overload for '<=' that accepts the supplied arguments
var monthString = (monthNumber <= 9) ? ("0" + monthNumber) : String(monthNumber)
                  ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

now we produce:

 error: binary operator '+' cannot be applied to operands of type 'String' and 'Int'
var monthString = (monthNumber <= 9) ? ("0" + monthNumber) : String(monthNumber)
                                        ~~~ ^ ~~~~~~~~~~~
 note: overloads for '+' exist with these partially matching parameter lists: (Int, Int), (String, String), (UnsafeMutablePointer<Memory>, Int), (UnsafePointer<Memory>, Int)
var monthString = (monthNumber <= 9) ? ("0" + monthNumber) : String(monthNumber)
                                        ^

which is the correct diagnostic.  While I'm at it, improve the location info for this
binary operator diagnostic to point to the right spot (the operator) and highlight
the LHS/RHS of the operator.



Swift SVN r29774
2015-06-28 17:53:36 +00:00
Joe Groff
1479a56ab3 Sema: Move semantic constraints on super/self.init out of the parser.
Instead of forcing full application of '{super,self}.init' in the parser, and installing the RebindSelf semantic expr node early, make these constraints to Sema-time checks, and parse '<expr>.init' as a regular postfix production. This is a better separation of concerns, and also opens the door to supporting 'metatype.init()' in more general expression contexts (though that part still needs some follow-up sema work).

Swift SVN r29343
2015-06-08 04:11:16 +00:00
Jordan Rose
fac5a83bbf Allow capturing super in explicit closures and nested functions.
The previous commit enabled this; now it's just about removing the
restriction in the parser and tightening up code completion.

Using 'super' in a closure where 'self' is captured weak or unowned still
doesn't work; the reference to 'self' within the closure is treated as
strong regardless of how it's declared. Fixing this requires a cascade of
effort, so instead I just cloned rdar://problem/19755221.

rdar://problem/14883824

Swift SVN r25065
2015-02-07 03:56:11 +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
Joe Pamer
2912159776 Improve diagnostics for expression typecheck errors
These changes make the following improvements to how we generate diagnostics for expression typecheck failure:
- Customizing a diagnostic for a specific expression kind is as easy as adding a new method to the FailureDiagnosis class,
  and does not require intimate knowledge of the constraint solver’s inner workings.
    - As part of this patch, I’ve introduced specialized diagnostics for call, binop, unop, subscript, assignment and inout
      expressions, but we can go pretty far with this.
    - This also opens up the possibility to customize diagnostics not just for the expression kind, but for the specific types
      involved as well.
- For the purpose of presenting accurate type info, partially-specialized subexpressions are individually re-typechecked
  free of any contextual types. This allows us to:
    - Properly surface subexpression errors.
    - Almost completely avoid any type variables in our diagnostics. In cases where they could not be eliminated, we now
      substitute in "_".
    - More accurately indicate the sources of errors.
- We do a much better job of diagnosing disjunction failures. (So no more nonsensical ‘UInt8’ error messages.)
- We now present reasonable error messages for overload resolution failures, informing the user of partially-matching
  parameter lists when possible.

At the very least, these changes address the following bugs:

<rdar://problem/15863738> More information needed in type-checking error messages
<rdar://problem/16306600> QoI: passing a 'let' value as an inout results in an unfriendly diagnostic
<rdar://problem/16449805> Wrong error for struct-to-protocol downcast
<rdar://problem/16699932> improve type checker diagnostic when passing Double to function taking a Float
<rdar://problem/16707914> fatal error: Can't unwrap Optional.None…Optional.swift, line 75 running Master-Detail Swift app built from template
<rdar://problem/16785829> Inout parameter fixit
<rdar://problem/16900438> We shouldn't leak the internal type placeholder
<rdar://problem/16909379> confusing type check diagnostics
<rdar://problem/16951521> Extra arguments to functions result in an unhelpful error
<rdar://problem/16971025> Two Terrible Diagnostics
<rdar://problem/17007804> $T2 in compiler error string
<rdar://problem/17027483> Terrible diagnostic
<rdar://problem/17083239> Mysterious error using find() with Foundation types
<rdar://problem/17149771> Diagnostic for closure with no inferred return value leaks type variables
<rdar://problem/17212371> Swift poorly-worded error message when overload resolution fails on return type
<rdar://problem/17236976> QoI: Swift error for incorrectly typed parameter is confusing/misleading
<rdar://problem/17304200> Wrong error for non-self-conforming protocols
<rdar://problem/17321369> better error message for inout protocols
<rdar://problem/17539380> Swift error seems wrong
<rdar://problem/17559593> Bogus locationless "treating a forced downcast to 'NSData' as optional will never produce 'nil'" warning
<rdar://problem/17567973> 32-bit error message is really far from the mark: error: missing argument for parameter 'withFont' in call
<rdar://problem/17671058> Wrong error message: "Missing argument for parameter 'completion' in call"
<rdar://problem/17704609> Float is not convertible to UInt8
<rdar://problem/17705424> Poor error reporting for passing Doubles to NSColor: extra argument 'red' in call
<rdar://problem/17743603> Swift compiler gives misleading error message in "NSLayoutConstraint.constraintsWithVisualFormat("x", options: 123, metrics: nil, views: views)"
<rdar://problem/17784167> application of operator to generic type results in odd diagnostic
<rdar://problem/17801696> Awful diagnostic trying to construct an Int when .Int is around
<rdar://problem/17863882> cannot convert the expression's type '()' to type 'Seq'
<rdar://problem/17865869> "has different argument names" diagnostic when parameter defaulted-ness differs
<rdar://problem/17937593> Unclear error message for empty array literal without type context
<rdar://problem/17943023> QoI: compiler displays wrong error when a float is provided to a Int16 parameter in init method
<rdar://problem/17951148> Improve error messages for expressions inside if statements by pre-evaluating outside the 'if'
<rdar://problem/18057815> Unhelpful Swift error message
<rdar://problem/18077468> Incorrect argument label for insertSubview(...)
<rdar://problem/18079213> 'T1' is not identical to 'T2' lacks directionality
<rdar://problem/18086470> Confusing Swift error message: error: 'T' is not convertible to 'MirrorDisposition'
<rdar://problem/18098995> QoI: Unhelpful compiler error when leaving off an & on an inout parameter
<rdar://problem/18104379> Terrible error message
<rdar://problem/18121897> unexpected low-level error on assignment to immutable value through array writeback
<rdar://problem/18123596> unexpected error on self. capture inside class method
<rdar://problem/18152074> QoI: Improve diagnostic for type mismatch in dictionary subscripting
<rdar://problem/18242160> There could be a better error message when using [] instead of [:]
<rdar://problem/18242812> 6A1021a : Type variable leaked
<rdar://problem/18331819> Unclear error message when trying to set an element of an array constant (Swift)
<rdar://problem/18414834> Bad diagnostics example
<rdar://problem/18422468> Calculation of constant value yields unexplainable error
<rdar://problem/18427217> Misleading error message makes debugging difficult
<rdar://problem/18439742> Misleading error: "cannot invoke" mentions completely unrelated types as arguments
<rdar://problem/18535804> Wrong compiler error from swift compiler
<rdar://problem/18567914> Xcode 6.1. GM, Swift, assignment from Int64 to NSNumber. Warning shown as problem with UInt8
<rdar://problem/18784027> Negating Int? Yields Float
<rdar://problem/17691565> attempt to modify a 'let' variable with ++ results in typecheck error about @lvalue Float
<rdar://problem/17164001> "++" on let value could give a better error message

Swift SVN r23782
2014-12-08 21:56:47 +00:00
Argyrios Kyrtzidis
628567bfe5 [Frontend] Make it erroneous if no frontend action is specified when invoking the frontend, and update tests.
Swift SVN r21584
2014-08-29 19:17:37 +00:00
Doug Gregor
91fb509558 Outside function input types, ban single-element tuples with a label and variadic tuples.
Addresses <rdar://problem/15456156> and <rdar://problem/17466857>, and
sets us up for more simplification in the type system.


Swift SVN r20995
2014-08-04 04:43:32 +00:00
Joe Pamer
a314db950e Remove another point of non-determinism while tracking failed constraints, and use this as an opportunity to improve certain diagnostics. (rdar://problem/16808495)
Swift SVN r19244
2014-06-26 19:48:48 +00:00
Ted Kremenek
7da31bdfdd Disable parsing of single quoted character literals, enabling under a flag.
I didn't want to rip this logic out wholesale.  There is a possibility
the character lexing can be reborn/revisited later, and
disabling it in the parser was easy.

Swift SVN r18102
2014-05-15 07:05:59 +00:00
Ted Kremenek
fad874708e Adjust test cases.
Swift SVN r17964
2014-05-12 22:01:52 +00:00
Joe Groff
0a16e6e1f6 Sema: super.constructor in the constraint checker.
Set up constraints and solution application for SuperConstructorRefCallExpr.

Swift SVN r3916
2013-01-31 23:17:32 +00:00