Commit Graph

181 Commits

Author SHA1 Message Date
Hamish Knight
f95eb6bf48 [Sema] Tighten up function call check in resolveKeyPathExpr
Check for `CallExpr` instead of `ApplyExpr`, we don't support
arbitrary postfix operators in key paths.
2025-06-17 23:07:55 +01:00
Amritpan Kaur
3c30d68d2e Merge pull request #78823 from amritpan/method-keypaths
[Sema/SILGen/IRGen] Implement method & initializer keypaths.
2025-03-19 18:59:17 -07:00
Amritpan Kaur
98cd675eb9 Guard feature behind experimental flag. 2025-03-19 10:54:09 -07:00
Amritpan Kaur
15c219cd70 [Tests] Add tests. 2025-03-19 10:54:09 -07:00
Amritpan Kaur
78e7f6a72d [Tests] Update tests. 2025-03-19 10:54:09 -07:00
Pavel Yaskevich
db2b9f08d2 [Tests] NFC: Update and add a few test-cases related to noncopyable types in key path context 2025-03-18 13:47:00 -07:00
Daniel Rodríguez Troitiño
5abb1ea6ac [test] Remove some REQUIRES: for features not longer used in those files
While doing #76740 I iteratively was adding new `REQUIRES:` as new
usages of the features were found, but I did not realize that at the
same time other people might be removing some of those usages. The tests
in this commit had some `REQUIRES:` line for a previous
`-enable-experimental/upcoming-feature`, but they not longer use those
features, so the `REQUIRES:` were effectively disabling the tests (at
least in the case of `KeyPathWithStaticMembers`. In other cases they
might still had executed).
2024-11-04 20:53:07 -08:00
Allan Shortlidge
7b5757b29b Sema: Replace TypeChecker::checkDeclarationAvailability().
Adopt `getUnmetDeclAvailabilityRequirement()` instead.
2024-11-03 11:37:01 -08:00
Daniel Rodríguez Troitiño
ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.

Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).

All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.

There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
2024-11-02 11:46:46 -07:00
Pavel Yaskevich
5d77f3ca01 [Frontend] NFC: Remove KeyPathWithStaticMembers feature flag
This is a temporary way to land SE-0438 changes without disrupting
anything else.
2024-10-30 10:53:42 -07:00
Amritpan Kaur
2cb1088d08 [Test] Mark tests REQUIRES: asserts for KeyPathWithStaticMembers flag. 2024-09-29 23:06:18 -07:00
Amritpan Kaur
8ebc928649 Guard feature behind experimental flag. 2024-09-27 22:42:04 -07:00
Amritpan Kaur
2c641a8e50 [Tests] Update Sema tests. 2024-09-27 22:42:04 -07:00
Frederick Kellison-Linn
0d79f4523a Allow function-function conversions for keypath literals
Remove keypath subtype asserts; always use cached root type

Add tests for keypaths converted to funcs with inout param

Add unit test for overload selection
2024-01-23 08:51:44 -05:00
Pavel Yaskevich
e4f9965ff7 [ConstraintSystem] Fail key path capability inference if root is a placeholder
If root type of a key path has been determined to be a hole there
is no reason to delay the inference decision which should be a
failure because none of the components would be inferrable from
a placeholder root.
2024-01-01 12:48:31 -08:00
Pavel Yaskevich
f6254f7599 [ConstraintSystem] Support existential opening on key path subscript index 2023-11-17 15:49:31 -08:00
Pavel Yaskevich
9f21b95fcb [CSDiagnostics] A tailored diagnostic when passing key path as an argument to non-key path parameter
Produce a tailored diagnostic that omits a fully unresolved key path
type (`KeyPath<_, _>`) when key path without an explicit root type is
passed as an argument to non-keypath parameter type (i.e. `Int`).
2023-11-08 19:54:32 -08:00
Pavel Yaskevich
0a2f1b14a7 [CSBindings] Delay key path type inference until literal capability is known
Since key path root is now transitively inferred. Key path type
inference can be delayed until key path is resolved enough to
infer its capability.

This solves multiple problems:

- Inference fully controls what key path type is bound to;
- KeyPath constraint simplification doesn't have to double-check
  the capability and attempt to re-bind key path type;
- Custom logic to resolve key path type is no longer necessary;
- Diagnostics are improved because capability and root/value type
  mismatch are diagnosed when key path is matched against the
  contextual type.
2023-11-08 19:54:31 -08:00
Pavel Yaskevich
d066881243 [Tests] NFC: Adjust changed test-cases 2023-11-01 09:15:14 -07:00
Pavel Yaskevich
62d15cda1b [CSGen] Use a correct locator for subtype between explicit and inferred root types
Covariant conversions between explicit and contextual/inferred root
types of a key path are simulated through a subtype constraint which
has to be attached to a `KeyPathRoot` element.
2023-11-01 09:15:14 -07:00
Pavel Yaskevich
8b4985054a [CSDiagnostics] Differentiate between key path type and value issues
Make sure that contextual mismatch uses a correct locator when
the issue is with key path value type instead of the key path
type.
2023-11-01 09:15:14 -07:00
Pavel Yaskevich
b17ec0e385 [CSSimplify] Broaden delay of the key path assignment
If key path is connected to a disjunction directly or indirectly
(i.e. via ApplicableFunction constraint) do not attempt to bind
it until disjunction is taken, otherwise there is a risk to miss
a valid keypath-to-function conversion.
2023-10-06 17:47:10 -07:00
Pavel Yaskevich
6fd6c16bf7 [CSSimplify] Key path should use a default type is contextual type is a placeholder
If there is something wrong with the context, let's assign a default
KeyPath type to the key path literal to avoid propagating placeholder
into the key path inference.
2023-10-06 16:59:53 -07:00
Pavel Yaskevich
4830c5be9a [CSSimplify] Unwrap of key path root can only yield one type
For methods there are two possibilities - force unwrap and
conditional, that's why we need a disjunction with two choices.

This is not the case for key path root type it could only
be force unwrapped.
2023-10-06 16:14:01 -07:00
Pavel Yaskevich
0a9e960420 [CSDiagnostics] Don't suggest unwrapping a key path root without an explicit type
A key path without an explicit root cannot be unwrapped since the
optionality is inferred from context and we cannot suggest removing
that, adding explicit type is not going to change anything and
`!` and `?` after the leading dot is not supported.
2023-10-06 13:36:35 -07:00
Pavel Yaskevich
5a6c562b8c [CSSimplify] Adjust locators associated with keypath root/value matching constraints
`tryMatchRootAndValueFromType` anchored both root and value match
constraints directly on the key path expression. That is incorrect
because we have special locators for that.
2023-10-06 10:35:42 -07:00
Pavel Yaskevich
6a1783d48e [CSSimplify] Prevent overly eager solving of key path constraint
If key path literal is passed as an argument to a function/subscript
application its type cannot be resolved until the overload for the
call is selected, otherwise it could prevent a valid keypath-to-function
conversion in cases were argument ends up being a function type.
2023-10-05 17:10:47 -07:00
Pavel Yaskevich
5c83b18f64 [CSBindings] Infer key path types from superclass constrained existential values
If type of the key path expression is convertible to an existential
value with a superclass constraint represented as a known key path
type, we can use it to inform key path inference.

Resolves: rdar://93103421
2023-10-03 10:15:35 -07:00
Amritpan Kaur
6eadf2dce8 [Test] Update tests 2023-08-21 13:01:25 -07:00
Amritpan Kaur
366707d01b [Test] Update tests. 2023-08-16 14:28:08 -07:00
Amritpan Kaur
d5f0fff83c [Tests] Add and update tests 2023-07-26 20:32:30 -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
Allan Shortlidge
7dc313f1be NFC: Fix tests that mistakenly rely on unavailable stored properties.
Preparation for rdar://107449845
2023-04-04 08:52:39 -07:00
Pavel Yaskevich
6c5186f1ca [CSFix] Diagnose missing base type unwrap in ambiguous contexts 2023-03-06 10:17:51 -08:00
Anthony Latsis
d911aad234 Gardening: Migrate test suite to GH issues: expr/unary 2022-08-30 00:31:18 +03:00
Pavel Yaskevich
f3ff87b6f4 [Diagnostics] Diagnose re-labeling failures in ambiguity conditions
If all solutions point to the same overload choice that needs
re-labeling it's safe to diagnose it as if there was no ambiguity
because the call site is static.
2022-05-13 14:25:14 -07:00
Pavel Yaskevich
5331e276d5 Merge pull request #41730 from xedin/se-0326-solve-pattern-bindings-via-conjunctions
[SE-0326] Re-enable multi-statement closure inference by default
2022-03-15 13:21:03 -07:00
Pavel Yaskevich
966f58f044 [Tests] NFC: Adjust all the test-cases improved by multi-statement inference 2022-03-08 01:13:44 -08:00
Holly Borla
12459cff80 [Diagnostics] Print 'any' in diagnostic arguments. 2022-03-05 14:26:45 -08:00
Pavel Yaskevich
bc54bc6bb7 Revert "[TypeChecker] SE-0326: Enable multi-statement closure inference by default" 2021-11-29 17:26:08 -08:00
Pavel Yaskevich
63f355fde0 Merge pull request #39989 from xedin/more-diag-improvements-for-multi-stmt-closures
[TypeChecker] SE-0326: Enable multi-statement closure inference by default
2021-11-17 10:14:58 -08:00
Pavel Yaskevich
67d87e104f [Tests] NFC: Adjust all the test-cases improved by multi-statement inference 2021-11-15 16:42:06 -08:00
Hamish Knight
d6ac93efb1 [CS] Don't set parsed paths for dynamic member key paths
The logic here could form AST loops due to passing
in `anchor` for the key path's parsed path.

However setting a parsed path here seems to be a
holdover from the CSDiag days, so set the path to
`nullptr` and rip out and the rest of the synthesis
and SanitizeExpr logic for it.

rdar://85236369
2021-11-15 12:25:17 +00:00
Pavel Yaskevich
d21069b3e5 [ConstraintSystem] Propagate holes up to result of optional chaining
If underlying type of an optional chain has been marked as a hole,
e.g. due to a reference to an invalid or missing member, let's
propagate that information to object type of an optional that
represents a result of an optional chain.

Resolves: rdar://80941497
2021-09-10 21:32:51 -07:00
Pavel Yaskevich
ba1b67a1ee [TypeChecker] NFC: Add a couple test-cases of partial key path inference 2021-05-28 17:54:06 -07:00
Pavel Yaskevich
0c75593a04 [CSBindings] Fix inference of partial key path from conversion constraints
It's not permitted to use `PartialKeyPath` type to resolve a key path
expression, because that type is intended to be a type-erased version of
a fully resolved `KeyPath` type.

In situations where contextual type is a partial key path (e.g. parameter
type is a partial key path), let's replace it with a `KeyPath` type that
is a subtype of `PartialKeyPath` and allow value inference to happen.

Resolves: SR-5667
Resolves: rdar://32365183
2021-05-28 17:54:05 -07:00
Luciano Almeida
c6804668de Merge pull request #37521 from LucianoPAlmeida/SR-14644-keypath
[Sema][Diagnostics][SR-14644] Improving diagnostics for key path with invalid components
2021-05-20 11:53:00 -03:00
Luciano Almeida
9f42c6995b [tests] Add regression tests for SR-14644 2021-05-19 21:36:15 -03:00
Luciano Almeida
0b0279f169 [tests] Add regression tests for SR-14499 2021-05-18 09:09:12 -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