Commit Graph

41 Commits

Author SHA1 Message Date
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
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
Freddy Kellison-Linn
aedf854e33 Follow ups for keypath function conversion PR 2024-02-03 13:41:22 -05: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
9cd9619a57 [CSBindings] Unwrap optionals from contextual function type used as a key path type
The key path is going to be implicitly wrapped into a contextual
optional type.

Resolves: rdar://72864716
Resolves: https://github.com/apple/swift/issues/56393
2023-12-08 15:08:17 -08:00
Pavel Yaskevich
cceef44379 [CSSimplify] Detect and diagnose invalid arguments for key path subscript 2023-11-22 21:05:06 -08: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
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
Amritpan Kaur
cb984791d6 [NFC] Move keypath diagnostic from general to keypath 2023-08-01 12:11:51 -07:00
Amritpan Kaur
59d26795c2 [Test] Add AnyKeyPath test and move keypath diagnostics 2023-08-01 12:11:27 -07:00
Amritpan Kaur
d5f0fff83c [Tests] Add and update tests 2023-07-26 20:32:30 -07:00
Amritpan Kaur
d6486e25eb Add test 2023-06-23 13:56:42 -07:00
Anthony Latsis
da8d035b0b Gardening: Migrate test suite to GH issues: Constraints (2/5) 2022-08-19 06:43:11 +03:00
Pavel Yaskevich
2bf05b96e5 [CSFix] Make it possible to diagnose keypath inference failure in ambiguous contexts
Resolves: rdar://85458997
2021-12-20 15:03:28 -08:00
Robert Widmann
592e90af9b Add Sugar for Variadics
We used to represent the interface type of variadic parameters directly
with ArraySliceType. This was awfully convenient for the constraint
solver since it could just canonicalize and open [T] to Array<$T>
wherever it saw a variadic parameter. However, this both destroys the
sugaring of T... and locks the representation to Array<T>. In the
interest of generalizing this in the future, introduce
VariadicSequenceType. For now, it canonicalizes to Array<T> just like
the old representation. But, as you can guess, this is a new staging
point for teaching the solver how to munge variadic generic type bindings.

rdar://81628287
2021-08-06 12:51:39 -07:00
Pavel Yaskevich
24b69f5c89 [TypeChecker] NFC: Add one more test-case for SR-13442 2020-11-10 16:04:48 -08:00
Luciano Almeida
7815ecf2a0 [CSApply] Handle OptionalForce component when is initial component on key path expr 2020-08-25 19:31:02 -03:00
Luciano Almeida
9371ef0573 [tests] Adding regression tests and for unwrapping base on key path application 2020-07-15 08:57:43 -03:00
Luciano Almeida
5cf230cf42 [tests] Adding regression tests to SR-11184 2020-07-12 13:47:02 -03:00
Holly Borla
77d0a40236 [NFC] Add a regression test for SR-12432 2020-04-29 10:24:50 -07:00
Luciano Almeida
fab4b876ee [tests] Adjusting key path tests to diagnostic of key path refering to init methods 2020-03-28 16:33:32 -03:00
Hamish Knight
b62c9b6b01 [CS] Use getParameterType for KeyPath as function
Previously we were using `getPlainType` to match
the parameter type against the key path's base
type. This gave us the external parameter type,
which would be the element type for a variadic
parameter.  However the code we generate expects
the internal parameter type, which is provided by
`getParameterType`.

Resolves rdar://problem/59445486.
2020-03-11 17:21:28 -07:00
Pavel Yaskevich
47c7b9b910 [Diagnostics] Upon keypath result contextual mismatch try to match object types
If there was a mismatch between last component type and contextual
key path result type, let's try to re-match the types with all optionals
stripped off. In cases where the problem is optionality difference
e.g. `[Int] vs. [Int]?` that propagates contextual information to
the last component which facilitates better diagnostics.

Resolves: rdar://problem/57843297
2019-12-13 00:50:54 -08:00
Holly Borla
e63f259f4f [ConstraintSystem] Bind holes to UnresolvedType instead of Any. 2019-11-05 09:15:13 -08:00
Brent Royal-Gordon
932128eab6 Fix SE-0249 source compatibility break
In some situations where both the KeyPath and closure solutions for an expression with a keypath literal were valid, the type checker could not choose between them and Swift would emit an “ambiguous use” error. This change increase the typechecking score of the closure solution so that the typechecker will favor the KeyPath solution, preserving source compatibility for existing APIs.

Fixes rdar://problem/56131416.
2019-10-09 17:17:41 -07:00
Doug Gregor
562ed4d999 [Constraint solver] Tie together all of the type variables in a key path.
This is a workaround for rdar://problem/54322807 that should limit the
expansion in the number of constraint scopes visited.
2019-08-20 11:11:07 -07:00
Greg Titus
cf047295d7 Coerce key path index expr to handle upcast correctly. 2019-08-18 18:44:34 -07:00
gregomni
469e06ae2c Update to HEAD, fix Param type changes, merging. 2019-08-06 07:52:56 -07:00
gregomni
bf3a786227 Add tests with no contextual type info. 2019-08-06 07:52:56 -07:00
gregomni
a2cd53d802 Handle simplification of optional-chaining key path literals, distinguish function type and keypath BGT type without explicit disjunctions. 2019-08-06 07:52:56 -07:00
Brent Royal-Gordon
ffe1684a8e Add typechecking tests 2019-08-06 07:52:56 -07:00
Sam Lazarus
64b1186cb7 Sema: Change closure passed to matchDeepTypeArguments to return if it recorded anything 2019-06-14 12:35:32 -04:00
Sam Lazarus
cd0cc3c2c4 Test: Add a todo about a regression introduced by generic mismatch diagnostic 2019-06-14 12:35:32 -04:00
gregomni
821f63fe98 Make assignments and assignment failure diagnoses directly in the CS.
More specific diagnoses for assigning to read-only keypaths.
'computeAssignDestType' is dead code now.
ConstraintFix shouldRecordFix()
2018-08-24 20:39:03 -07:00
gregomni
d604047625 When root type of a keypath is unresolved by the constraint system, use the root interface type for diagnosis. 2018-07-31 17:15:12 -07:00
Mark Lacey
fea720f229 [MiscDiagnostics] Emit a deprecation warning for some writes through literal keypaths.
We incorrectly allowed some keypaths to be inferred as writable
keypaths in Swift 3/4 modes. This no longer happens when
-swift-version 5 is specified.

This warning is a limited attempt at providing some advanced notice of
code that will break, only in the cases where the keypath is a direct
argument to a keypath subscript write.

Fixes: rdar://problem/40068274
2018-06-25 23:03:06 -07:00
Mark Lacey
9687615d58 Fix RUN lines in a couple constraint solver tests. 2018-06-19 12:57:05 -07:00
Mark Lacey
83ebd71644 Allowing forming WritableKeyPath to read-only value in Swift 3/4.
We inadvertantly allowed this in the past, so continue to do so when
compiling in Swift 3/4 mode to avoid suddenly breaking existing code.

The diagnostic here is pretty bad, and I've opened issues for that as
well as providing some kind of deprecation warning for this so that
even under Swift 3/4 mode we alert users that this is unsupported.

rdar://problem/39802797
2018-05-08 14:26:02 -07:00