Commit Graph

39 Commits

Author SHA1 Message Date
Anthony Latsis
5e41794680 AST: Quote attributes more consistently in DiagnosticsSema.def 2025-04-23 19:18:08 +01:00
Anthony Latsis
85fae6b9ff Gardening: Migrate test suite to GH issues: attr 2022-08-11 18:00:04 +03:00
Luciano Almeida
0519dd7cab [Sema] Adjustments on implementation and diagnostic message for SR-14720 2021-06-30 06:39:04 -03:00
Luciano Almeida
51ee1de6f9 [Sema] Adjust escapeness function parameter diagnostic to use decl description 2021-06-30 06:39:04 -03:00
Luciano Almeida
e58dfa90f0 [test] Add regression tests for SR-14720 2021-06-30 06:39:04 -03:00
Suyash Srijan
f2545dc7d1 [CSDiagnostics] Insert '@escaping' fix-it when type has '@autoclosure' during non-escaping function type diagnostic (#33191) 2020-07-30 00:54:06 +01:00
Ivan Smetanin
f9b1a524da Fix escaping_optional_type_argument producing behavior 2020-04-04 20:22:04 +03:00
Ivan Smetanin
5f68f7a717 Make escaping_optional_type_argument to be an error, use it instead of original message when object type is a function type 2020-04-02 18:08:19 +03:00
Ivan Smetanin
3dacbed891 Add new error diagnostic for escaping optional closures 2020-04-01 08:57:48 +03:00
Suyash Srijan
3cda934329 [Typechecker] Fix duplicate diagnostics when using attributes (#28888)
* [Typechecker] resolveAttributedType() should invalidate the type repr after emitting a diagnostic, to prevent duplicate diagnostics later

* [Test] Update '@noescape' attribute diagnostics

* [Typechecker] Add a special diagnose method to TypeResolver that accepts a TypeRepr and invalidates it

* [Typechecker] Rename the special 'diagnose' method to 'diagnoseInvalid' for clarity
2019-12-20 19:26:50 +00:00
Nathan Hawes
4d2aca16a1 [Diag] Fix bug in type attribute SourceRange computation in type attribute fixits. 2019-08-05 11:36:32 -07:00
Pavel Yaskevich
62b2da803c [ConstraintSystem] Improve @escaping parameter diagnostics
Detect difference in escapiness while matching function types
in the solver and record a fix that suggests to add @escaping
attribute where appropriate.

Also emit a tailored diagnostic when non-escaping parameter
type is used as a type of a generic parameter.
2019-05-02 00:40:30 -07:00
Slava Pestov
003a9a47b2 Parse: Remove obsolete @autoclosure(escaping) and @noescape type attributes
Some diagnostics got worse, but I think the reduction in compiler complexity
is worth it, and copy-and-pasting Swift 2 code is not likely to produce great
results anyway.

Also, this corrects an oversight where we did not reject @pseudogeneric on
function types in AST parsing.
2019-04-09 15:02:14 -04:00
Slava Pestov
e214156abf Sema: Remove escaping capture diagnostics
I'm about to replace all of this with a SIL pass.
2019-04-09 15:02:14 -04:00
Suyash Srijan
be6dc7c84a [typechecker] handle typealias inside protocols when used with @escaping 2019-01-30 17:51:02 +00:00
Mark Lacey
8b55a0f61b SE-0054: Rework diagnostics for IUOs and revise Swift 3 /4 semantics.
For Swift 3 / 4:

Deprecate the spelling "ImplicitlyUnwrappedOptional", emitting a warning
and suggesting "!" in places where they are allowed according to
SE-0054.

In places where SE-0054 disallowed IUOs but we continued to accept them
in previous compilers, emit a warning suggesting "Optional" or "?"  as
an alternative depending on context and treat the IUO as an Optional,
noting this in the diagnostic.

For Swift 5:

Treat "ImplicitlyUnwrappedOptional" as an error, suggesting
"!" in places where they are allowed by SE-0054.

In places where SE-0054 disallowed IUOs, emit an error suggestion
"Optional" or "?" as an alternative depending on context.
2017-11-18 11:41:53 +09:00
Mark Lacey
e07a7362cf Add a warning that ImplicitlyUnwrappedOptional is deprecated in 4+.
Per SE-0054, implicitly unwrapped optional is not a distinct type in the
type system, but rather just the notion that certain Optionals (denoted
by the sigil "!" rather than "?") can be implicitly unwrapped.

This is a first step in the direction of implementing this notion by
emitting a warning if the type is spelled out.
2017-10-26 18:09:26 -07:00
Huon Wilson
55e1aa2a9f [Parse] Upgrade @noescape/@autoclosure(escaping) warnings to Swift 4 errors.
Part of rdar://problem/28961650 .
2017-07-12 13:26:09 -07:00
Slava Pestov
2119ab2782 Sema: A call of a closure literal is noescape
We cannot model a type variable bound to the ExtInfo of a function
type in the constraint solver, which means we have a hard time
propagating noescape-ness in some cases.

Fixes <rdar://problem/31910280> and <rdar://problem/32409133>.
2017-05-31 17:31:36 -07:00
Garric G. Nahapetian
7863e29279 Add fix-it to error and add note - SR-4637 (#8947)
Specialize the diagnostic emitted to remove the @escaping attribute from type refs to mention that arrows in optionals are implicitly escaping anyway.
2017-04-30 16:17:05 -04:00
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