Commit Graph

2502 Commits

Author SHA1 Message Date
Holly Borla
e1591314cf Merge pull request #37380 from hborla/property-wrapper-inference-crash
[ConstraintSystem] Fix a constraint system crash with property wrapper inference using the $ syntax.
2021-05-12 08:55:51 -07:00
Holly Borla
c297070106 [Diagnostics] Always use the parameter name for closure parameter diagnostics,
because the $ prefix does not indicate that the parameter is anonymous.
2021-05-11 18:30:27 -07:00
Pavel Yaskevich
c346bbd514 [Diagnostics] Point out where anonymous closure parameters are used in a multi-statement closure 2021-05-11 15:07:44 -07:00
Pavel Yaskevich
ddfaf80181 Merge pull request #37347 from xedin/rdar-77700261
[CSFix] Suppress ambiguity warning about non-`Optional` base with sta…
2021-05-11 10:13:14 -07:00
Pavel Yaskevich
2fdebccbd7 Merge pull request #37342 from xedin/rdar-77466241
[ResultBuilders] Diagnose pre-check errors inline
2021-05-10 15:53:26 -07:00
Pavel Yaskevich
a3fe65d87e [CSFix] Suppress ambiguity warning about non-Optional base with static member lookup
Disable non-Optional "assumption" warning for ambiguities related to a
static member lookup in generic context because it's possible to declare
a member with the same name on a concrete type and in an extension of a
protocol that type conforms to e.g.:

```swift
struct S : P { static var test: S { ... }

extension P where Self == S { static var test: { ... } }
```

And use that in an optional context e.g. passing `.test`
to a parameter of expecting `S?`.

Resolves: rdar://77700261
2021-05-10 12:52:26 -07:00
Pavel Yaskevich
4b0d9a2509 [ResultBuilders] Diagnose pre-check errors inline
Not all of the pre-check errors could be diagnosed by re-running
`PreCheckExpression` e.g. key path expressions are mutated to
a particular form after an error has been produced.

To make the behavior consistent, let's allow pre-check to emit
diagnostics and unify pre-check and constraint generation fixes.

Resolves: rdar://77466241
2021-05-10 11:06:58 -07:00
Pavel Yaskevich
c9eac2215a Merge pull request #37292 from xedin/rdar-77022842
[CSBindings] Don't infer subtypes/supertype bindings for a closure type
2021-05-07 10:41:06 -07:00
Pavel Yaskevich
3c0388d945 [CSBindings] Don't infer subtypes/supertype bindings for a closure type
A type representing a closure expression is always bound to its
"inferred" type based on the body, so contextual bindings just
serve as a trigger to "resolve" a closure. Let's not attempt any
subtype/supertype inference for a type variable representing a
closure since if "direct" bindings have failed, it wouldn't be bound
to such types regardless.

Resolves: rdar://problem/77022842
2021-05-06 13:35:45 -07:00
Pavel Yaskevich
29cb7ddbcb [Diagnostics] Handle ambiguities related to use of nil literal
When `nil` is passed as an argument to call with multiple overloads
it's possible that this would result in ambiguity where matched
expected argument type doesn't conform to `ExpressibleByNilLiteral`.

To handle situations like this locator for contextual mismatch
has to be adjusted to point to the call where `nil` is used, so
`diagnoseAmbiguityWithFixes` can identify multiple overloads and
produce a correct ambiguity diagnostic.

Resolves: rdar://75514153
2021-05-05 12:56:25 -07:00
Pavel Yaskevich
3b54fdb7f6 [TypeChecker] NFC: Add a test-case for expression affected by rdar://61749633 2021-05-04 14:58:41 -07:00
Pavel Yaskevich
46bc3b672d Merge pull request #37115 from xedin/disable-only-in-perf
[CSSimplify] Allow overload choices with missing labels to be considered for diagnostics
2021-04-29 10:25:16 -07:00
Pavel Yaskevich
f36ecf2fa1 [CSSimplify] Allow overload choices with missing labels to be considered for diagnostics
Let's make use of a newly added "disable for performance" flag to
allow solver to consider overload choices where the only issue is
missing one or more labels - this makes it for a much better
diagnostic experience without any performance impact for valid code.
2021-04-28 12:04:57 -07:00
Pavel Yaskevich
40a32dc39a [TypeChecker] NFC: Add a test-case for rdar://77233864 2021-04-27 15:57:55 -07:00
Evan Wilde
d0d9bef703 Merge pull request #37056 from etcwilde/ewilde/fix-await-fixits
[Concurrency] Fix await fix-it placement
2021-04-26 08:12:50 -07:00
Luciano Almeida
b851974424 [Sema] Do not attempt warn extraneous checked cast for placeholder types 2021-04-24 23:52:58 -03:00
Evan Wilde
3da0a540eb Update tests
This patch updates all the tests to accept the new error messages.
*Gack* so many things needed cleaning up.
2021-04-24 07:51:18 -07:00
Luciano Almeida
00c25317ea Merge pull request #36883 from LucianoPAlmeida/SR-13483-closure-args
[SR-13483][Sema] Make sure to record the correct remove args fix when repairing a tuple destructure attempt
2021-04-16 08:34:07 -03:00
Luciano Almeida
f40b9b6c29 [Sema] Minor adjusting on RemoveExtraneousArguments record logic 2021-04-15 20:33:46 -03:00
Pavel Yaskevich
2de9053dae [Diagnostics] Filter operators if all their arguments are holes
Restrict filtering in `simplifyAppliedOverloadsImpl` to disable
overload set for operators only, because other calls e.g. regular
functions or subscripts could be filtered on labels and are less
overloaded.

Filtering non-operator calls could also lead to incorrect diagnostics
because first choice could have all sorts of different issues e.g.
incorrect labels and number of parameters.

Resolves: rdar://55369704
2021-04-14 15:44:13 -07:00
Luciano Almeida
c1f43c8cc6 [tests] [SR-12483] Adding regression tests 2021-04-14 09:29:08 -03:00
Luciano Almeida
3d784687e4 [Sema] Adding a space in closure parameter destructuring fix in cases closure body is empty to avoid invalid inlet code 2021-04-13 23:46:54 -03:00
Pavel Yaskevich
b088aea88b [ConstraintSystem] Allow fixing r-value -> l-value mismatch without a fix for placeholders
If left-hand side of a conversion that requires l-value is a placeholder type,
let's fix that by propagating placeholder to the order side (to allow it to
infer a placeholder if needed) without recording a fix since placeholder can
be converted to `inout` and/or l-value and already indicates existence of a
problem at some other spot in the expression.

Resolves: rdar://76250381
2021-04-12 17:14:07 -07:00
Pavel Yaskevich
ceeee459b4 Merge pull request #36631 from xedin/conformance-perf-experiment
[Perf][CSSimplify] Transfer conformance requirements of a parameter to an argument
2021-04-12 13:13:56 -07:00
Pavel Yaskevich
ba1fc170bd Merge pull request #36845 from xedin/allow-double-cgfloat-with-one-side-is-optional
[TypeChecker] Allow Double<->CGFloat conversion with optional promotions
2021-04-12 13:10:20 -07:00
Pavel Yaskevich
f481a81458 Merge pull request #36854 from xedin/detect-error-exprs-in-result-builders
[Diagnostics] Allow result build to detect `ErrorExpr`s in the body
2021-04-12 10:32:02 -07:00
Pavel Yaskevich
22a231e4d8 [Diagnostics] Allow result build to detect ErrorExprs in the body
We assume that presence of `ErrorExpr` means that the problem has
been diagnosed early (i.e. by parser), so the fix is going to return
`true` if diagnostic engine has emitted an error.

Resolves: rdar://76246526
2021-04-09 16:42:59 -07:00
Pavel Yaskevich
c10f04d241 [TypeChecker] Allow Double<->CGFloat conversion with optional promotions
There are APIs that expect a `Double?` or `CGFloat?` argument
and it should be possible to pass `CGFloat` and `Double` respectively.
2021-04-09 12:04:34 -07:00
Pavel Yaskevich
4f19ba2c2a [CSSimplify] Teach transitive conformance check about Unsafe{Mutable}RawPointer conversions 2021-04-09 10:27:17 -07:00
Mishal Shah
22f61df98b Use %target-cpu in the tests to support running on Apple Silicon hardware 2021-04-08 23:26:18 -07:00
Pavel Yaskevich
2137e1bafd [TypeChecker] NFC: Add a test-case to test condition requirements interaction with transitive conformance checks 2021-04-08 16:02:32 -07:00
Pavel Yaskevich
ea9539d47f [CSSimplify] Add AnyHashable check to simplifyTransitivelyConformsTo
Just like `Optional` and `UnsafePointer` argument could be implicitly
converted to `AnyHashable`.
2021-04-08 13:41:25 -07:00
Pavel Yaskevich
dd67132fd9 Merge pull request #36793 from xedin/rdar-52204608
[Diagnostics] Contextual mismatch should be attached to the closure i…
2021-04-07 14:07:56 -07:00
Pavel Yaskevich
df8113b5dd [Diagnostics] Contextual mismatch should be attached to the closure if its body is empty/implicit
If there is a contextual mismatch associated with a closure body,
make sure that the diagnostic is attached to the closure even
if the body is empty or implicit.

Resolves: rdar://52204608
2021-04-07 10:06:34 -07:00
Pavel Yaskevich
583d617254 Merge pull request #36786 from xedin/partial-note-crash-objc-optionals
[Diagnostics] Fix crash while trying to print candidates for a option…
2021-04-07 10:04:48 -07:00
Pavel Yaskevich
c7a8b561aa Merge pull request #36756 from xedin/rdar-64425653
[TypeChecker] NFC: Run `Constraints/dynamic_lookup.swift` on all supp…
2021-04-07 10:04:07 -07:00
Pavel Yaskevich
a16d557fd0 [Diagnostics] Fix crash while trying to print candidates for a optional @objc method reference 2021-04-06 16:20:57 -07:00
Pavel Yaskevich
6080a40cff [TypeChecker] NFC: Run Constraints/dynamic_lookup.swift on all supported platforms
Resolves: rdar://64425653
2021-04-05 17:31:58 -07:00
Doug Gregor
fcd5d43457 Revert "stdlib: Add reasync variants of '&&', '||' and '??'" 2021-04-05 16:45:44 -07:00
Pavel Yaskevich
1d8c2a10c6 Merge pull request #36545 from xedin/rdar-75476311
[ConstraintSystem] Bind external closure parameter type to a concrete…
2021-04-05 10:04:42 -07:00
Slava Pestov
f190e51f8d GSB: Diagnose redundant superclass requirements using the redundant requirement graph 2021-04-03 22:33:14 -04:00
Pavel Yaskevich
225e2dbeed [ConstraintSystem] Bind external closure parameter type to a concrete contextual type
Performance optimization.

If there is a concrete contextual type we could use, let's bind
it to the external type right away because internal type has to
be equal to that type anyway (through `BindParam` on external type
i.e. <internal> bind param <external> conv <concrete contextual>).

```swift
func test(_: ([String]) -> Void) {}

test { $0 == ["a", "b"] }
```

Without this optimization for almost all overloads of `==`
expect for one on `Equatable` and one on `Array` solver would
have to repeatedly try the same `[String]` type for `$0` and
fail, which does nothing expect hurts performance.

Resolves: rdar://19836070
Resolves: rdar://19357292
Resolves: rdar://75476311
2021-04-02 22:11:03 -07:00
Pavel Yaskevich
ce135e6204 Merge pull request #36691 from xedin/a-couple-of-tests
[TypeChecker] NFC: Add a couple of tests for inference with optional/…
2021-04-02 00:46:40 -07:00
Pavel Yaskevich
ae8efa38d5 [TypeChecker] NFC: Add a couple of tests for inference with optional/pointer promotion 2021-03-31 17:26:24 -07:00
Slava Pestov
c473869141 stdlib: Add reasync variants of '&&', '||' and '??'
Fixes rdar://problem/72770687.
2021-03-31 19:21:08 -04:00
Pavel Yaskevich
8e401d2413 Merge pull request #36657 from xedin/rdar-75978086
[CSBindings] A couple of adjustments to transitive protocol inference
2021-03-31 12:31:13 -07:00
Pavel Yaskevich
f00c578761 Merge pull request #34401 from xedin/implicit-cgfloat-conversion
[DNM][TypeChecker] Implement Double <-> CGFloat implicit conversion
2021-03-31 10:20:28 -07:00
Pavel Yaskevich
a075459f21 [TypeChecker] NFC: Add test-case for rdar://75978086 2021-03-30 13:39:18 -07:00
Pavel Yaskevich
a51e3da285 [CSGen] Avoid failing due to invalid explicit closure parameters
If closure parameter has an explicit type, type resolution
would diagnose the issue and cache the resulting error type for
future use. Invalid types currently fail constraint generation,
which doesn't play well with result builders because constraint
generation for their bodies happens during solving.

Let's handle invalid parameters gracefully, replace them with
placeholders and let constraint generation proceed.

Resolves: rdar://75409111
2021-03-26 10:38:18 -07:00
Pavel Yaskevich
84857b6374 [PreCheck] Remove closure parameter validation
This is no longer necessary since parameter type would be validated
during constraint generation.
2021-03-25 14:34:24 -07:00