Commit Graph

1549 Commits

Author SHA1 Message Date
Pavel Yaskevich 58678a67f8 [CSSimplify] Don't attempt overload choices of all call arguments are invalid
Short-circuit calls where all arguments are invalid, otherwise the
solver would end up producing a solution for every overload which
it cannot disambiguate which quickly turns into "too complex" situation.
2026-06-01 11:28:19 -07:00
Ben Cohen c9c9000b20 MiscDiagnostics: handle implicit callee in fixItEncloseTrailingClosure (#88860)
When a CallExpr's callee is implicit (e.g. `callAsFunction`),
`fn->getEndLoc()` collapses to the call site's location, so the
bare-trailing-closure path could compute `lastLoc` at or past the
closure's start. The resulting `fixItReplaceChars(lastLoc,
closureRange.Start, ...)` produced a degenerate SourceRange that crashed
the Swift-syntax-aware diagnostic renderer when constructing
`Range<AbsolutePosition>`. Detect that case and fall back to a plain
insertion at the closure's start.

fixes rdar://170779809
2026-05-07 05:51:55 -07:00
Pavel Yaskevich 561f6492d4 [CSSimplify] Don't transfer typed throws onto the closure
This is a partial revert of https://github.com/swiftlang/swift/pull/87360

The change attempted to infer a concrete thrown error type onto
the closure but that leads to incorrect solutions when closure is
passed as an argument to an overloaded declaration because the
solver doesn't check whether calls in the body do throw the
expected type even with `FullTypedThrows` feature enabled
and so the safest option is still to assume un-typed `throws`
unless typed throws comes from a concrete contextual type.

Resolves: rdar://173132715
2026-03-24 09:27:55 -07:00
Freddy Kellison-Linn 45505b87a5 Implement async defer
Use closure for defer body

Revert to main

Rework implementation to keep FuncDecl

Add AST briding

Add test with async let

Add main actor tests

Add additional tests
2026-03-14 17:47:51 -04:00
Slava Pestov 4718412ec9 Sema: Consolidate tests for leading dot expressions in test/expr/leading_dot 2026-03-10 14:47:31 -04:00
Slava Pestov 6c211745f6 Sema: Fix small problem in inferTransitiveKeyPathBindings()
It looks like originally, we would only infer bindings from a
KeyPath type, which has invariant generic arguments. However,
nowadays we can infer a keypath root type from a function
type as well, because we allow keypath to function conversions.

So, if we inferred the key path root type through a function type,
then in fact we cannot introduce it as an exact binding, and
we must preserve variance.

This fixes a test failure that appears with a subsequent change
I'm making.
2026-03-10 14:47:28 -04:00
Hamish Knight ed33b31922 [Sema] Allow falling back to outer results from closure
If we encounter a variable declared after its use within a closure,
we can fallback to using an outer result if present. This matches the
behavior outside of a closure and generally seems more consistent with
the behavior we have if we also find an inner result.

rdar://163656720
2026-03-03 21:59:12 +00:00
Hamish Knight 7350671733 [Sema] Catch use-before-declarations in nested closures
Previously we would allow these in Sema and diagnose them in SILGen,
but allowing them in Sema is unsound because it means the constraint
system ends up kicking interface type requests for declarations that
should be type-checked as part of the closure itself. Adjust the
name lookup logic to look through parent closures when detecting
invalid forward references.

For now we don't fallback to an outer result on encountering a
use-before-declaration to preserve the current behavior. I'm planning
on changing that in the next commit though.

rdar://74430478
2026-03-03 21:59:12 +00:00
Slava Pestov 9336f9860a Merge pull request #87159 from slavapestov/exact-bindings
Sema: Exact bindings
2026-02-27 11:54:32 -05:00
Slava Pestov 9cf7131f23 Sema: Prefer binding sets with Exact bindings 2026-02-24 21:34:39 -05:00
Pavel Yaskevich 50c99da2f6 Merge pull request #87360 from xedin/typed-throws+closures
[ConstraintSystem] A few fixes for interaction between typed throws feature and closures
2026-02-23 06:57:43 -08:00
Rintaro Ishizaki 799d8af0f1 Merge pull request #86244 from calda/cal--array-init-trailing-closure 2026-02-20 20:51:44 -08:00
Pavel Yaskevich c6150638f2 [CSDiagnostics] Adjust assertion to handle throws(Never) considered to be a throwing function type
`isThrowing` returns `true` for a function type that is `throws(Never)`
even though it's wrong, let's work around that until the underlying issue
is fixed.
2026-02-20 09:22:17 -08:00
Pavel Yaskevich 105bdb8910 [ConstraintSystem] Propagate typed throws error type into throwing closures
In a typed throws context a throwing closure (as determined from the
body or an explicit `throws`) assumes an error type of the context that
is a subtype of `any Error`.

This is a carve out from `FullTypedThrows` feature that let's more
code that adopted typed throws to type-check without source compatibility
impact since without context a closure would still be using un-typed
throws and no additional inference of error type is done.
2026-02-20 09:14:51 -08:00
Cal Stephens 980edf83a9 Improve tests and simplify code 2026-02-19 12:51:54 -08:00
Cal Stephens cf470ada61 Support '[Element] { ... }' trailing closure init syntax 2026-02-19 12:51:54 -08:00
Slava Pestov 5f3c8a3926 Sema: Handle existential metatype conversions in scoreCandidateMatch() 2026-02-18 22:31:13 -05:00
Slava Pestov ae4f5e7c82 Run tests with -solver-enable-crash-on-valid-salvage 2026-02-13 09:57:22 -05:00
Artem Chikin 1e5ba5fca8 [Literal Expressions] Add support for literal expressions in enum raw values
Modify relevant portions of the type-checker and parser to allow, when the 'LiteralExpressions' experimental feature is enabled, for arbitrary integer-typed expressions in enum raw value specifiers. These expressions will be type-checked and constant-folded into an integer literal expression, keeping the current interface of 'EnumElementDecl' consistent for clients.

Previously, 'EnumRawValuesRequest' had two different "modes" which were discerned based on typechecking stage (structural | interface), where the former had the request compute all raw values, both user-specified literal expressions and computing increment-derived values as well; the latter would also type-check the user-specified expressions and compute their types.
- With the need to have enum case raw values support arbitrary integer expressions, the request ('EnumRawValuesRequest') has been refactored and simplified to *always* both compute all case raw values and perform type-checking of user-specified raw value expressions. This is done in order to allow the AST-based constant-folding infrastructure ('ConstantFoldExpression' request) to run on the expressions. Constant folding is invoked during the evaluation of 'EnumRawValuesRequest' on all user-specified raw value expressions, in order to be able to compute subsequent increment values and ensure the expressions are foldable. If they are not, i.e. if constant folding fails, a relevant diagnostic will be emitted.
- 'EnumElementDecl' continues to store the raw value expression, which is no longer a 'LiteralExpr' but rather an 'Expr'; however, the getter ('getRawValueExpr') continues to return a 'LiteralExpr' by invoking the constant-folding request on the stored value, which is guaranteed to return a cached result from a prior invocation in 'EnumRawValuesRequest', assuming it succeeded.
- Furthermore, the 'structural' request kind was previously not cached, whereas now because the request must always do the complete type-checking work, it is always cached.

Resolves rdar://168005520
2026-02-10 09:43:07 +00:00
Hamish Knight 746f011cd0 Merge pull request #77063 from jamieQ/jquadri/warn-weak-to-strong-capture
[Sema]: diagnose implicit strong captures of weak capture list entries
2026-02-04 14:55:58 +00:00
Pavel Yaskevich a10957244a Merge pull request #86942 from xedin/fix-leading-dot-base-inference
[CSBindings] Filter leading-dot base types based on member lookup
2026-02-04 06:43:26 -08:00
Slava Pestov 1b918ded02 Merge pull request #86163 from youngbash88/fix-54030
[Sema] Move anonymous closure argument check from parser to semantic analysis
2026-02-04 02:03:50 -05:00
Jamie f9e41569f1 [Sema]: diagnose implicit strong captures of weak capture list items
Add a diagnostic for when a weak or unowned capture list item binds a
referent that is implicitly strongly captured in an outer escaping
closure.
2026-02-03 16:21:20 -06:00
Pavel Yaskevich c6977a596a [Tests] NFC: Add a test-case for invalid leading-dot syntax reference
This is no longer supported because `Q` is not a direct requirement of `T`.
2026-02-02 15:32:23 -08:00
AnirudhMathur12 afc9f97451 The fix for the callee locator now produces specific no exact matches errors and candidate notes instead of the generic failed to produce diagnostic fallback. This updates the test to match the new behavior. 2026-01-26 22:14:12 +05:30
bashir 176229aeb4 [Sema] Move anonymous closure argument check from parser to semantic analysis 2025-12-22 01:35:04 +02:00
Slava Pestov e7d2c163be Merge pull request #85933 from slavapestov/fix-ben-regression
Sema: Disambiguate some more bidirectional conversions
2025-12-10 06:53:01 -05:00
Slava Pestov f3e6b4ceda Sema: Disambiguate some more bidirectional conversions
This fixes an ambiguity introduced by the stdlib change in
0f99458900.

Since (borrowing T) -> () and (T) -> () both convert to
each other, we could end up with ambiguous solutions where
neither one was better than the other. Generalize the
existing trick we use for labeled vs unlabeled tuples to
also strip off ownership specifiers and @convention(...)
from function types. This fixes the regression, as well
an existing FIXME in a test I added a while ago where
the same problem arises with @convention(block).
2025-12-09 18:31:59 -05:00
Pavel Yaskevich 7d3e40b7bb Merge pull request #85830 from jamieQ/no-async-in-await-fixit
[Sema]: add fixit for `no_async_in_await` warning
2025-12-08 11:26:32 -08:00
Jamie 87aab10541 [test]: update existing tests for SingleValueExpr fixit 2025-12-06 05:18:24 -06:00
Jamie 2c4e26b94f [test]: update existing tests for new fixit 2025-12-06 04:05:44 -06:00
Jamie 5aba778b01 [Sema]: add fixit for no_async_in_await warning 2025-12-04 04:54:23 -06:00
Anthony Latsis 91d2323b16 [test] Add tracking test for https://github.com/swiftlang/swift/issues/85587 2025-12-02 12:21:35 +00:00
Hamish Knight 00d8774032 [Sema] Upgrade tuple shuffle warning to error in future lang mode
This has been deprecated for a while now, flip it to an error for a
future language mode.
2025-10-29 15:14:23 +00:00
Hamish Knight 24347812f5 [Diag] Reword the tuple shuffle diagnostic
"reorder" seems a bit less jargony than "shuffle", and include the 
labels that are being reordered.
2025-10-29 15:14:23 +00:00
Becca Royal-Gordon e6d8b02626 Make module selectors non-experimental
Approved by SE-0491.
2025-10-24 16:23:50 -07:00
Becca Royal-Gordon 78a7df8d4a Merge pull request #85018 from beccadax/this-is-the-key-path 2025-10-21 16:27:38 -07:00
Becca Royal-Gordon c58c307c2e Don’t redundantly diagnose key path components
A key path component that resolved to an `ErrorExpr` would be diagnosed twice: once when the `ErrorExpr` was created, then again when it was processed. Fix this redundant diagnostic.
2025-10-20 15:11:14 -07:00
Becca Royal-Gordon 96e6b1d618 Fix malformed arg label error with module selector
The legacy parser has a special case for code like `fn(:)` which corrects it to `fn(_:)`, but the new `::` token was interfering with cases where there were two adjacent colons (e.g. `fn(::)`). Correct this issue.
2025-10-18 03:15:53 -07:00
Becca Royal-Gordon 58954734a0 [NFC-ish] Do lookahead without llvm::function_ref 2025-10-16 13:30:29 -07:00
Henrik G. Olsson cbc0ec3b88 Add -verify-ignore-unrelated where necessary (NFC)
These are tests that fail in the next commit without this flag. This
does not add -verify-ignore-unrelated to all tests with -verify, only
the ones that would fail without it. This is NFC since this flag is
currently a no-op.
2025-10-04 14:19:52 -07:00
Hamish Knight 9f5a754b77 [Sema] Ban placeholders in typed throws
This never worked correctly and would crash in SILGen, ban the use
of placeholder types. While here, ensure we replace any ErrorTypes
with holes when solving the closure in the constraint system.
2025-09-17 20:41:20 +01:00
Allan Shortlidge e0eba4ed5e AST: Add printing support for #available and #_hasSymbol conditions.
Teach `ASTPrinter` to print `if #available` and `if #_hasSymbol` statements.
2025-09-05 18:34:31 -07:00
Felipe Mussi Ferreira Peixoto 9779591212 [CSDiagnostics] Prevent nested type references in KeyPath components (#83625)
This change adds detection for nested type references in KeyPath
components and applies the appropriate fix to generate meaningful error
messages, following the same pattern already established for method
references.

The fix ensures that invalid KeyPath references fail gracefully in
normal mode and provide helpful diagnostics in diagnostic mode,
improving the developer experience when working with KeyPaths.

Resolves: https://github.com/swiftlang/swift/issues/83197
2025-08-27 14:50:14 -07:00
Allan Shortlidge 2d5824ef1a Sema: Diagnose key path setter availability.
Diagnose the availability of the specific accessors that are referenced
implicitly via a key path reference. This causes setter availability to be
diagnosed when passing a key path to a function that takes a `WritableKeyPath`.

Resolves rdar://157232221.
2025-08-27 07:58:35 -07:00
Hamish Knight 5c3f6703a0 Remove diag::type_of_expression_is_ambiguous
This is a diagnostic that is only really emitted as a fallback when
the constraint system isn't able to better diagnose the expression.
It's not particulary helpful for the user, and can be often be
misleading since the underlying issue might not actually be an
ambiguity, and the user may well already have a type annotation. Let's
instead just emit the fallback diagnostic that we emit in all other
cases, asking the user to file a bug.
2025-08-19 17:14:23 +01:00
Mykola Pokhylets 89f8f8b9bf Wrap only changes related to the closure frontend logic 2025-08-02 20:24:46 +02:00
Mykola Pokhylets ae48446716 Wrap SE-0481 into an upcoming feature until source incompatibilities are resolved 2025-08-02 20:24:21 +02:00
Allan Shortlidge 99380bf00f Sema: Sometimes allow universally unavailable declarations to be referenced.
In implicit contexts that are universally unavailable, allow writable key paths
to be formed to properties with setters that are also marked as universally
unavailable. This fixes a regression from the previous commit where the code
synthesized for `@Observable` properties in universally unavailable classes was
rejected by the availability checker.
2025-07-15 14:08:57 -07:00
Allan Shortlidge 4076fa6b2e ConstraintSystem: Make key paths for properties with unavailable setters read-only.
Previously, only conditional unavailability was considered, but setters that
are always unavailable must also make a keypath read-only.

Resolves rdar://155832511.
2025-07-15 10:33:44 -07:00