File tree Expand file tree Collapse file tree 3 files changed +16
-4
lines changed
validation-test/Sema/SwiftUI Expand file tree Collapse file tree 3 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -7648,6 +7648,13 @@ ConstraintSystem::inferKeyPathLiteralCapability(KeyPathExpr *keyPath) {
7648
7648
if (keyPath->hasSingleInvalidComponent ())
7649
7649
return fail ();
7650
7650
7651
+ // If root is determined to be a hole it means that none of the components
7652
+ // are resolvable and key path is not viable.
7653
+ auto rootTy =
7654
+ getFixedTypeRecursive (getKeyPathRootType (keyPath), /* wantRValue=*/ false );
7655
+ if (rootTy->isPlaceholder ())
7656
+ return fail ();
7657
+
7651
7658
auto mutability = KeyPathMutability::Writable;
7652
7659
for (unsigned i : indices (keyPath->getComponents ())) {
7653
7660
auto &component = keyPath->getComponents ()[i];
Original file line number Diff line number Diff line change @@ -914,13 +914,13 @@ func testKeyPathHole() {
914
914
915
915
func f( _ i: Int ) { }
916
916
f ( \. x) // expected-error {{cannot infer key path type from context; consider explicitly specifying a root type}} {{6-6=<#Root#>}}
917
- // expected-error@-1 {{cannot convert value of key path type to expected argument type 'Int'}}
918
917
f ( \. x. y) // expected-error {{cannot infer key path type from context; consider explicitly specifying a root type}} {{6-6=<#Root#>}}
919
- // expected-error@-1 {{cannot convert value of key path type to expected argument type 'Int'}}
920
918
921
- func provideValueButNotRoot< T> ( _ fn: ( T ) -> String ) { }
919
+ func provideValueButNotRoot< T> ( _ fn: ( T ) -> String ) { } // expected-note 2 {{in call to function 'provideValueButNotRoot'}}
922
920
provideValueButNotRoot ( \. x) // expected-error {{cannot infer key path type from context; consider explicitly specifying a root type}}
921
+ // expected-error@-1 {{generic parameter 'T' could not be inferred}}
923
922
provideValueButNotRoot ( \. x. y) // expected-error {{cannot infer key path type from context; consider explicitly specifying a root type}}
923
+ // expected-error@-1 {{generic parameter 'T' could not be inferred}}
924
924
provideValueButNotRoot ( \String . foo) // expected-error {{value of type 'String' has no member 'foo'}}
925
925
926
926
func provideKPValueButNotRoot< T> ( _ kp: KeyPath < T , String > ) { }
@@ -1237,3 +1237,9 @@ func test_keypath_coercion_to_function() {
1237
1237
func test_keypath_application_with_composition( v: String, kp: any KeyPath< String, Int> & PP) {
1238
1238
_ = v [ keyPath: kp] // Ok
1239
1239
}
1240
+
1241
+ func test_leading_dot_key_path_without_context( ) {
1242
+ func test( _: AnyKeyPath ? ) { }
1243
+ test ( \. utf8)
1244
+ // expected-error@-1 {{cannot infer key path type from context; consider explicitly specifying a root type}}
1245
+ }
Original file line number Diff line number Diff line change @@ -16,7 +16,6 @@ extension EnvironmentValues {
16
16
set { self [ \. MyHorizontalAlignmentEnvironmentKey. self] = newValue }
17
17
// expected-error@-1 {{generic parameter 'K' could not be inferred}}
18
18
// expected-error@-2 {{cannot infer key path type from context; consider explicitly specifying a root type}}
19
- // expected-error@-3 {{cannot convert value of key path type to expected argument type 'K.Type'}}
20
19
}
21
20
}
22
21
You can’t perform that action at this time.
0 commit comments