Commit Graph

377 Commits

Author SHA1 Message Date
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
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
Pavel Yaskevich
61d3a9f786 [CSClosure] Always pre-check init targets of wrapped vars
If a variable with attached property wrapper has an initializer
expression it could be modified by implicit wrapper application,
if there is no initializer - one would be synthesized by the
compiler (without arguments). In both cases target has to be
pre-checked before constraints are generated for it.

Resolves: https://github.com/apple/swift/issues/61024
2022-09-12 16:08:36 -07:00
Pavel Yaskevich
3e791dd169 [CSClosure] Use correct type for implicit wrapper variables
Using `computeWrappedValueType` is incorrect because
that return a type of the wrapped variable and not
the *wrapper* variable (one that starts with `_`).

Resolves: https://github.com/apple/swift/issues/61017
2022-09-12 09:53:24 -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
Pavel Yaskevich
3ebc541fd5 [CSDiagnostics] Verify that member is in collection context
`MissingMemberFailure::diagnoseInLiteralCollectionContext`
should verify that a parent (or parent of a parent) expression
is indeed a collection expression instead of checking types.

Resolves: rdar://91452726
2022-08-17 12:12:27 -07: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
Anthony Latsis
4d3aa95d59 Add regression test to close #42790 2022-06-22 22:17:30 +03:00
Pavel Yaskevich
9c8bebe4f8 [CSClosure] Detect and diagnose conflicting pattern variables in case statements
Avoid mutating case label items while solving, instead let's use types
recorded in the constraint system for each pattern variable and use
that for var reference in the case body. This also helps to detect
and diagnose type conflicts while solving.
2022-06-03 16:35:18 -07:00
Pavel Yaskevich
1099cca050 Merge pull request #59238 from xedin/rdar-92757114-test
[CSClosure] NFC: Add a test-case for rdar://92757114
2022-06-03 16:28:04 -07:00
Pavel Yaskevich
c581497bd4 [CSClosure] NFC: Add a test-case for rdar://92757114
Used to produce a fallback `type of expression ...` diagnostic
2022-06-03 12:21:06 -07:00
Pavel Yaskevich
df1e38ff36 [TypeChecker] NFC: Add test-case for rdar://93061432 2022-05-30 23:17:41 -07:00
Pavel Yaskevich
953095a9ce [CSClosure] Perform syntactic checks on rewritten statements
Fix an oversight where syntactic checking was not performed on
any statements in a body of a multi-statement after successful
solution application.

Resolves: rdar://94049113
2022-05-27 14:51:27 -07:00
Pavel Yaskevich
4e9992c261 [CSClosure] Fix crash in fallthrough statement checking
`fallthrough` requires both source and destination `case`
"preambles" be type-checked before it could be validated,
which means that solution application for `case` statements
in a `switch` has to be split in two - preamble first and
bodies afterwards.

Resolves: https://github.com/apple/swift/issues/59035
Resolves: rdar://93796211
2022-05-24 14:20:42 -07:00
Pavel Yaskevich
0e8ece615f Merge pull request #58834 from xedin/var-finder-return-handling
[CSClosure] Fix per-element variable finder to correctly handle retur…
2022-05-18 18:02:14 -07:00
Pavel Yaskevich
569333135c Merge pull request #58768 from xedin/redecl-check-in-multi-closures
[CSClosure] Diagnose invalid re-declarations in multi-statement closures
2022-05-18 15:03:41 -07:00
Pavel Yaskevich
ddd7e495dd [CSClosure] Fix per-element variable finder to correctly handle return statements
Type finder is still allowed to walk into closures to find any
referenced variables, but it should bring external result type
into scope only if a particular `return` belongs to the same
closure as the element.
2022-05-18 13:52:34 -07:00
Pavel Yaskevich
dfadee3731 [CSDiagnostics] Attach missing member diagnostic to a pattern/statement
If missing member is found in e.g. case statement or a pattern,
let's attach diagnostic directly to it.
2022-05-18 00:28:08 -07:00
Pavel Yaskevich
854f64eff5 [CSClosure] Diagnose invalid re-declarations in multi-statement closures
Calling `typeCheckDecl` on `VarDecl` is what triggers re-declaration
checking and that was skipped by the solution application logic.
2022-05-09 12:50:39 -07:00
Pavel Yaskevich
67895c2927 [CSClosure] Mark partially inferred external declarations as invalid
If a syntactic element references an external declaration (relative
to its own context), let's check whether it has any type variables,
and if so, replace them with errors to remove any possibility of
bringing external constraints into element's scope.

Resolves: rdar://92347054
2022-05-05 11:44:26 -07: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
Hamish Knight
04bf10b497 Merge pull request #58524 from hamishknight/condtrail 2022-04-29 19:03:57 +01:00
Hamish Knight
c5a53ef73e [Sema] Don't warn on trailing closures in closure conditions
Add ClosureExpr to the list of expressions we don't
walk into for the purposes of diagnosing trailing
closures in conditional initializers.

rdar://92521618
2022-04-29 14:47:19 +01:00
Pavel Yaskevich
48e70ed6cc [ConstraintSystem] Fail ~= synthesis if constraint generation fails
If constraint generation for application of `~=` failed that should
result in an immediate synthesis failure.

Resolves: rdar://92366212
2022-04-28 18:02:19 -07:00
Pavel Yaskevich
6db0001863 [TypeChecker] NFC: Remove -experimental-multi-statement-closures flag
SE-0326 has been enabled by default, so this flag is no longer necessary.
2022-04-20 10:40:27 -07:00
Pavel Yaskevich
f7253f253e Merge pull request #42228 from xedin/enable-se-0347-by-default
[TypeChecker] SE-0347: Enable type inference from default expressions
2022-04-08 16:10:20 -07:00
Pavel Yaskevich
73e15c0c4d Merge pull request #42195 from xedin/rdar-91225620
[CSClosure] Handle wrapped variables without explicit initializers
2022-04-07 10:05:37 -07:00
Pavel Yaskevich
b03021dbb7 [TypeChecker] SE-0347: Enable type inference from default expressions 2022-04-06 15:03:00 -07:00
Pavel Yaskevich
869a413aae [CSClosure] Handle wrapped variables without explicit initializers
All variables without explicit initializers were considered to be
uninitialized which is incorrect because if a variable has a property
wrapper attached to it that wrapper needs its initializer type-checked,
for example:

```
@propertyWrapper
struct Wrapper {
  var name: String

  ...
}

test {
  @wrapper(name: "wrapper")
  var v;
}
```

`v` gets initialized via a call to `Wrapper(name: "wrapper")`.

Resolves: rdar://91225620
2022-04-06 14:36:31 -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
8506d9dd98 Merge pull request #42022 from hborla/default-argument-fixes
[ConstraintSystem] Only attempt to infer a type from a default argument if there is a non-null callee.
2022-03-25 12:01:30 -07:00
Holly Borla
0fdb9a38d2 [ConstraintSystem] Bail out of inference from default arguments if there
is no parameter list for the callee.

This can happen when the callee is a closure that has been assigned to
a variable.
2022-03-25 00:20:34 -07:00
Pavel Yaskevich
3c5a6f93e9 Merge pull request #41864 from xedin/improvements-for-diagnoseAmbiguity
[ConstraintSystem] Augment `diagnoseAmbiguity` to handle non-expression anchors
2022-03-21 10:00:19 -07:00
Pavel Yaskevich
ebdef12fe1 [ContraintSystem] Augment diagnoseAmbiguity to diagnose non-expression ambiguities
Since constraint solver can now handle statements, patterns, and declarations,
it's possible to that ambiguity could be detected in a non-expression context,
for example - pattern matching in switch statements. Augment `diagnoseAmbiguity`
to accept overloads with non-expression anchors and diagnose them in order of
their appearance in a solution.
2022-03-17 13:02:20 -07:00