Commit Graph

1275 Commits

Author SHA1 Message Date
Egor Zhdan dc4ba09d44 [cxx-interop] Fix-it for using nil instead of std::nullopt
In C++, `std::nullopt` is implicitly convertible to `std::optional<T>`. Swift doesn't support implicit type conversions between arbitrary types. Instead, the developer is expected to use `nil` literal, which is implicitly converted to `std::optional<T>`. This works via `CxxOptional`'s conformance to `ExpressibleByNilLiteral`.

This improves the diagnostic produced by Swift for the attempted usage of `std::nullopt` in places where the type conversion expected by the developer doesn't happen. A note will now be emitted:
```
use the 'nil' literal instead
```

rdar://162203520
2026-06-09 18:22:43 +01:00
Madushan Gamage e0b2f60c78 Diagnose static key path members on protocol metatypes
Key paths rooted at a protocol metatype could slip through the normal metatype checks and reach SILGen when they referenced a static property like \.foo. That left the compiler in the wrong state and could crash instead of producing a targeted error.

Teach constraint fixing to reject static member references through protocol metatype roots, add a dedicated diagnostic for that case, and consistently treat metatype bases as AnyMetatypeType during type checking and SILGen.
2026-06-01 13:12:14 -07:00
Slava Pestov 6b84857d6f AST: Remove useDC parameter from getDynamicMemberLookupKind() 2026-05-08 15:46:20 -04:00
Slava Pestov b062b8a285 Convert SubscriptDecl @dynamicMemberLookup checking to request
Adds a new DynamicMemberLookupSubscriptRequest type for evaluating and
caching the validity of a `SubscriptDecl`'s usage to fulfill a
`@dynamicMemberLookup` requirement for a specific usage.
2026-05-08 15:46:17 -04:00
Slava Pestov e4f99cc3be Use SubscriptDecl interface for @dynamicMemberLookup checks
`SubscriptDecl` exposes eligibility for `@dynamicMemberLookup`
requirements directly, so the `TypeChecker` interface for these members
can be replaced.
2026-05-08 15:46:17 -04:00
Aidan Hall e3d55f64c2 Lifetimes: Treat noescape function types as ~Escapable 2026-04-30 16:30:38 +01:00
Pavel Yaskevich cf310a517e [Diagnostics] Diagnose missing pattern(s) in associated value match
Teach the missing argument diagnostic about pattern matches, there
was no diagnostic for this situation at all which results in
"failed to produce a diagnostic" fallback when this happens.

Resolves: rdar://167455709
2026-03-30 10:41:12 -07:00
Pavel Yaskevich 24d61f7da2 [Diagnostics] Refactor handling of multiple missing arguments
Prepare to diagnose missing patterns by refactoring how diagnostic
arguments and fix-its are formed whne there are multiple missing
arguments.
2026-03-27 15:23:16 -07:00
Pavel Yaskevich 298dcc6aa8 Merge pull request #87931 from xedin/issue-87818
[Diagnostics] Diagnose missing closure, function value parameters in …
2026-03-23 06:51:10 -07:00
Doug Gregor 20e65b713e Merge pull request #84474 from DougGregor/stdlib-swiftsourceinfo
Build and install .swiftsourceinfo files for the standard library + friends
2026-03-18 21:56:38 -07:00
Pavel Yaskevich 7d1f6f92ee [Diagnostics] Diagnose missing closure, function value parameters in assignments
Teach `MissingArgumentsFailure` that a "source" of the assignment could
be a closure that has some of the expected arguments missing. For function
values in the same situation, produce a generic conversion mismatch
diagnostic.

Resolves: https://github.com/swiftlang/swift/issues/87818
Resolves: rdar://172316156
2026-03-18 11:07:03 -07:00
Doug Gregor c261a1db0d Minor fixes to deal with the presence of .swiftsourceinfo for the Swift standard library 2026-03-11 10:58:04 -07:00
Hamish Knight 49f4d04703 [AST] Ensure Type diagnostic args are not solver allocated
Replace any type variables or placeholders with ErrorType, which will
just print as `_`.
2026-03-10 23:42:20 +00:00
John Hui c62949c51c [cxx-interop] [NFC] Remove unused ClangImporter::Implementation pointer
This was previously used to control whether a CxxRecordSemantics or
CxxRecordAsSwiftType request would trigger diagnostics when determining
a type is a foreign reference type. That interface led to obscure
control flow and was removed recently. This patch removes the vestigial
pointer field those requests used.

(Actually, that pointer was *never* used by CxxRecordAsSwiftType
requests; its call sites just happened to pick it up because it shares
the same input descriptor type as CxxRecordSemantics).

rdar://170858418
2026-03-05 14:22:57 -08:00
Artem Chikin 2fb1b73644 Merge pull request #87006 from artemcm/LiteralExpressionIntegerGenerics
[Literal Expressions] Add support for literal expressions in integer generic parameter values
2026-02-24 19:09:35 +00:00
Artem Chikin b6e9e5c7ba [Literal Expressions] Introduce expression-based generic arguments
Introduce new syntax for parsing arbitrary integer literal expressions for generic value arguments:
```swift
InlineArray<(<Expr>), T>
[(<Expr>) of T]
```
Which, for now, will co-exist alongside the current syntax of simple integer literals.

Replace `IntegerTypeRepr` with `GenericArgumentExprTypeRepr`, a new `TypeRepr` node that wraps arbitrary expressions in generic argument positions (e.g., `InlineArray<(1 + 3), Int>`). The node tracks resolution state, distinguishing whether the expression resolved to a type or an integer value.

Key changes:
- Parse parenthesized generic arguments as expressions
- Recover and distinguish types from integer expressions in `resolveGenericArgumentExprTypeRepr`.
- When the `LiteralExpressions` feature is enabled, type-check and constant-fold expressions to integer values
- Extract `PreCheckTarget` into a public header to expose `simplifyTypeExpr` for use during type resolution

Resolves rdar://168005391
2026-02-24 14:10:39 +00:00
Aviva Ruben 6d045e3b56 Avoid automatically making pack argument into tuple
Fixes #69245 by ensuring CSSimplify does not wrap PackExpansionType in a
tuple when it is the argument for a tuple parameter. This was causing a
crash. Also changes matchTypes to wrap such a pack expansion in a tuple
after diagnosing so we can infer more types. Adds a tailored diagnostic,
note, and fix-it to AllowInvalidPackExpansion for tuple containing pack
expansion parameters, that wraps with parens and names tuple parameter
instead of non-pack parameter.
2026-02-20 14:54:41 -08:00
Becca Royal-Gordon 31f99c2f55 Ignore generic context when module selector used
Normally, an unbound reference to a generic type within its own context is automatically bound to the identity generic arguments:

```
struct G<T> {
    typealias TA = G    // as if you wrote G<T>
}
```

Module selectors normally disable this kind of contextual behavior; make sure that this is not an exception.

To pipe the information needed to do this through the constraint solver, we extend FunctionRefInfo to remember whether a module selector was used.
2026-02-17 18:21:37 -08:00
Anthony Latsis 85db41932d Switch ASTContext::isLanguageModeAtLeast to LanguageMode 2026-02-10 16:06:58 +00:00
Anthony Latsis 31cafb0a27 Switch DiagnosticEngine::warnUntilLanguageMode and co. to LanguageMode 2026-02-10 16:06:56 +00:00
Slava Pestov 7cd06a5088 Sema: Split off TypeVariableType.h/.cpp 2026-02-05 09:19:01 -05:00
Hamish Knight de91fd77ec [CS] Remove some now-unnecessary for loop logic
We no longer need to track the `ForEachStmtInfo` in the
`SyntacticElementTarget`, and we can remove the special diagnostic
logic for `next` and `makeIterator` since those are type-checked
separately now.
2026-01-23 15:17:29 +00:00
Tim Kientzle 8eabeeb8ca [SE-0474] Read2/Modify2 => YieldingBorrow/YieldingMutate
This updates a large number of internal symbols, function names,
and types to match the final approved terminology.  Matching the
surface language terminology and the compiler internals should
make the code easier for people to understand into the future.
2026-01-03 16:05:12 -08:00
Pavel Yaskevich 270bbc5720 [CSDiagnostics] Produce a tailored diagnostic for key path mutability mismatches
If the type of a key path literal is read-only due to setter
availability constraints but the context requires a writable
key path, let's produce a tailed availability diagnostic that
points to the offending setter.

Resolves: rdar://157249275
2025-12-18 14:58:21 -08:00
Anthony Latsis 153dd02cd8 Merge pull request #85833 from swiftlang/jepa-main
[NFC] "SwiftVersion" → "LanguageMode" in `DiagnosticEngine::warnUntilSwiftVersion`, etc.
2025-12-05 09:34:30 +00:00
Anthony Latsis 88220a33c3 [NFC] "SwiftVersion" → "LanguageMode" in DiagnosticEngine::warnUntilSwiftVersion, etc. 2025-12-04 15:11:07 +00:00
Hamish Knight 3861d58175 [CS] Remove CTP_CannotFail
This is now unused.
2025-11-30 11:12:39 +00:00
Hamish Knight 9a31ef029c [CS] NFC: Remove CTP_ComposedPropertyWrapper
This has been unused since we added a custom `AllowWrappedValueMismatch`
fix.
2025-11-16 18:31:55 +00:00
Hamish Knight 6abfea9312 [CS] NFC: Remove CTP_CalleeResult
This has been unused since the removal of CSDiag.
2025-11-16 18:29:37 +00:00
Slava Pestov 819738c83e AST: Rename mapTypeIntoContext() => mapTypeIntoEnvironment(), mapTypeOutOfContext() => mapTypeOutOfEnvironment() 2025-11-12 14:48:19 -05:00
naveen-seth 9a88d61462 Address xedin's review feedback 2025-11-10 23:04:50 +01:00
naveen-seth 8b7b0e944b [Sema] Fix crash when diagnosing ambiguous trailing closure inits
Fixes #85376.

This fixes a compiler crash that occurred when diagnosing an ambiguous call
using trailing closure syntax, where one of the candidates was a function or
initializer with no parameters.
2025-11-10 03:12:18 +01:00
Hamish Knight 1781faba1a [CS] Upgrade tuple label mismatch warning to error for future lang mode
I missed upgrading this to an error for Swift 6 mode, let's upgrade it
to an error for a future language mode. It's important we reject these
cases since we're otherwise allowing subtyping to be a weaker constraint
than conversion.
2025-10-29 15:14:23 +00:00
Becca Royal-Gordon ec92be4955 Support module selectors for cross-import overlays 2025-10-24 16:23:50 -07:00
Becca Royal-Gordon 60cc537f70 Improve module selector constraint solver diagnostics 2025-10-24 16:23:49 -07:00
Becca Royal-Gordon 7bf14de2e6 Handle module selectors with local vars right 2025-10-24 16:23:34 -07:00
Hamish Knight d65f28984a [CS] Improve diagnostics for non-metatype type(of:) contextual type
Emit a custom diagnostic for this case, and handle holes.
2025-10-06 21:45:48 +01:00
Hamish Knight 669a2ce9b0 [CS] Sink placeholder handling logic into Solution::simplifyType
Move the logic from `FailureDiagnostic::resolveType` into
`Solution::simplifyType` to allow completion to use it too. While
here, also handle cases where the placeholder is from a different
member of the equivalence class to the generic parameter.
2025-10-04 12:56:52 +01:00
Hamish Knight 7e5dfc28fa [CS] Split out element archetype handling in resolveType
Make sure we do this after we transform the type as otherwise we could
skip resolving type variables and let them escape.
2025-10-04 12:56:52 +01:00
Hamish Knight 5171b84dba [CS] Replace UnresolvedType with ErrorType in simplifyType/resolveType
This means we now either produce a bare ErrorType, or an ErrorType
with a generic parameter original type for a generic parameter hole.
We ought to further consolidate this logic by sinking the generic
parameter original type replacement into `simplifyType` itself, but
I'm leaving that for a future patch since it affects completion
results and I want to try keep this close to NFC.
2025-10-03 09:50:42 +01:00
Allan Shortlidge 2467b931a7 ConstraintSystem: Move key path type utilities to AST. 2025-09-25 07:13:17 -07:00
Slava Pestov a12c160d0b Sema: Replace calls to OverloadChoice constructor with two overloads of getDecl() 2025-09-18 14:54:16 -04:00
Pavel Yaskevich 5207b0ec8a Merge pull request #84287 from xedin/issue-84150
[CSSimplify] Fix key path to function conversion to check key path re…
2025-09-15 11:48:30 -07:00
Meghana Gupta c764244df0 Merge pull request #84180 from meg-gupta/borrowandmutatepr
Add preliminary support for borrow accessors
2025-09-15 10:01:15 -07:00
Pavel Yaskevich ac27f53c04 [CSSimplify] Fix key path to function conversion to check key path requirements
`KeyPath` types now have conformance requirements placed on their
`Root` and `Value` types which need to be checked even when there
is a key path to function conversion involved, otherwise the solver
would be accepting invalid code.

Note that without function conversion the requirements come from
a type opened during assignment - https://github.com/swiftlang/swift/pull/80081/files.

Resolves: https://github.com/swiftlang/swift/issues/84150
2025-09-15 00:35:19 -07:00
Konrad `ktoso` Malawski d2a03b45d1 Merge pull request #84119 from ktoso/wip-allow-any-serialization-requirement 2025-09-12 11:08:20 +09:00
Konrad Malawski 644aa87447 Harden diagnoseForcedCastExpr for lack of cast-to type 2025-09-11 22:00:56 +09:00
Meghana Gupta 9fe489ce22 Introduce borrow and mutate as new accessor kinds
And handle them in various covered switches
2025-09-09 14:30:26 -07:00
Hamish Knight 71d825dcb8 [CS] NFC: Remove CTP_ForEachStmt 2025-09-05 22:20:28 +01:00
Hamish Knight 7fb532e4e6 Merge pull request #83776 from hamishknight/the-diags-never-stop-no
[Diags] Allow multiple in-flight diagnostics
2025-09-03 19:59:44 +01:00