Commit Graph

22 Commits

Author SHA1 Message Date
Pavel Yaskevich
ec3b783380 [Diagnostics] Improve diagnostic for invalid conversion to AnyObject 2020-01-29 00:37:39 -08:00
Pavel Yaskevich
ebdb5c7776 [ConstraintSystem] Improve handling of ambiguities related to fixes
Solutions passed to `diagnoseAmbiguityWithFixes` aren't filtered
so we need to remove all of the solutions with the score worse
than overall "best". Also logic has to account for some fixes being
"warnings".
2019-12-03 12:07:16 -08:00
Pavel Yaskevich
58329e0c27 Revert "[Diagnostics][Qol] SR-11295 Emit diagnostics for same type coercion. " 2019-10-25 01:05:07 -07:00
Luciano Almeida
86ca3454d6 Fixing warning UnnecessaryCoercion tests 2019-10-21 23:11:21 -03:00
David Farler
b7d17b25ba Rename -parse flag to -typecheck
A parse-only option is needed for parse performance tracking and the
current option also includes semantic analysis.
2016-11-28 10:50:55 -08:00
Jordan Rose
bc83940301 Make pointer nullability explicit using Optional.
Implements SE-0055: https://github.com/apple/swift-evolution/blob/master/proposals/0055-optional-unsafe-pointers.md

- Add NULL as an extra inhabitant of Builtin.RawPointer (currently
  hardcoded to 0 rather than being target-dependent).
- Import non-object pointers as Optional/IUO when nullable/null_unspecified
  (like everything else).
- Change the type checker's *-to-pointer conversions to handle a layer of
  optional.
- Use 'AutoreleasingUnsafeMutablePointer<NSError?>?' as the type of error
  parameters exported to Objective-C.
- Drop NilLiteralConvertible conformance for all pointer types.
- Update the standard library and then all the tests.

I've decided to leave this commit only updating existing tests; any new
tests will come in the following commits. (That may mean some additional
implementation work to follow.)

The other major piece that's missing here is migration. I'm hoping we get
a lot of that with Swift 1.1's work for optional object references, but
I still need to investigate.
2016-04-11 20:06:38 -07:00
Maxim Moiseev
7372e9e045 COpaquePointer => OpaquePointer 2015-12-07 16:52:45 -08:00
Chris Lattner
b660cb3c8e Enhance the general parameter list matching logic in CSDiags to know about
argument list mismatches, and diagnose them with a very specific error when
they occur in member lookups.  This fixes
<rdar://problem/22356434> QoI: Missing diagnostic for invalid arguments passed to enum case constructor

where before we'd produce:

ee.swift:5:16: error: type of expression is ambiguous without more context
let list: E = .C(wrongLabel: 0)
              ~^~~~~~~~~~~~~~~~

now we produce:

ee.swift:1:17: error: incorrect argument label in call (have 'wrongLabel:', expected 'label:')
let list: E = .C(wrongLabel: 0)
                ^~~~~~~~~~~
                 label

I think that unresolved member exprs now get good diagnostics in all cases that they have
a contextual type, but of course there are lots more cases where we're not getting a 
contextual type.



Swift SVN r31402
2015-08-22 04:46:49 +00:00
Chris Lattner
9d9b8aaf35 move protocol conformance errors away from being diagnosed as a Failure, instead
putting it into the expr diagnostics path, allowing more contextual messages.


Swift SVN r30920
2015-08-01 18:31:59 +00:00
Chris Lattner
6a27182712 two unrelated changes:
- Have DiagnosticEngine produce "aka" annotations for sugared types.
 - Fix the "optional type '@lvalue C?' cannot be used as a boolean; test for '!= nil' instead"
   diagnostic to stop printing @lvalue noise.

This addresses:
<rdar://problem/19036351> QoI: Print minimally-desugared 'aka' types like Clang does



Swift SVN r30587
2015-07-24 20:22:20 +00:00
Dmitri Hrybenko
f5de8757e4 stdlib: remove Word and UWord
These types are leftovers from the early pre-1.0 times when Int and UInt
were always 64-bit on all platforms.  They serve no useful purpose
today.  Int and UInt are defined to be word-sized and should be used
instead.

rdar://18693488

Swift SVN r30564
2015-07-24 05:01:32 +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
f2a40da3ed fix FailureDiagnosis::collectCalleeCandidateInfo to look at the entire
disjunction candidate set for a constraint that fails to match, not just
a single Bind within it.  This eliminates the arbitrary nature of picking
one match, allowing us to diagnose the entire candidate set.

This exposed that we were trying to do argument matching of 'self' against
the partially curried arguments.  Adjust the hack we have for that a bit to
make things work, but there are bigger problems for argument matching that
will need to be addressed.


Swift SVN r30064
2015-07-10 06:03:37 +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
183c279889 change visitAssignExpr to only get retypecheck one side of its subexpr at a time,
and change it to get the source before the destination.  This is the right thing to
do and also conveniently works around a bogus:
  '_' can only appear in a pattern or on the left side of an assignment

diagnostic.

This needs to be fixed in a more systematic way to cover other cases, but this change
is the right thing to do independently of that.



Swift SVN r29929
2015-07-07 01:05:15 +00:00
Arnold Schwaighofer
f7771859d8 Rename the optimize_test feature to executable_test and document that feature.
Swift SVN r29213
2015-06-01 23:44:13 +00:00
Arnold Schwaighofer
3643c614a3 Run tests in optimize test modes
This runs all files that have a target-build-swift or target-run-stdlib-swift
RUN line in optimize test mode.

Swift SVN r29206
2015-06-01 21:23:31 +00:00
Chris Lattner
e4b6afb9ae Start moving the testsuite to the "_ = foo()" idiom for evaluating an
expression but ignoring its value.  This is the right canonical way to do
this.  NFC, just testsuite changes.



Swift SVN r28638
2015-05-15 20:15:54 +00:00
Chris Willmore
6c21a6414a <rdar://problem/19421148> Calling init with a missing label doesn't provide a descriptive error when overloaded inits differ only by label
Swift SVN r24624
2015-01-22 01:12:45 +00:00
Joe Pamer
dc338c2a71 Update wording of some new diagnostics.
Swift SVN r23783
2014-12-08 21:56:52 +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
Jordan Rose
c782dc939f [ClangImporter] FSEventStreamRef is not a CF object.
Nor is ConstFSEventStreamRef.

Unfortunately, they both get bridged to COpaquePointer, so they're not
constructible from one another--they're identical.

rdar://problem/18112747

Swift SVN r21546
2014-08-28 22:14:47 +00:00