@@ -959,12 +959,18 @@ func testMemberAccessOnOptionalKeyPathComponent() {
959
959
// expected-note@-2 {{chain the optional using '?' to access member 'm' only for non-'nil' base values}} {{17-17=?}}
960
960
// expected-note@-3 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}} {{17-17=!}}
961
961
962
+ // FIXME(diagnostics): Ideally there should be two errors here - one for `b_opt` and one for `c` but since there is
963
+ // no contextual type it means that both `!` and `?` could work to reference `.d` and that creates ambiguity which
964
+ // is not possible to diagnose at the moment.
962
965
_ = \S1a . b_opt. c. d
963
966
// expected-error@-1 {{value of optional type 'S1b?' must be unwrapped to refer to member 'c' of wrapped base type 'S1b'}}
964
967
// expected-note@-2 {{chain the optional using '?' to access member 'c' only for non-'nil' base values}} {{17-17=?}}
968
+ let _: KeyPath < S1a , Int > = \S1a . b_opt. c. d
969
+ // expected-error@-1 {{value of optional type 'S1b?' must be unwrapped to refer to member 'c' of wrapped base type 'S1b'}}
970
+ // expected-note@-2 {{chain the optional using '?' to access member 'c' only for non-'nil' base values}} {{40-40=?}}
965
971
// expected-error@-3 {{value of optional type 'S1c?' must be unwrapped to refer to member 'd' of wrapped base type 'S1c'}}
966
- // expected-note@-4 {{chain the optional using '?' to access member 'd' only for non-'nil' base values}} {{19-19 =?}}
967
- // expected-note@-5 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}} {{19-19 =!}}
972
+ // expected-note@-4 {{chain the optional using '?' to access member 'd' only for non-'nil' base values}} {{42-42 =?}}
973
+ // expected-note@-5 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}} {{42-42 =!}}
968
974
_ = \S1a . b_opt? . c. d
969
975
// expected-error@-1 {{value of optional type 'S1c?' must be unwrapped to refer to member 'd' of wrapped base type 'S1c'}}
970
976
// expected-note@-2 {{chain the optional using '?' to access member 'd' only for non-'nil' base values}} {{20-20=?}}
@@ -1064,7 +1070,8 @@ func f_56996() {
1064
1070
func f_55805( ) {
1065
1071
let _: KeyPath < String ? , Int ? > = \. utf8. count
1066
1072
// expected-error@-1 {{key path root inferred as optional type 'String?' must be unwrapped to refer to member 'utf8' of unwrapped type 'String'}}
1067
- // expected-error@-2 {{key path value type 'Int' cannot be converted to contextual type 'Int?'}}
1073
+ // expected-error@-2 {{cannot assign value of type 'KeyPath<String?, Int>' to type 'KeyPath<String?, Int?>'}}
1074
+ // expected-note@-3 {{arguments to generic parameter 'Value' ('Int' and 'Int?') are expected to be equal}}
1068
1075
}
1069
1076
1070
1077
// rdar://74711236 - crash due to incorrect member access in key path
0 commit comments