Commit Graph

19 Commits

Author SHA1 Message Date
Jordan Rose
4b87bd93f9 Tweak DiagnosticEngine's 'aka' logic to only kick in for typealiases. (#9010)
Previously we had more ad hoc logic that tried to decide if it was
worth desugaring a type based on its structure. Now we instead look
for a typealias that might actually benefit from desugaring, and if
we don't find one we won't show the 'aka' note.
2017-04-25 19:37:22 -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
Michael Ilseman
12fb0bad7b [swift-version] Allow swift-version 4 and tests
The recent @escaping on variadic argument closures back-compat fix is
the first Swift 3.0 compatibility behavior that we don't want to carry
forwards indefinitely into the future. To address this, we
version-gate the diagnostic suppression.

Makes it an official compatibility check. Creates new test directory
for compatibility testing. Allow -swift-version 4 so that we can test
it both ways.
2016-10-11 17:42:25 -07:00
Michael Ilseman
54f4103b5b [3.0 compat] Don't diagnose @escaping var-arg closures.
Var-arg closures are already escaping, so we typically want to issue
an error if @escaping is specified. To not do sure will confuse and
give a false impression on the un-annotated semantics and whether it
is needed. But, 3.0 shipped with a bug where we didn't consistently
apply the no-escape-by-default rule here, and thus it was semantically
meaningful (and needed).

In order to preserve source compatibility, albeit at the expense of
developers on versions 3.0.1 and later in the Swift 3 family, we
suppress the error if we see @escaping. Either way, this is a
relatively uncommon usage, so the confusion won't be too wide spread.
2016-10-10 16:16:41 -07:00
Rintaro Ishizaki
430a0d8459 [AST] Remove @escaping from decl attributes.
@escaping is not really a decl attribute, ever since it was introduced.
2016-10-11 02:26:13 +09:00
Michael Ilseman
19fc5f9409 [TypeCheckType] Setters are escaping by default only at top level.
We have a special case check for the no-escape-by-default rules for a
computed property setter's newValue argument, which if a closure,
obviously has to be escaping. But, we checked this by checking the
type's overall DeclContext, which unfortunately meant we also made
nested closures escaping implicitly. This fixes that to only tack on
the implicit escaping at the top level for the setter's type.
2016-09-27 09:31:45 -07:00
practicalswift
3a4ee89034 [gardening] Use consistent formatting. 2016-09-17 12:12:49 +02:00
Slava Pestov
90d6e8dce8 Sema: Variadic parameters are always @escaping and cannot be @autoclosure
A variadic parameter of function type must be @escaping -- we cannot
reason about an array of non-escaping closures, so this was a safety
hole.

Also, attempting to define an @autoclosure variadic did not produce a
diagnostic, but would fail later on if you actually tried to do
anything with it. Let's ban this completely.

Both changes are source breaking, but impact is limited to code that
was already only marginally valid.
2016-09-15 21:46:02 -07:00
Michael Ilseman
ffd3dde01c [TypeChecker] Don't double validate dict types
Prior, binding generic args in dictionary type checking would double
resolve the key and value types a second time, emitting duplicated
errors potentially. Instead, we reuse the resolved types.
2016-09-09 13:00:21 -07:00
Michael Ilseman
585716387c [noescape-by-default] Diagnostic notes for closure type arguments
Adds in helpful notes when a closure type argument is already
escaping, and thus doesn't need annotation. The common case targeted
now is Optional and IUO, which is the biggest bang for our buck
without needlessly complicating the type options.

Test cases included for the new note, and potential interactions.

In the future we'd like some kind of parent pointer, or context stack
to give better diagnostics universally. For now, we hack it by having
ImmediateOptionalTypeArgument as a special flag.
2016-09-09 13:00:21 -07:00
Michael Ilseman
c16f8919d8 [escaping] Correct diagnostic for parameter position
In situations where @escaping is used in non-function-parameter
positions, we give an incorrect diagnostic message pertaining to
function types. Instead, we should just state that this is not allowed
in non-function-parameter positions.

This includes the general message fix. Unfortunately, this does not
include more friendly messages for special cases, e.g. closure members
of aggregate and optional closures. That may be possible with more
nested type context information in TypeCheckType.
2016-09-07 15:38:20 -07:00
Michael Ilseman
97e4e2abe5 [noescape-by-default] Improve diagnostics.
This makes the special case diagnostics for detecting a missing
@escaping read through Optional and IUOs.
2016-08-12 17:06:12 -07:00
Jordan Rose
148e25dc03 Provide the '@escaping' fix-it for any call-site escaping mismatch. (#4181)
...not just those where the functions match otherwise. This allows the
fix-it to be provided in cases where the closure being passed is a
subtype, or when there are generics involved. Yes, the '@escaping'
might not be the only issue, but it will need to get fixed, and
probably independently of anything else that's going on (except
perhaps calling the wrong function).

rdar://problem/27729540
2016-08-11 14:32:36 -07:00
Michael Ilseman
caa9d67469 [noescape by default] Emit deprecation warning/fixit for @noescape
@noescape is now the default behavior, so deprecate it and offer a
fixit.
2016-08-04 16:28:43 -07:00
Michael Ilseman
9e9a1b96c9 [noescape by default] Add @autoclosure @escaping syntax
Adds the preferred syntax for escaping autoclosures, which is
@autoclosure @escaping. Deprecates @autoclosure(escaping), and
provides fixits.
2016-08-04 15:27:34 -07:00
Michael Ilseman
49394eb370 [noescape-by-default] incorporate Doug's feedback
Added sugared test case
2016-08-02 21:06:40 -07:00
Michael Ilseman
4ca39fd284 [noescape-by-default] Expand useful diagnostics to more cases
Extends the more useful diagnostics for non-escaping function
parameters used in @escaping contexts to apply to all functions that
are equivalent modulo ExtInfo.
2016-08-02 14:52:43 -07:00
Michael Ilseman
ce1565a110 [noescape-by-default] Better diagnostics for parameters
Issue better diagnostics, along with notes and fixits, for the common
case of using an implicitly non-escaping parameter of function type in
a context expecting an @escaping closure. Provides even more specific
diagnostics for common scenarios such as passing to another function
or assignment.
2016-08-02 14:20:11 -07:00
Trent Nadeau
6ef59c09e5 Added @escaping attribute parsing 2016-07-08 21:14:39 -04:00