Commit Graph

21 Commits

Author SHA1 Message Date
Jordan Rose
fef3a3768c Use access scopes instead of adjustAccessLevelForProtocolExtension
This gets adjustAccessLevelForProtocolExtension, a hack of sorts to
begin with, out of ValueDecl's general API, and down to a helper for
isAccessibleFrom and isSetterAccessibleFrom. (The only reason these
two don't go through access scopes is as an optimization.)
2018-07-23 16:36:16 -07:00
Slava Pestov
a5579d1cff AST: Plug a hole in access control checking
A protocol extension of a private protocol can define internal
or public members. We should not be able to find these members
from another file or module if an internal or public type
conforms to the protocol.

Fixes <rdar://problem/21380336>.
2018-04-05 23:24:48 -07: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
Manav Gabhawala
7928140f79 [SE-0046] Implements consistent function parameter labels by discarding extraneous parameter names and adding _ where necessary 2016-04-06 20:21:58 -04:00
Daniel Duan
780b58a9a5 [Parser] update tests for 'inout' syntax adjustment 2016-02-26 01:33:22 -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
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
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
Dmitri Hrybenko
f46f16ae82 stdlib: implement new print() API
rdar://20775683

Swift SVN r28309
2015-05-08 01:37:59 +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
43c7334abc fix two QoI issues:
- <rdar://problem/16306600> QoI: passing a 'let' value as an inout results in an unfriendly diagnostic
 - <rdar://problem/16927246> provide a fixit to change "let" to "var" if needing to mutate a variable

We now refer to an inout argument as such, e.g.:

t.swift:7:9: error: cannot pass 'let' value 'a' as inout argument
  swap(&a, &b)
        ^

we also produce a note with a fixit to rewrite let->var in trivial cases where mutation is
being assed for, e.g.:

t.swift:3:3: note: change 'let' to 'var' to make it mutable
  let a = 42
  ^~~
  var

The note is produced by both Sema and DI.



Swift SVN r27774
2015-04-26 21:51:50 +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
Jordan Rose
f18dc4101f [Accessibility] Honor private(set) with -enable-access-control.
...for both variables and subscripts.

Swift SVN r19549
2014-07-04 01:53:49 +00:00