1541 Commits

Author SHA1 Message Date
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
Pavel Yaskevich
2957da3591 [ConstraintSystem] Disable performance hacks by default
This also changes the flag to `-enable-constraint-solver-performance-hacks`.
2025-06-27 23:43:09 -07:00
Doug Gregor
c34f81e110 Allow #selector to reference async method in non-async code
Fixes rdar://153118331
2025-06-23 12:41:18 -07:00
Hamish Knight
b37e34ea8d [Sema] Tighten up function call check in resolveKeyPathExpr
Check for `CallExpr` instead of `ApplyExpr`, we don't support
arbitrary postfix operators in key paths.
2025-06-17 23:07:46 +01:00
Mike Ash
53aa827f8f Merge pull request #81957 from mikeash/implicit-weak-capture-test-timing-fix
[Test] Make implicit_weak_capture.swift more robust.
2025-06-10 15:14:35 -04:00
Anthony Latsis
f2e1420a90 Sema: Never record argument label mismatches for unlabeled trailing closures
Fixes a crash on invalid. The previous logic was causing a label
mismatch constraint fix to be recorded for an unlabeled trailing closure
argument matching a variadic paramater after a late recovery argument
claim in `matchCallArgumentsImpl`, because the recovery claiming skips
arguments matching defaulted parameters, but not variadic ones. We may
want to reconsider that last part, but currently it regresses the
quality of some diagnostics, and this is a targeted fix.

The previous behavior is fine because the diagnosis routine associate
with the constraint fix (`diagnoseArgumentLabelError`) skips unlabeled
trailing closures when tallying labeling issues — *unless* there are no
other issues and the tally is zero, which we assert it is not.

Fixes rdar://152313388.
2025-06-05 18:01:20 +01:00
Mykola (Nickolas) Pokhylets
87e536ebec Merge pull request #80440 from nickolas-pohilets/mpokhylets/weak-let 2025-06-05 09:59:33 +02:00
Mike Ash
d0248afd14 [Test] Make implicit_weak_capture.swift more robust.
This test creates an object then checks a weak reference to that object on a background thread. It was doing this check after 10ms, and any small hiccup could potentially delay the object's destruction enough to spuriously fail.

Rearrange the test to check the weak reference in a loop for several seconds before giving up. This makes it very fast on success (it's done the moment it sees nil) while being robust against up to several seconds of delay in destroying the object if that happens.

rdar://149868181
2025-06-03 17:08:41 -04:00
Pavel Yaskevich
4132aa04f9 [Tests] NFC: Update all of the test-cases improved by changes to generic argument mismatch handling 2025-06-03 00:49:06 -07:00