Commit Graph

222 Commits

Author SHA1 Message Date
Cal Stephens
be0e68eca3 Add more test cases, simplify logic 2025-02-02 19:28:18 -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
Pavel Yaskevich
859106eed1 [Diagnostics] Expand trailing closure failure to handle all closure arguments 2024-01-08 14:09:18 -08: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
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
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
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
Cal Stephens
5bfdfd822c Only enable SE-0365 in Swift 6 2022-09-28 19:35:26 -07:00
Cal Stephens
cc92f76a9e Revert changes for handling SE-0365 in Swift 5
Revert "Remove properties from AST nodes"

This reverts commit e4b8a829fe.

Revert "Suppress more false-positive 'self is unused' warnings"

This reverts commit 35e028e5c2.

Revert "fix warning annotation in test"

This reverts commit dfa1fda3d3.

Revert "Permit implicit self for weak self captures in nonescaping closures in Swift 5 (this is an error in Swift 6)"

This reverts commit 94ef6c4ab4.
2022-09-28 17:44:02 -07:00
Cal Stephens
35e028e5c2 Suppress more false-positive 'self is unused' warnings 2022-09-26 09:28:22 -07:00
Cal Stephens
dfa1fda3d3 fix warning annotation in test 2022-09-25 16:19:57 -07:00
Cal Stephens
94ef6c4ab4 Permit implicit self for weak self captures in nonescaping closures in Swift 5 (this is an error in Swift 6) 2022-09-25 14:32:19 -07:00
Cal Stephens
9dd56f9daf Move remaining logic in LookupResultEntry::getBaseDecl() to ASTScope::lookupUnqualified impl, add more extensive tests, fix failing tests 2022-09-22 11:04:08 -07:00
Cal Stephens
9167a177cc Merge branch 'main' into cal--implicit-weak-self 2022-09-11 10:24:55 -07:00
Luciano Almeida
9e42002132 Merge pull request #60952 from LucianoPAlmeida/diag-closure 2022-09-06 13:15:57 -03:00
Luciano Almeida
7b82be5e2b [test] Opaque result is only available in 10.10 macos 2022-09-06 09:12:36 -03:00
Luciano Almeida
9c9af903bb [test] Add opaque result type cases 2022-09-05 10:29:16 -03:00
Luciano Almeida
7300fb5836 [Sema] Improve diagnostic for closure return contextual mismatch 2022-09-04 22:28:49 -03:00
Anthony Latsis
867472491f Merge pull request #60812 from AnthonyLatsis/migrate-test-suite-to-gh-issues-12
Gardening: Migrate test suite to GH issues p. 12
2022-09-02 06:06:53 +03:00
Luciano Almeida
109737551e [Sema] Handle non-function type parameters for closure arguments in ambiguity diagnositc 2022-08-27 20:42:19 -03:00
Anthony Latsis
6c615c8ead Gardening: Migrate test suite to GH issues: expr/closure 2022-08-27 05:26:00 +03:00
Alex Hoppen
e14fa7291f [CS] Don’t fail constraint generation for ErrorExpr or if type fails to resolve
Instead of failing constraint generation by returning `nullptr` for an `ErrorExpr` or returning a null type when a type fails to be resolved, return a fresh type variable. This allows the constraint solver to continue further and produce more meaningful diagnostics.

Most importantly, it allows us to produce a solution where previously constraint generation for a syntactic element had failed, which is required to type check multi-statement closures in result builders inside the constraint system.
2022-07-20 09:46:12 +02:00
Cal Stephens
778a2fc1f5 Merge branch 'main' into cal--implicit-weak-self 2022-07-18 10:00:23 -07:00
Luciano Almeida
11877d7a1b [Sema][Revert] Revert CTP to CTP_ReturnStmt for closure result in return stmt 2022-07-15 09:31:11 -03:00
Luciano Almeida
44f4eba6c5 [Sema] Add return context valid source loc to implicit tuple expr context for diagnostic 2022-07-11 20:57:54 -03:00
Josh Soref
92a1c4bc28 Spelling test expr (#58577)
* spelling: expressions

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: lousy

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: refers

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: should

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-05-04 14:16:58 -07:00
Evan Wilde
4c7e4615d9 Improve captured field diagnostics
This patch improves the error message emitted when the capture list
contains an item that is a sub-field of a struct/class/etc....

If the closure capture did not include `weak` at the beginning, the
presence of a period would cause the if-chain to fall through the
identifier checking, resulting in an error message about expecting a
`weak` keyword. Instead, I've opted to accept the period at that stage
of parsing so that we can fall through to a better error message.

For the following code
```
{ [self.field] in ... }
```
instead of emitting
`expected 'weak', 'unowned', or no specifier in capture list`,
we now emit
`fields may only be captured by assigning to a specific name`
with a fix-it that changes the code to
```
{ [ field = self.field ] in ... }
```
2022-04-01 18:23:00 -07:00
Pavel Yaskevich
5c3fb222e1 [CSClosure] Explode pattern binding declarations into conjunctions
`one-way` constraints disable some optimizations related to component
selection because they imply strict ordering. This is a problem for
multi-statement closures because variable declarations could involve
complex operator expressions that rely on aforementioned optimizations.

In order to fix that, let's move away from solving whole pattern binding
declaration into scheme that explodes such declarations into indvidual
elements and inlines them into a conjunction.

For example:

```
let x = 42, y = x + 1, z = (x, test())
```

Would result in a conjunction of three elements:

```
x = 42
y = x + 1
z = (x, test())
```

Each element is solved indepedently, which eliminates the need for
`one-way` constraints and re-enables component selection optimizations.
2022-03-08 21:37:40 -08:00
Pavel Yaskevich
966f58f044 [Tests] NFC: Adjust all the test-cases improved by multi-statement inference 2022-03-08 01:13:44 -08:00
Cal Stephens
369e20f64c Put back unused capture warnings 2021-12-26 14:29:38 -08:00
Cal Stephens
ccdf807211 Move weak self errors to their own file 2021-12-26 14:14:31 -08:00
Cal Stephens
20ed27a5c6 Tests pass, except for 'capture 'y' was never used' issue 2021-12-26 12:34:27 -08:00