Commit Graph

375 Commits

Author SHA1 Message Date
Slava Pestov
f07a16f92d Sema: Disable special handling of OneWayEqual constraints 2025-03-11 13:55:39 -04:00
Cal Stephens
14632b7c3e Update tests after pulling fix from master 2025-02-10 08:13:27 -08:00
Cal Stephens
041c68519c Simplify diagnostics 2025-02-06 08:38:13 -08:00
Cal Stephens
684c908564 Prevent nested closure in 'extension Optional' from unexpectedly being allowed 2025-02-04 18:49:42 -08:00
Cal Stephens
be0e68eca3 Add more test cases, simplify logic 2025-02-02 19:28:18 -08:00
Cal Stephens
e6a2230fdf Fix issue where implicit self was unexpectedly not allowed in nested weak self closure in Swift 6 mode 2025-01-18 18:25:23 -08:00
Hamish Knight
59885c474f [test] Add a lazy local test case
This hit an assertion I was trying to add to make
sure we don't try to recursively type-check when
type-checking a closure. Currently we can end up
type-checking the initializer for `x` while generating
constraints for the closure due to the fact that we
eagerly compute the interface type for the backing
lazy storage var. We ought to make that computation
lazy, but in the mean time, add this test case.
2024-09-17 12:35:11 +01:00
Hamish Knight
fe272e6cdd [Sema] Restore 5.10 implicit self behavior prior to Swift 6 mode
Unfortunately we've encountered another source
breaking case here:

```
class C {
  func method() {}

  func foo() {
    Task { [weak self] in
      Task {
        method()
      }
    }
  }
}
```

In 5.10 we'd only do the unqualified lookup for
`self` when directly in a `weak self` closure,
but with the implicit self rework, we'd start
using the `weak self` here, leading to a
type-checker error.

At this point, adding more edge cases to the
existing logic is going to make things much more
complicated. Instead, reinstate the 5.10 implicit
self lookup behavior and diagnostic logic,
switching over to the new logic only under Swift 6
mode.

rdar://129475277
2024-06-10 20:29:16 +01:00
Hamish Knight
21c0247eb2 [Sema] Preserve compatibility for weak self with @_implicitSelfCapture
In 5.10 we warned on this:

```swift
func bar(@_implicitSelfCapture _ fn: @escaping () -> Void) {}

class C {
  func foo() {
    bar { [weak self] in
      foo()
    }
  }
}
```

But with the implicit self rework, this accidentally
became an error. Fix it to ensure we continue to
warn until Swift 6 mode.

rdar://128941797
2024-05-29 16:11:38 +01:00
Cal Stephens
7d897fd383 Fix validation for async let thunks 2024-05-04 11:25:24 -07:00
Cal Stephens
7e95f9b15a Fix unexpected error by simplifying outermost capture validation 2024-05-04 09:25:24 -07:00
Cal Stephens
74a33eb420 Improve 'shouldOnlyWarn' logic 2024-04-25 06:26:50 -07:00
Cal Stephens
3fcc5a8f46 Always validate self capture 2024-03-31 19:50:44 -07:00
Cal Stephens
97178b2494 Look up the outer self decl via the capture's parent initializer instead of ASTScope::lookupSingleLocalDecl 2024-03-13 20:18:48 -07:00
Cal Stephens
f21aee7baa Improve quality of 'capture self explicitly to enable implicit self in this closure' and 'variable other than self captured here under the name self does not enable implicit self' diagnostics 2024-03-12 10:45:17 -07:00
Cal Stephens
94dcf9bc70 Fix edge cases related to nested autoclosures, invalid weak self unwrapping 2024-03-11 07:42:44 -07:00
Cal Stephens
8c5f783f5b [SE-0365] Fix issue where implicit self was unexpectedly disallowed in nested closures 2024-03-10 07:57:51 -07:00
Holly Borla
f1cd9cb422 [Test] Remove REQUIRES: asserts from tests that use -swift-version 6. 2024-02-13 07:13:35 -08:00
Pavel Yaskevich
859106eed1 [Diagnostics] Expand trailing closure failure to handle all closure arguments 2024-01-08 14:09:18 -08:00
Sophia Poirier
073f541734 [Concurrency] promote GlobalConcurrency from experimental to future feature 2024-01-06 19:07:23 -08:00
Doug Gregor
b7fd43949a Remove the TypedThrows experimental feature from the remaining tests 2024-01-03 22:08:56 -08:00
Doug Gregor
8ad137fb51 [Typed throws] Infer thrown error type for do..catch blocks within closures.
Start classifying all potential throw sites within a constraint
system and associate them with the nearest enclosing catch node. Then,
determine the thrown error type for a given catch node by taking the
union of the thrown errors at each potential throw site. Use this to
compute the error type thrown from the body of a `do..catch` block
within a closure.

This behavior is limited to the upcoming feature `FullTypedThrows`.
2023-12-13 14:59:23 -08:00
Doug Gregor
7f82b2a9aa [Typed throws] Enable checking of thrown types on closures.
Enable typed throws on explicit closures, either due to contextual
type information or due to explicit specification.
2023-09-29 10:51:54 -07:00
Pavel Yaskevich
cfea0d3d22 [TypeChecker] NFC: Add XFAIL'ed test-case for https://github.com/apple/swift/issues/67363 2023-08-14 10:06:52 -07:00
Pavel Yaskevich
64a654dc0d Revert "[CSBindings] Prefer conjunctions over closure variables without bindings"
This reverts commit 11ee82de7b.
2023-08-14 10:02:05 -07:00
Pavel Yaskevich
11ee82de7b [CSBindings] Prefer conjunctions over closure variables without bindings
If a closure doesn't have a contextual type inferred yet it should
be delayed in favor of already resolved closure conjunction because
"resolving" such a closure early could miss result builder attribute
attached to a parameter the closure is passed to.

Partially resolves https://github.com/apple/swift/issues/67363
2023-07-21 09:46:09 -07:00
Slava Pestov
1957bd6065 Sema: Reword diagnostics to say 'without a type annotation' instead of 'without more context' 2023-06-09 17:44:42 -04:00
Pavel Yaskevich
20d7642ca4 [CSGen] Allow expression pattern types to be holes 2023-04-24 10:02:00 -07:00
Cal Stephens
ee906f7ba5 Merge branch 'main' into cal--SE-3065-bad-pattern-check 2023-04-20 13:41:48 -07:00
Pavel Yaskevich
ff62be17a4 Merge pull request #65211 from calda/cal--weak-self-capture-inner-func
[SE-0365] Allow implicit self in inner functions in [weak self] closures, like with [self] closures
2023-04-19 22:48:24 -07:00
Cal Stephens
3e140286e8 Fix issue where non-pattern-binding condition would break SE-0365 unwrapped self check 2023-04-19 19:17:35 -07:00
Cal Stephens
6670639e9b Clean up implementation, add more extensive tests 2023-04-19 08:32:43 -07:00
Cal Stephens
9e55fb0ba0 Allow implicit self in inner functions in [weak self] closures, like with [self] closures 2023-04-15 09:27:20 -06:00
Cal Stephens
548456d62f Add test case for #64757 2023-04-03 18:21:02 -07:00
Anthony Latsis
14b70f306b DiagnosticVerifier: Default expected fix-it start line to the diagnostic's 2023-03-08 12:10:27 +03:00
Michael Gottesman
0ad5a18d40 Update test output. 2023-03-03 18:19:26 -08:00
Michael Gottesman
c97121d3ee [reference-binding] Add support for inout binding parsing/serialization. 2023-03-01 20:48:54 -08:00
Hamish Knight
043b192dcd [Sema] Diagnose duplicate pattern vars in pattern resolution
Unify the duplicate pattern var checking in
pattern resolution such that it is always called
no matter how we end up type-checking the pattern.
This avoids incorrectly allowing duplicate pattern
vars to compile for patterns as a part of
multi-statement closures.
2023-03-01 16:20:14 +00:00
Pavel Yaskevich
8e82f1d68b [CSGen] Detect nested out-of-scope variables in recursive declarations
Follow-up to https://github.com/apple/swift/pull/63505

Since, when the type is not stated, a variable assumes the
type of its initializer that enables out-of-scope variables
to be nested inside of some other concrete type i.e. Optional.

Resolves: https://github.com/apple/swift/issues/63455
2023-02-11 19:19:09 -08:00
Pavel Yaskevich
bffb8d9ee2 Revert "[CSGen] Handle recursive use of variable declarations" 2023-02-10 16:45:59 -08:00
Pavel Yaskevich
83dd93ad2e [CSGen] Handle recursive use of variable declarations
It's possible for out-of-scope type variable to be the type of
declaration if such declaration is recursively referenced in
the body of a closure located in its initializer expression.
In such cases type of the variable declaration cannot be connected
to the closure because its not known in advance (determined by the
initializer itself).

Resolves: https://github.com/apple/swift/issues/63455
2023-02-07 17:48:26 -08:00
Pavel Yaskevich
65e7eec62f [CSSolver] Solve multi-statement closures in source order
Currently solver picks the first conjunction it can find,
which means - the earliest resolved closure. This is not
always correct because when calls are chained closures
passed to the lower members could be resolved sooner
than the ones higher up but at the same time they depend
on types inferred from members higher in the chain.

Let's make sure that multi-statement closures are always
solved in order they appear in the AST to make sure that
types are available to members lower in the chain.
2022-12-12 10:57:21 -08:00
Allan Shortlidge
74e55ef51f Test: Temporarily disable implicit_weak_capture.swift for back_deployment_runtime configs. 2022-11-10 18:21:21 -08:00
Andrew Trick
1ecf0a5586 implicit_weak_capture test requires Concurrency
Fixes rdar://101942652 (macOS 10.14.4) (Swift in the OS)
libswift_Concurrency; Symbol not found:
_swift_task_enterThreadLocalContext)
2022-11-03 19:35:47 -07:00
Cal Stephens
c081d56cf1 Add test case that implicit self in a weak closure doesn't result in a strong capture 2022-10-27 17:50:44 -07:00
Cal Stephens
8528021f0d Change lookup behavior in ASTScope::lookupUnqualified when self has been unwrapped 2022-10-26 20:38:43 -07:00
Cal Stephens
ebcc9c2b8b Revert "Disable SE-0365 behavior for escaping closues in Swift 5 mode"
This reverts commit f8ca2937a8.
2022-10-26 17:38:01 -07:00
Cal Stephens
f8ca2937a8 Disable SE-0365 behavior for escaping closues in Swift 5 mode 2022-10-22 09:15:09 -07:00
Cal Stephens
22e43136d9 Enable SE-0365 behavior in Swift 5.8 2022-10-10 08:03:03 -07:00
Pavel Yaskevich
1a79d93121 Merge pull request #40702 from calda/cal--implicit-weak-self
[SE-0365] Allow implicit self for `weak self` captures
2022-09-30 10:30:57 -07:00