You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// expected-error@-1 {{subscript index of type '(Int, Int)' in a key path must be Hashable}}
875
881
}
876
882
877
-
// SR-12290: Ban keypaths with contextual root and without a leading dot
878
-
structSR_12290{
883
+
// https://github.com/apple/swift/issues/54718
884
+
// Ban keypaths with contextual root and without a leading dot.
885
+
structS_54718{
879
886
letproperty:[Int]=[]
880
-
letkp1:KeyPath<SR_12290,Int>= \property.count // expected-error {{a Swift key path with contextual root must begin with a leading dot}}{{38-38=.}}
881
-
letkp2:KeyPath<SR_12290,Int>= \.property.count // Ok
882
-
letkp3:KeyPath<SR_12290,Int>= \SR_12290.property.count // Ok
887
+
letkp1:KeyPath<S_54718,Int>= \property.count // expected-error {{a Swift key path with contextual root must begin with a leading dot}}{{37-37=.}}
888
+
letkp2:KeyPath<S_54718,Int>= \.property.count // Ok
889
+
letkp3:KeyPath<S_54718,Int>= \S_54718.property.count // Ok
883
890
884
-
func foo1(_:KeyPath<SR_12290,Int>= \property.count){} // expected-error {{a Swift key path with contextual root must begin with a leading dot}}{{42-42=.}}
885
-
func foo2(_:KeyPath<SR_12290,Int>= \.property.count){} // Ok
886
-
func foo3(_:KeyPath<SR_12290,Int>= \SR_12290.property.count){} // Ok
891
+
func foo1(_:KeyPath<S_54718,Int>= \property.count){} // expected-error {{a Swift key path with contextual root must begin with a leading dot}}{{41-41=.}}
892
+
func foo2(_:KeyPath<S_54718,Int>= \.property.count){} // Ok
893
+
func foo3(_:KeyPath<S_54718,Int>= \S_54718.property.count){} // Ok
887
894
888
-
func foo4<T>(_:KeyPath<SR_12290,T>){}
895
+
func foo4<T>(_:KeyPath<S_54718,T>){}
889
896
func useFoo4(){
890
897
foo4(\property.count) // expected-error {{a Swift key path with contextual root must begin with a leading dot}}{{11-11=.}}
891
898
foo4(\.property.count) // Ok
892
-
foo4(\SR_12290.property.count) // Ok
899
+
foo4(\S_54718.property.count) // Ok
893
900
}
894
901
}
895
902
@@ -930,57 +937,51 @@ func testMissingMember() {
930
937
_ = \String.x.y // expected-error {{value of type 'String' has no member 'x'}}
// expected-error@-1 {{value of optional type 'Optional<String>' must be unwrapped to refer to member 'count' of wrapped base type 'String'}}
991
992
// expected-note@-2 {{use unwrapped type 'String' as key path root}} {{4-20=String}}
992
993
993
-
\SR5688_S.[5].count
994
+
\S2.[5].count
994
995
// expected-error@-1 {{value of optional type 'String?' must be unwrapped to refer to member 'count' of wrapped base type 'String'}}
995
-
// expected-note@-2 {{chain the optional using '?' to access member 'count' only for non-'nil' base values}}{{16-16=?}}
996
-
// expected-note@-3 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}{{16-16=!}}
996
+
// expected-note@-2 {{chain the optional using '?' to access member 'count' only for non-'nil' base values}}{{10-10=?}}
997
+
// expected-note@-3 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}{{10-10=!}}
997
998
998
999
999
-
\SR5688_O.Nested?.foo.count
1000
-
// expected-error@-1 {{value of optional type 'SR5688_O.Nested?' must be unwrapped to refer to member 'foo' of wrapped base type 'SR5688_O.Nested'}}
1001
-
// expected-note@-2 {{use unwrapped type 'SR5688_O.Nested' as key path root}}{{4-20=SR5688_O.Nested}}
1002
-
1000
+
\S3.Nested?.foo.count
1001
+
// expected-error@-1 {{value of optional type 'S3.Nested?' must be unwrapped to refer to member 'foo' of wrapped base type 'S3.Nested'}}
1002
+
// expected-note@-2 {{use unwrapped type 'S3.Nested' as key path root}}{{4-14=S3.Nested}}
1003
+
1003
1004
\(Int, Int)?.0
1004
1005
// expected-error@-1 {{value of optional type '(Int, Int)?' must be unwrapped to refer to member '0' of wrapped base type '(Int, Int)'}}
1005
1006
// expected-note@-2 {{use unwrapped type '(Int, Int)' as key path root}}{{4-15=(Int, Int)}}
1006
-
1007
-
SR5688_KP(\.count) // expected-error {{key path root inferred as optional type 'String?' must be unwrapped to refer to member 'count' of unwrapped type 'String'}}
1008
-
// expected-note@-1 {{chain the optional using '?.' to access unwrapped type member 'count'}} {{15-15=?.}}
1009
-
// expected-note@-2 {{unwrap the optional using '!.' to access unwrapped type member 'count'}} {{15-15=!.}}
1007
+
1008
+
func kp(_:KeyPath<String?,Int>){}
1009
+
1010
+
kp(\.count) // expected-error {{key path root inferred as optional type 'String?' must be unwrapped to refer to member 'count' of unwrapped type 'String'}}
1011
+
// expected-note@-1 {{chain the optional using '?.' to access unwrapped type member 'count'}} {{8-8=?.}}
1012
+
// expected-note@-2 {{unwrap the optional using '!.' to access unwrapped type member 'count'}} {{8-8=!.}}
1010
1013
let _ :KeyPath<String?,Int>= \.count // expected-error {{key path root inferred as optional type 'String?' must be unwrapped to refer to member 'count' of unwrapped type 'String'}}
1011
1014
// expected-note@-1 {{chain the optional using '?.' to access unwrapped type member 'count'}} {{37-37=?.}}
1012
1015
// expected-note@-2 {{unwrap the optional using '!.' to access unwrapped type member 'count'}} {{37-37=!.}}
@@ -1051,8 +1054,8 @@ func testSyntaxErrors() {
1051
1054
_ = \A.a!;
1052
1055
}
1053
1056
1054
-
// SR-14644
1055
-
funcsr14644(){
1057
+
// https://github.com/apple/swift/issues/56996
1058
+
funcf_56996(){
1056
1059
_ = \Int.byteSwapped.signum() // expected-error {{invalid component of Swift key path}}
1057
1060
_ = \Int.byteSwapped.init() // expected-error {{invalid component of Swift key path}}
1058
1061
_ = \Int // expected-error {{key path must have at least one component}}
@@ -1061,8 +1064,9 @@ func sr14644() {
1061
1064
// expected-error@-1 {{expected member name following '.'}}
0 commit comments