Commit Graph

3274 Commits

Author SHA1 Message Date
Allan Shortlidge cea706a03f AST: Improve InFlightDiagnostic::fixItRemove() heuristics.
If the fix-it would remove a range that is followed by a newline and the
remaining text on the line is empty or all whitespace then remove the entire
line. This produces better results when a fix-it removes an attribute that is
written on a line by itself.
2026-05-06 11:03:30 -07:00
Allan Shortlidge 440120557e AST: Introduce the ModuleSelfImport diagnostic group. 2026-04-23 13:06:36 -07:00
Aidan Hall b872aedbd5 Merge pull request #88230 from aidan-hall/lifedep-ignore-in-type-inference
LifetimeDependence: Do not check witness method lifetimes in associated type inference
2026-04-20 10:33:13 +01:00
Aidan Hall eb25e9081d LifetimeDependence: Ignore in associated type inference
rdar://173716835
2026-04-17 12:15:14 +01:00
Aviva Ruben 1a032f3c51 Add comments that link to #88367 2026-04-08 14:29:47 -07:00
Aviva aa649de3ca Merge pull request #87939 from a-viv-a/suggest-immutable-witness
Suggest immutable witness
2026-03-30 10:04:33 -07:00
Meghana Gupta 3d3d476b6f Merge pull request #88107 from meg-gupta/enableborrow
Enable BorrowAndMutateAccessors by default
2026-03-27 12:43:02 -07:00
Meghana Gupta d6e220669f Enable BorrowAndMutateAccessors by default 2026-03-25 16:52:39 -07:00
Allan Shortlidge 9a25399f81 Make StrictAccessControl an experimental feature.
It was originally introduced as an upcoming feature, but there isn't any
precedent for using upcoming features as a way to opt-in to type checking fixes
without an associated Swift Evolution proposal. Rather than using a "feature" to
control this behavior, it would probably be better to offer a way to use
`-Werror` to upgrade these warnings to errors.
2026-03-24 17:59:40 -07:00
Aidan Hall c4d32f901d Merge pull request #87281 from aidan-hall/lifedep-protocol-check
Require compatible lifetimes in protocol conformance checking and function type matching
2026-03-24 14:16:56 +00:00
Aviva Ruben 69b6c8cc9e [Sema] Suggest let, nonisolated for properties and computed properties
Fixes rdar://89864078, by checking if all the required vars are
immutable, and suggesting mutable variables be converted to immutable to
become nonisolated and presumably fix the isolation issue. Also suggests
'nonisolated' on var decls without storage or wrapper. Additionally,
converts existing 'nonisolated' for method suggestion to emit per-method
instead of a top level 'all', for consistency with the new diagnostic,
based on PR feedback.
2026-03-23 15:42:18 -07:00
Hamish Knight 6e2806dbb8 [test] Test more cases in unbound_base.swift
A couple of these cases already work, add expectations to the rest,
and add a bunch more cases.
2026-03-21 22:18:15 +00:00
Hamish Knight cf17b935ef [test] Rename a struct 2026-03-21 22:18:14 +00:00
Hamish Knight 528ab2ec52 [test] Rename fully_constrained -> unbound_base
I'm planning on adding more test cases that don't necessarily have a
fully constrained base.
2026-03-21 22:18:14 +00:00
Aidan Hall 11429fc6ba LifetimeDependence: Lifetime subtyping tests
- Function type matching
- Protocol conformance
2026-03-20 14:42:15 +00:00
Gabor Horvath d15376a0a3 [cxx-interop] Fixup ownership mismatch between ObjC and Swift in thunks
The ObjC thunk already attempted to do fixup for ownership mismatches
but it derived the wrong parameter convention for the ObjC thunk itself
so this fixup did not happen. This PR makes sure we have the correct
ownership convention for the ObjC thunk so the fixup actually happens.

Furthermore, this PR relaxes the type checker so we no longer error out
on the ownership convention mismatch.

rdar://172701291
2026-03-18 15:51:58 +00:00
Kavon Farvardin d46a86e5b1 Sema: fix effects checking in witness matching
A requirement defines the maximal effects that a witness can have.

In some cases, we'd fail to properly reject such a witness with more
effects, when that witness is valid for another requirement within that
protocol. Thus, we'd hit an assertion failure in that case rather than
permitting the valid program to compile.

In a non-asserts compiler, we could end up failing to diagnose an invalid
chosen witness and crash in IRGen.

https://github.com/apple/swift/issues/73479
rdar://127669069
2026-03-12 22:08:40 -07:00
Pavel Yaskevich fcca0accb9 Merge pull request #87680 from xedin/constrain-init-param-to-read-or-write-keypath
[Diagnostics] PropertyWrappers: Allow enclosing-self subscript to acc…
2026-03-05 16:07:28 -08:00
Gábor Horváth 52a777237b Merge pull request #87678 from Xazax-hun/objc-impl-ownership-verification
[cxx-interop] Fix @implementation not detecting ownership mismatch
2026-03-05 16:38:29 +00:00
Pavel Yaskevich b035ceaeb5 [Diagnostics] PropertyWrappers: Allow enclosing-self subscript to accept a read-only keypath
This is a follow-up to https://github.com/swiftlang/swift/pull/87403
which allows existing code that uses `KeyPath` to be accepted by the
compiler.
2026-03-04 10:13:56 -08:00
Gabor Horvath 5515eb25dd [cxx-interop] Fix @implementation not detecting ownership mismatch
@objc @implementation annotated Swift methods did not check whether the
ownership conventions of the Swift function match the Obj-C(++)
declaration. A mismatch can result in use after free errors or leaks.

This PR adds some extra check for the ownership conventions and also
makes sure the imported Swift declaration is has the right parameter
ownership for `NSConusming` and `CFConsuming` annotated parameters.

rdar://168929333
2026-03-04 17:41:26 +00:00
Flamki b5ae453dca [PropertyWrappers] Use unquoted enclosing-self param names in diag 2026-02-28 20:02:20 +05:30
Flamki c401797b13 [PropertyWrappers] Match verifier expectations to emitted diag text 2026-02-28 00:46:36 +05:30
Flamki 09dff4928d [PropertyWrappers] Relax verify match for parameter-name quoting 2026-02-28 00:20:12 +05:30
Flamki 8569a6c59c [PropertyWrappers] Fix verify pattern in invalid wrapper test 2026-02-27 19:24:22 +05:30
Flamki d31c569fe4 [PropertyWrappers] Address final review nits for enclosing-self diagnostic 2026-02-26 11:05:00 +05:30
Flamki 3b96878566 [PropertyWrappers] Address review for enclosing-self key path diagnostic
Update diagnostic wording to mention both WritableKeyPath and ReferenceWritableKeyPath, include actual type in message, and refactor subscript parameter validation using a local checker for wrapped/projected and storage parameters.\n\nUpdate regression expectations accordingly.
2026-02-25 04:08:28 +05:30
Flamki fb1e8b4899 [PropertyWrappers] Diagnose invalid enclosing-self subscript key path parameters
Emit a dedicated diagnostic when an enclosing-self property wrapper subscript uses non-key-path types for the 'wrapped/projected' or 'storage' parameters, and ignore such subscripts for synthesis to avoid fallback <unknown>:0 key-path inference failures.\n\nUpdate property_wrappers_invalid.swift to verify the new direct diagnostics instead of relying on verify-ignore-unknown.\n\nResolves https://github.com/swiftlang/swift/issues/54422
2026-02-22 14:14:10 +05:30
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
Hamish Knight bc65846be2 [Sema] SE-0502: Enable ExcludePrivateFromMemberwiseInit by default
Enable the feature by default, and add an experimental feature
`DeprecateCompatMemberwiseInit` to control the deprecation behavior
which was deferred from the proposal.
2026-02-06 11:50:40 +00:00
Kavon Farvardin 006a0a494a Reparenting: require an extension
This change forces you to write ``@reparented` relationships
on an extension of a protocol, rather than on the protocol
itself.

The ProtocolConformance needs to be associated with some
GenericContext and IRGen expects it to be an ExtensionDecl.
That environment defines under what conditions the conformance
exists. We also need to define witnesses for the new parent's
requirements in an extension anyway, so it's a natural fit.

The previous workaround for this was kind of awful, as it'd
require searching all the protocol's extensions and "guess"
which extension they want to represent the conformance. While
we could try to synthesize an extension, there's two
challenges there:

1. Due to SuppressedAssociatedTypes, it's not so simple to
synthesize an unconstrained ExtensionDecl.
2. We currently rely on same-type requirements to pin the
associated types to particular witnesses of those requirements
in the extension. So it's not purely unconstrained! For example,

```
extension Seq: @reparented BorrowSeq where Iter == MyIter {}
```

The constraints that are disallowed (but not yet diagnosed)
are conditional conformance requirements, as the default
conformance for a reparenting cannot depend on those.

Thus, it's better that programmers to specify the extension.
2026-02-03 16:40:21 -08:00
Sam Pyankov aa30b1a106 Merge branch 'main' into revert_public-decl-internal-protocol 2026-01-23 15:17:25 -08:00
Sam Pyankov 70835508b0 Revert "Diagnose public protocol witnessed by an internal protocol extension"
This reverts commit 6280a7001f.
rdar://168627163
2026-01-23 10:28:19 -08:00
Alexis Laferrière c8f99af698 Merge pull request #86335 from xymus/exportability-nle-warn
Sema: Enable exportability checks in non-library-evolution mode as warnings by default
2026-01-22 09:47:52 -08:00
Sam Pyankov a0dc22e819 Merge pull request #86392 from sepy97/strict_access_check_errors
Stricter access control enforcement
2026-01-13 15:45:16 -08:00
Slava Pestov 23b951b817 Merge pull request #86429 from slavapestov/fix-rdar167851622
Sema: Don't just ignore protocol type aliases in LookupResultBuilder::add()
2026-01-10 10:39:29 -05:00
Slava Pestov 688ba5d9ff Sema: Don't just ignore protocol type aliases in LookupResultBuilder::add()
Fix regression from 62e4979691.

An associated type can be witnessed by a type alias that is
directly declared in a protocol. Don't drop it in this case.

It seems that this didn't matter too much in the past, but
now that name lookup prefers an associated type declaration
over a type alias (which may or may not be the type witness),
we really must correctly resolve the associated type to a
type witness instead of just dropping it sometimes.

Fixes rdar://167851622.
2026-01-09 15:31:34 -05:00
Tim Kientzle adec1f6cbe Merge pull request #86277 from tbkka/tbkka-rdar149303951-try1
[SE-0474] Implement final `yielding borrow`/`yielding mutate` naming for coroutine accessors
2026-01-09 08:52:21 -08:00
Sam Pyankov b0eee67a7b Emit an errors instead of warnings access control violations that should be fixed in the future when StrictAccessControl upcoming feature is enabled 2026-01-08 14:24:35 -08:00
Hamish Knight 7c36833439 Merge pull request #86311 from hamishknight/ext-fix
Avoid loading serialized extensions for nominals in SourceFile
2026-01-08 21:38:06 +00:00
Alexis Laferrière 5cc4c788aa Sema: Update warning on @_implementationOnly import
Invite users of `@_implementationsOnly` imports from modules without
library-evolution to adopt `CheckImplementationOnly`. Use the existing warning
on the import statement. Adopting that feature reports unsafe references to
implementation-only imported types as errors and silences the warning on
the import.
2026-01-06 15:12:47 -08:00
Slava Pestov 62e4979691 AST: Prefer associated types over protocol type aliases 2026-01-06 11:50:32 -05:00
Hamish Knight 4e950e3591 Avoid loading serialized extensions for nominals in SourceFile
Looking up serialized extensions for a nested nominal type requires
computing its mangled name, which may kick semantic requests. Ensure
we don't do this for nominals in parsed SourceFiles such that we
don't end up kicking this during extension binding.
2026-01-06 15:34:33 +00:00
Hamish Knight 5d7ece7b7f [test] Move extension_binding_multi.swift 2026-01-06 15:34:00 +00:00
Tim Kientzle 104dba920b [SE-0474] Implement yielding borrow and yielding mutate syntax
This does not rename all the internal variables, functions, and types
whose names were based on the old syntax.

I think it adds new syntax support everywhere it's needed while
retaining enough of the old syntax support that early adopters will
see nice deprecation messages guiding them to the new syntax.
2026-01-03 15:07:10 -08:00
Hamish Knight b1b7397aa3 [Sema] Use getFormalAccessScope in MemberwiseInitMaxAccessLevel
This ensures we handle nested types correctly for
`ExcludePrivateFromMemberwiseInit`.
2025-12-24 12:49:27 +00:00
Xi Ge 4a6badd6ee Merge pull request #85846 from sepy97/public-decl-internal-protocol
Diagnose public protocol requirements witnessed by internal protocol extensions
2025-12-17 09:39:32 -08:00
Sam Pyankov 6280a7001f Diagnose public protocol witnessed by an internal protocol extension
Private member witnessing a public constraint should be deprecated.
Previously existing workaround is checked and compiler emits a warning
when strict access check is not passed. Test files were fixed to expect
the corresponding warning.

rdar://74904373
2025-12-15 16:23:06 -08:00
Hamish Knight 45683f6561 [Sema] Exclude private initialized vars from memberwise initializer
Exclude properties with initial values from the memberwise initializer
if they are less accessible than the most accessible property, up to
`internal`. Introduce a compatibility overload that continues to
include the same properties as before until the next language mode.

This is gated behind the `ExcludePrivateFromMemberwiseInit` feature.

rdar://122416579
2025-12-08 23:22:35 +00:00
Jamie 2c4e26b94f [test]: update existing tests for new fixit 2025-12-06 04:05:44 -06:00