Commit Graph

55 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
a7339e67ac Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-22 11:36:07 -08:00
Chris Lattner
82e5c0c592 Update various tests to stop using ++/-- 2015-12-21 18:07:37 -08:00
Dmitri Gribenko
3d0ad16094 Unsafe[Mutable]Pointer.memory => .pointee 2015-12-16 15:50:31 -08:00
Chris Lattner
58fbd1b588 Add some testcases for some radars that are fixed on master. 2015-12-09 16:39:20 -08:00
gregomni
83a5e2cd37 Fix for SR-7
Add check for inout type getting set on DeclRef, diagnose missing
ampersand if so. Also added verifier that DeclRefs are never inout.
Added test.
2015-12-08 08:51:18 -08:00
David Farler
93b6962478 Warn when using 'var' bindings in function parameters
These will no longer be allowed in a future Swift release.

rdar://problem/23172698
2015-11-03 17:24:20 -08: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
7ad6eaad07 the previous patch improved 22308291 enough to consider it done.
Swift SVN r31697
2015-09-04 22:35:42 +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
712d3447ce improve some diagnostics around inout expr.
Swift SVN r31415
2015-08-22 22:29:14 +00:00
Chris Lattner
248727780f Now that enough yaks are cleanly shaven, completely reimplement how
we process contextual constraints when producing diagnostic.  Formerly,
we would aggressively drop contextual type information on the floor under
the idea that it would reduce constraints on the system and make it more
likely to be solvable.  However, this also has the downside of introducing
ambiguity into the system, and some expr nodes (notably closures) cannot
usually be solved without that contextual information.

In the new model, expr diagnostics are expected to handle the fact that
contextual information may be present, and bail out without diagnosing an
error if that is the case.  This gets us more information into closures,
allowing more specific return type information, e.g. in the case in
test/expr/closure/closures.swift.

This approach also produces more correct diagnostics in a bunch of other
cases as well, e.g.:

-  var c = [:]  // expected-error {{type '[_ : _]' does not conform to protocol 'DictionaryLiteralConvertible'}} 
+  var c = [:]  // expected-error {{expression type '[_ : _]' is ambiguous without more context}}

and the examples in test/stmt/foreach.swift, test/expr/cast/as_coerce.swift,
test/expr/cast/array_iteration.swift, etc.

That said, this another two steps forward, one back thing.  Because we
don't handle propagating sametype constraints from results of calls to their
arguments, we regress a couple of (admittedly weird) cases.  This is now 
tracked by:
<rdar://problem/22333090> QoI: Propagate contextual information in a call to operands

There is also the one-off narrow case tracked by:
<rdar://problem/22333281> QoI: improve diagnostic when contextual type of closure disagrees with arguments



Swift SVN r31319
2015-08-18 23:55:02 +00:00
Chris Lattner
6c3976061c If a contextual type is available when type checking collection literals, use it to
produce specific diagnostics about individual elements being incorrect instead of
complaining about the whole thing in aggregate.

This improves diagnostics immediately, but is also important to unblock future progress.



Swift SVN r31264
2015-08-17 16:41:55 +00:00
Chris Lattner
b6206ab418 add fixit checks to various type checker testcases
Swift SVN r31004
2015-08-04 20:30:54 +00:00
Chris Lattner
dcfc6180cf improve QoI of inout argument failures, and strip some single element tuple labels.
Swift SVN r30908
2015-08-01 05:20:23 +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
f2746eaf7b Add inout expr validation to the SyntacticUseRestrictions checker
in MiscDiagnostics, allowing us to correctly and consistently reject 
InOutExprs that do not appear in argument contexts.


Swift SVN r30746
2015-07-29 01:02:46 +00:00
Slava Pestov
6256158eb7 Sema: Fixes for stored let property access from constructor
isSettable() returns true for these, but they don't have a setter.
Tread carefully around them.

Fixes <rdar://problem/21877598> and <rdar://problem/21933630>.

Swift SVN r30631
2015-07-25 19:55:00 +00:00
Chris Lattner
107282297f two changes:
1) Teach resolveImmutableBase about SubscriptExprs that have 
resolved the decl that they are referring to.  This fixes case where we'd
generate an imprecise diagnostic because we weren't able to find the
result in the ResolvedOverloadSet list (which is because CSApply rewrite
it to a different expr node and the locator can't find it).

2) Change FailureDiagnosis::typeCheckIndependentSubExpression to have a
   blacklist of expressions that aren't recursed into, along with rationale
   for each node kind, instead of a short white list.  This produces more
   predictable results, e.g. producing the right diagnostic in 
   ClangModules/objc_parse.swift



Swift SVN r30118
2015-07-11 21:40:18 +00:00
Chris Lattner
55bcdb9099 Reapply the fix for <rdar://problem/21369926> Malformed Swift Enums crash playground service
Completely revamp getTypeOfIndependentSubExpression, to return the subexpression produced by 
type checking instead of just a type. This is important for cases when type checking changes
the root of the AST (e.g. resolving an unresolved_dot_expr) and allows us to eliminate grungy 
and unsafe recovery code that was in place to work around this.  The last point makes the
examples in Constraints/lvalues.swift better (giving a somewhat generic error instead of an 
specific-but-incorrect error that 'z' is immutable), 

but more importantly, it fixes a class of crashers like:
 <rdar://problem/21369926> Malformed Swift Enums crash playground service 
where we'd end up with a LiteralExpr typed as Int instead of a Builtin integer type of some sort.



Swift SVN r30028
2015-07-09 17:32:59 +00:00
Chris Lattner
31facf7204 revert r29932, which is triggering a problem on the ASAN bot that I need to investigate.
Swift SVN r29978
2015-07-08 17:14:43 +00:00
Chris Lattner
e8877e9555 Several changes:
- Fix a diagnostic to not include redundant ''s around a type name.
 - Rework CleanupIllFormedExpression to be simpler and to not 
   unconditionally destroy data when it doesn't.  This makes a code 
   completion test a bit more precise.
 - Completely revamp getTypeOfIndependentSubExpression, to return the 
   subexpression produced by type checking instead of just a type.  This
   is important for cases when type checking changes the root of the AST
   (e.g. resolving an unresolved_dot_expr) and allows us to eliminate
   grungy and unsafe recovery code that was in place to work around this.

The last point makes the examples in Constraints/lvalues.swift better (giving
a somewhat generic error instead of an specific-but-incorrect error that 'z'
is immutable), but more importantly, it fixes a class of crashers like
<rdar://problem/21369926> Malformed Swift Enums crash playground service

where we'd end up with a LiteralExpr typed as Int instead of a Builtin integer
type of some sort.



Swift SVN r29932
2015-07-07 04:35:31 +00:00
Doug Gregor
54979b70a7 Remove uses of complete-unnamed function parameters from the testsuite.
Support for "func f(Int)" is going away.

Swift SVN r29608
2015-06-24 16:01:37 +00:00
Chris Lattner
d1b092ee9c change "cannot assign to variable" diagnostic to "cannot assign to value", since
in some cases the problem is that you're trying to assign to a constant, not a 
variable.


Swift SVN r28966
2015-05-23 16:12:37 +00:00
Chris Lattner
cf1cb14205 recommit 28958/28959, there was a testcase that didn't get updated correctly
but it was between the two revisions.


Swift SVN r28964
2015-05-23 15:50:16 +00:00
Ted Kremenek
b4b81ff657 Revert "merge assignments to UnresolvedDotExpr onto the common path,"
Backing out to fix the build.

Swift SVN r28959
2015-05-23 07:55:07 +00:00
Ted Kremenek
381eb52207 Revert "Further consolidate mutation code, this time for DeclRefExprs. With that"
Backing out to fix th build.

Swift SVN r28958
2015-05-23 07:55:04 +00:00
Chris Lattner
291d7eaad7 Further consolidate mutation code, this time for DeclRefExprs. With that
done, the rest of the infrastructure is all common and can be simplified.  This
leaves us with a quite small and maintainable subsystem for diagnosing these
kinds of problems.

 include/swift/AST/DiagnosticsSema.def |   28 ++-----
 lib/Sema/CSDiag.cpp                   |  132 ++++++++++------------------------
 2 files changed, 48 insertions(+), 112 deletions(-)




Swift SVN r28957
2015-05-23 05:49:19 +00:00
Chris Lattner
3b64718b89 merge assignments to UnresolvedDotExpr onto the common path,
this is neutral w.r.t. diagnostics quality, but deletes a ton
of code:

 include/swift/AST/DiagnosticsSema.def |   21 ++---------
 lib/Sema/CSDiag.cpp                   |   64 ++--------------------------------
 2 files changed, 9 insertions(+), 76 deletions(-)



Swift SVN r28956
2015-05-23 05:18:59 +00:00
Chris Lattner
d5f68b478f Teach the recursive part of the diagnostics to handle the various things
that make vardecls and subscripts immutable.  This makes the indirect cases
a lot more specific ("this is a get-only property" instead of "this is 
immutable") and allows us to consolidate a bunch of code:

 2 files changed, 45 insertions(+), 119 deletions(-)




Swift SVN r28954
2015-05-23 04:53:08 +00:00
Chris Lattner
585cf17b67 don't use the term "r-value" in a diagnostic, use immutable value. Thanks to Jordan for pointing this out.
Swift SVN r28953
2015-05-23 04:10:25 +00:00
Chris Lattner
f31c58d8fd unify the constraint solver path for assignment lvalue failure with
the CSGen path for assignment lvalue failure.  No significant win other
than simplifcation.


Swift SVN r28942
2015-05-23 01:26:12 +00:00
Chris Lattner
7d881f8440 - Switch "&x", "++x" and "x+=1" onto the new style mutability diagnostics,
which tell you what the problem is, not just that you have one.
- Enhance diagnostics to be more specific about function calls producing 
  rvalues.



Swift SVN r28939
2015-05-23 00:17:12 +00:00
Chris Lattner
8853d19c2b Dramatically improve the diagnostics when a store is invalid, by taking
into account accesibility, assignments to self in a non-mutating
method (consistently), recursive components of an lvalue that makes it 
non-settable, etc.  Now we tell you what the *problem* was, instead of
just whining.

This fixes:
<rdar://problem/19370429> QoI: fixit to add "mutating" when assigning to a member of self in a struct
<rdar://problem/17632908> QoI: Modifying struct member in non-mutating function produces difficult to understand error message

in their full generality.



Swift SVN r28867
2015-05-21 05:53:36 +00:00
Chris Lattner
df19d03eb7 When diagnosing invalid assignment errors, dig into the constraint system to see
if it has already resolved a member binding of an UnresolvedDotExpr.  This allows
us to give tailored diagnostics to indicate whether the destination is not an lvalue
because the property itself was immutable or when the base is immutable.

In addition to improved diagnostics, this allows us to fixit hint "let" to "var" on
property definitions, and we can even go so far as to fixit hint insert 'mutating' on 
the enclosing func decl when self is the problem.

This fixes the non-subscript cases of:
<rdar://problem/17632908> QoI: Modifying struct member in non-mutating function produces difficult to understand error message
<rdar://problem/19370429> QoI: fixit to add "mutating" when assigning to a member of self in a struct
<rdar://problem/20234955> QoI: Error message for assigning to 'let' fields should say that the error is due to a 'let' binding

Subscript cases to follow.



Swift SVN r28854
2015-05-20 22:18:52 +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 Lattner
0b5c1125e4 improve and consistify diagnostics for non-lvalue inout arguments.
Swift SVN r27795
2015-04-27 01:05:29 +00:00
Chris Lattner
9f36074698 fix <rdar://problem/19711233> QoI: poor diagnostic for operator-assignment involving immutable operand
We now produce tailored diagnostics for assignment operators that are passed a non-mutable LHS,
e.g.:

t.swift:14:3: error: cannot pass 'let' value 'x' to mutating binary operator '/='
x /= 19
~ ^
t.swift:13:1: note: change 'let' to 'var' to make it mutable
let x = 42
^~~
var





Swift SVN r27780
2015-04-27 00:20:57 +00:00
Chris Willmore
9e8d4b0dbf Use isVoid() instead of isEqual(TheEmptyTupleType). Add tests for underspecification issue fixed by r25939.
<rdar://problem/19835413> Reference to value from array changed

Swift SVN r25962
2015-03-10 22:35:08 +00:00
Chris Willmore
7cbadb1d2c When UnsafeMutablePointer<$T1> has a Conversion constraint to
UnsafeMutablePointer<Void>, don't bind $T1 to Void. This fixes an
unintentional dependency on the order in which constraints are visited
by the solver.

Fix some resulting underconstrained expressions in the stdlib.

<rdar://problem/19835413> Reference to value from array changed

Swift SVN r25921
2015-03-10 10:08:38 +00:00
Dmitri Hrybenko
2d12d510f2 Lowercase the first character in compiler diagnostics for consistency
Swift SVN r24634
2015-01-22 06:19:14 +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
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
Doug Gregor
f0d03efb4c Drastically restrict the set of alternative literal types checked by the solver.
When the solver has attempted to produce a solution using the default
literal type tha has failed, dont' try every type that conforms to
that literal type. Instead, try the bridged class type (which deals
with the common AnyObject case) or one of two other options:
  - For integer literals, try the default floating point type (Double)
  - For string literals, try the standard library's AssertString (this
  is a temporary hack)

This limits exponential blow-up in cases where the literal's type
cannot be determined from context. Addresses rdar://problem/18307267.



Swift SVN r22131
2014-09-19 16:22:21 +00:00
Chris Lattner
e0b0205cd7 Remove the @assignment attribute entirely. It doesn't do anything except
enforce its own little constraints.  The type checker isn't using it for
anything, and it is just clutter.

This resolves <rdar://problem/16656024> Remove @assignment from operator implementations



Swift SVN r19960
2014-07-14 22:44:25 +00:00
Chris Lattner
8991456ff2 Switch infix/postfix/prefix to be declaration modifiers instead of attributes,
eliminating the @'s from them when used on func's.  This is progress towards
<rdar://problem/17527000> change operator declarations from "operator prefix" to "prefix operator" & make operator a keyword

This also consolidates rejection of custom operator definitions into one
place and makes it consistent, and adds postfix "?" to the list of rejected
operators.

This also changes the demangler to demangle weak/inout/postfix and related things
without the @.



Swift SVN r19929
2014-07-14 15:51:49 +00:00
Doug Gregor
ae23d3c4f7 Remove all test dependencies on __conversion.
Swift SVN r19812
2014-07-10 16:58:42 +00:00
Joe Groff
cb48fbd24b Enable pointer conversions.
Swift SVN r19274
2014-06-26 23:26:31 +00:00