Skip to content

Commit d911aad

Browse files
committed
Gardening: Migrate test suite to GH issues: expr/unary
1 parent 65663b0 commit d911aad

File tree

2 files changed

+94
-90
lines changed

2 files changed

+94
-90
lines changed

test/expr/unary/keypath/keypath.swift

Lines changed: 92 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ func testKeyPathOptional() {
480480
_ = \AA.c?.i
481481
_ = \AA.c!.i
482482

483-
// SR-6198
483+
// https://github.com/apple/swift/issues/48750
484484
let path: KeyPath<CC,Int>! = \CC.i
485485
let cc = CC()
486486
_ = cc[keyPath: path]
@@ -546,7 +546,8 @@ func testImplicitConversionInSubscriptIndex() {
546546
_ = \BassSubscript.["hello"] // expected-error{{must be Hashable}}
547547
}
548548

549-
// Crash in diagnostics + SR-11438
549+
// Crash in diagnostics + https://github.com/apple/swift/issues/53839
550+
550551
struct UnambiguousSubscript {
551552
subscript(sub: Sub) -> Int { get { } set { } }
552553
subscript(y y: Sub) -> Int { get { } set { } }
@@ -569,8 +570,8 @@ func useBothUnavailableSubscript(_ sub: Sub) {
569570
// expected-error@-1 {{'subscript(_:)' is unavailable}}
570571
}
571572

572-
// SR-6106
573-
func sr6106() {
573+
// https://github.com/apple/swift/issues/48661
574+
func f_48661() {
574575
class B {}
575576
class A {
576577
var b: B? = nil
@@ -583,8 +584,8 @@ func sr6106() {
583584
}
584585
}
585586

586-
// SR-6744
587-
func sr6744() {
587+
// https://github.com/apple/swift/issues/49293
588+
func f_49293() {
588589
struct ABC {
589590
let value: Int
590591
func value(adding i: Int) -> Int { return value + i }
@@ -597,7 +598,8 @@ func sr6744() {
597598
_ = get(for: \.value)
598599
}
599600

600-
func sr7380() {
601+
// https://github.com/apple/swift/issues/49928
602+
func f_49928() {
601603
_ = ""[keyPath: \.count]
602604
_ = ""[keyPath: \String.count]
603605

@@ -811,17 +813,20 @@ func test_keypath_with_method_refs() {
811813
let _ = \A.Type.faz.bar // expected-error {{key path cannot refer to static method 'faz()'}}
812814
}
813815

814-
// SR-12519: Compiler crash on invalid method reference in key path.
816+
// https://github.com/apple/swift/issues/54961
817+
// Compiler crash on invalid method reference in key path.
818+
815819
protocol Zonk {
816820
func wargle()
817821
}
818822
typealias Blatz = (gloop: String, zoop: Zonk?)
819823

820-
func sr12519(fleep: [Blatz]) {
824+
func f_54961(fleep: [Blatz]) {
821825
fleep.compactMap(\.zoop?.wargle) // expected-error {{key path cannot refer to instance method 'wargle()'}}
822826
}
823827

824-
// SR-10467 - Argument type 'KeyPath<String, Int>' does not conform to expected type 'Any'
828+
// https://github.com/apple/swift/issues/52867
829+
// Argument type 'KeyPath<String, Int>' does not conform to expected type 'Any'
825830
func test_keypath_in_any_context() {
826831
func foo(_: Any) {}
827832
foo(\String.count) // Ok
@@ -846,7 +851,8 @@ func test_keypath_inference_with_optionals() {
846851
}
847852
}
848853

849-
func sr11562() {
854+
// https://github.com/apple/swift/issues/53967
855+
func f_53967() {
850856
struct S1 {
851857
subscript(x x: Int) -> Int { x }
852858
}
@@ -874,22 +880,23 @@ func sr11562() {
874880
// expected-error@-1 {{subscript index of type '(Int, Int)' in a key path must be Hashable}}
875881
}
876882

877-
// SR-12290: Ban keypaths with contextual root and without a leading dot
878-
struct SR_12290 {
883+
// https://github.com/apple/swift/issues/54718
884+
// Ban keypaths with contextual root and without a leading dot.
885+
struct S_54718 {
879886
let property: [Int] = []
880-
let kp1: KeyPath<SR_12290, Int> = \property.count // expected-error {{a Swift key path with contextual root must begin with a leading dot}}{{38-38=.}}
881-
let kp2: KeyPath<SR_12290, Int> = \.property.count // Ok
882-
let kp3: KeyPath<SR_12290, Int> = \SR_12290.property.count // Ok
887+
let kp1: KeyPath<S_54718, Int> = \property.count // expected-error {{a Swift key path with contextual root must begin with a leading dot}}{{37-37=.}}
888+
let kp2: KeyPath<S_54718, Int> = \.property.count // Ok
889+
let kp3: KeyPath<S_54718, Int> = \S_54718.property.count // Ok
883890

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
887894

888-
func foo4<T>(_: KeyPath<SR_12290, T>) {}
895+
func foo4<T>(_: KeyPath<S_54718, T>) {}
889896
func useFoo4() {
890897
foo4(\property.count) // expected-error {{a Swift key path with contextual root must begin with a leading dot}}{{11-11=.}}
891898
foo4(\.property.count) // Ok
892-
foo4(\SR_12290.property.count) // Ok
899+
foo4(\S_54718.property.count) // Ok
893900
}
894901
}
895902

@@ -930,57 +937,51 @@ func testMissingMember() {
930937
_ = \String.x.y // expected-error {{value of type 'String' has no member 'x'}}
931938
}
932939

933-
// SR-5688
934-
struct SR5688_A {
935-
var b: SR5688_B?
936-
}
937-
938-
struct SR5688_AA {
939-
var b: SR5688_B
940-
}
940+
// https://github.com/apple/swift/issues/48258
941+
func testMemberAccessOnOptionalKeyPathComponent() {
942+
struct S1a {
943+
var b: S1b
944+
var b_opt: S1b?
945+
}
941946

942-
struct SR5688_B {
947+
struct S1b {
943948
var m: Int
944-
var c: SR5688_C?
945-
}
949+
var c: S1c?
950+
}
946951

947-
struct SR5688_C {
952+
struct S1c {
948953
var d: Int
949-
}
950-
951-
struct SR5688_S {
952-
subscript(_ x: Int) -> String? { "" }
953-
}
954-
955-
struct SR5688_O {
956-
struct Nested {
957-
var foo = ""
958954
}
959-
}
960955

961-
func SR5688_KP(_ kp: KeyPath<String?, Int>) {}
956+
_ = \S1a.b_opt.m
957+
// expected-error@-1 {{value of optional type 'S1b?' must be unwrapped to refer to member 'm' of wrapped base type 'S1b'}}
958+
// expected-note@-2 {{chain the optional using '?' to access member 'm' only for non-'nil' base values}} {{17-17=?}}
959+
// expected-note@-3 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}} {{17-17=!}}
960+
961+
_ = \S1a.b_opt.c.d
962+
// expected-error@-1 {{value of optional type 'S1b?' must be unwrapped to refer to member 'c' of wrapped base type 'S1b'}}
963+
// expected-note@-2 {{chain the optional using '?' to access member 'c' only for non-'nil' base values}} {{17-17=?}}
964+
// expected-error@-3 {{value of optional type 'S1c?' must be unwrapped to refer to member 'd' of wrapped base type 'S1c'}}
965+
// expected-note@-4 {{chain the optional using '?' to access member 'd' only for non-'nil' base values}} {{19-19=?}}
966+
// expected-note@-5 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}} {{19-19=!}}
967+
_ = \S1a.b_opt?.c.d
968+
// expected-error@-1 {{value of optional type 'S1c?' must be unwrapped to refer to member 'd' of wrapped base type 'S1c'}}
969+
// expected-note@-2 {{chain the optional using '?' to access member 'd' only for non-'nil' base values}} {{20-20=?}}
970+
971+
_ = \S1a.b.c.d
972+
// expected-error@-1 {{value of optional type 'S1c?' must be unwrapped to refer to member 'd' of wrapped base type 'S1c'}}
973+
// expected-note@-2 {{chain the optional using '?' to access member 'd' only for non-'nil' base values}} {{15-15=?}}
974+
// expected-note@-3 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}} {{15-15=!}}
962975

963-
func testMemberAccessOnOptionalKeyPathComponent() {
976+
struct S2 {
977+
subscript(_ x: Int) -> String? { get {} }
978+
}
964979

965-
_ = \SR5688_A.b.m
966-
// expected-error@-1 {{value of optional type 'SR5688_B?' must be unwrapped to refer to member 'm' of wrapped base type 'SR5688_B'}}
967-
// expected-note@-2 {{chain the optional using '?' to access member 'm' only for non-'nil' base values}} {{18-18=?}}
968-
// expected-note@-3 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}} {{18-18=!}}
969-
970-
_ = \SR5688_A.b.c.d
971-
// expected-error@-1 {{value of optional type 'SR5688_B?' must be unwrapped to refer to member 'c' of wrapped base type 'SR5688_B'}}
972-
// expected-note@-2 {{chain the optional using '?' to access member 'c' only for non-'nil' base values}} {{18-18=?}}
973-
// expected-error@-3 {{value of optional type 'SR5688_C?' must be unwrapped to refer to member 'd' of wrapped base type 'SR5688_C'}}
974-
// expected-note@-4 {{chain the optional using '?' to access member 'd' only for non-'nil' base values}} {{20-20=?}}
975-
// expected-note@-5 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}} {{20-20=!}}
976-
_ = \SR5688_A.b?.c.d
977-
// expected-error@-1 {{value of optional type 'SR5688_C?' must be unwrapped to refer to member 'd' of wrapped base type 'SR5688_C'}}
978-
// expected-note@-2 {{chain the optional using '?' to access member 'd' only for non-'nil' base values}} {{21-21=?}}
979-
980-
_ = \SR5688_AA.b.c.d
981-
// expected-error@-1 {{value of optional type 'SR5688_C?' must be unwrapped to refer to member 'd' of wrapped base type 'SR5688_C'}}
982-
// expected-note@-2 {{chain the optional using '?' to access member 'd' only for non-'nil' base values}} {{21-21=?}}
983-
// expected-note@-3 {{force-unwrap using '!' to abort execution if the optional value contains 'nil'}} {{21-21=!}}
980+
struct S3 {
981+
struct Nested {
982+
var foo = ""
983+
}
984+
}
984985

985986
\String?.count
986987
// expected-error@-1 {{value of optional type 'String?' must be unwrapped to refer to member 'count' of wrapped base type 'String'}}
@@ -990,23 +991,25 @@ func testMemberAccessOnOptionalKeyPathComponent() {
990991
// expected-error@-1 {{value of optional type 'Optional<String>' must be unwrapped to refer to member 'count' of wrapped base type 'String'}}
991992
// expected-note@-2 {{use unwrapped type 'String' as key path root}} {{4-20=String}}
992993

993-
\SR5688_S.[5].count
994+
\S2.[5].count
994995
// 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=!}}
997998

998999

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+
10031004
\(Int, Int)?.0
10041005
// expected-error@-1 {{value of optional type '(Int, Int)?' must be unwrapped to refer to member '0' of wrapped base type '(Int, Int)'}}
10051006
// 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=!.}}
10101013
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'}}
10111014
// expected-note@-1 {{chain the optional using '?.' to access unwrapped type member 'count'}} {{37-37=?.}}
10121015
// expected-note@-2 {{unwrap the optional using '!.' to access unwrapped type member 'count'}} {{37-37=!.}}
@@ -1051,8 +1054,8 @@ func testSyntaxErrors() {
10511054
_ = \A.a!;
10521055
}
10531056

1054-
// SR-14644
1055-
func sr14644() {
1057+
// https://github.com/apple/swift/issues/56996
1058+
func f_56996() {
10561059
_ = \Int.byteSwapped.signum() // expected-error {{invalid component of Swift key path}}
10571060
_ = \Int.byteSwapped.init() // expected-error {{invalid component of Swift key path}}
10581061
_ = \Int // expected-error {{key path must have at least one component}}
@@ -1061,8 +1064,9 @@ func sr14644() {
10611064
// expected-error@-1 {{expected member name following '.'}}
10621065
}
10631066

1064-
// SR-13364 - keypath missing optional crashes compiler: "Inactive constraints left over?"
1065-
func sr13364() {
1067+
// https://github.com/apple/swift/issues/55805
1068+
// Key-path missing optional crashes compiler: Inactive constraints left over?
1069+
func f_55805() {
10661070
let _: KeyPath<String?, Int?> = \.utf8.count // expected-error {{no exact matches in reference to property 'count'}}
10671071
// expected-note@-1 {{found candidate with type 'Int'}}
10681072
}
@@ -1139,14 +1143,14 @@ func test_partial_keypath_inference() {
11391143
}
11401144
}
11411145

1142-
// SR-14499
1143-
struct SR14499_A { }
1144-
struct SR14499_B { }
1146+
// https://github.com/apple/swift/issues/56854
1147+
func f_56854() {
1148+
struct S1 {}
1149+
struct S2 {}
11451150

1146-
func sr14499() {
1147-
func reproduceA() -> [(SR14499_A, SR14499_B)] {
1151+
func reproduceA() -> [(S1, S2)] {
11481152
[
1149-
(true, .init(), SR14499_B.init()) // expected-error {{cannot infer contextual base in reference to member 'init'}}
1153+
(true, .init(), S2.init()) // expected-error {{cannot infer contextual base in reference to member 'init'}}
11501154
]
11511155
.filter(\.0) // expected-error {{value of type 'Any' has no member '0'}}
11521156
// expected-note@-1 {{cast 'Any' to 'AnyObject' or use 'as!' to force downcast to a more specific type to access members}}
@@ -1155,9 +1159,9 @@ func sr14499() {
11551159
// expected-note@-1 2 {{cast 'Any' to 'AnyObject' or use 'as!' to force downcast to a more specific type to access members}}
11561160
}
11571161

1158-
func reproduceB() -> [(SR14499_A, SR14499_B)] {
1162+
func reproduceB() -> [(S1, S2)] {
11591163
[
1160-
(true, SR14499_A.init(), .init()) // expected-error {{cannot infer contextual base in reference to member 'init'}}
1164+
(true, S1.init(), .init()) // expected-error {{cannot infer contextual base in reference to member 'init'}}
11611165
]
11621166
.filter(\.0) // expected-error {{value of type 'Any' has no member '0'}}
11631167
// expected-note@-1 {{cast 'Any' to 'AnyObject' or use 'as!' to force downcast to a more specific type to access members}}
@@ -1166,7 +1170,7 @@ func sr14499() {
11661170
// expected-note@-1 2 {{cast 'Any' to 'AnyObject' or use 'as!' to force downcast to a more specific type to access members}}
11671171
}
11681172

1169-
func reproduceC() -> [(SR14499_A, SR14499_B)] {
1173+
func reproduceC() -> [(S1, S2)] {
11701174
[
11711175
(true, .init(), .init()) // expected-error 2 {{cannot infer contextual base in reference to member 'init'}}
11721176
]

test/expr/unary/keypath/salvage-with-other-type-errors.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extension A: K {
3232
// expected-note@-2 {{overloads for '+' exist with these partially matching parameter lists: (String, String)}}
3333
}
3434

35-
// SR-5034
35+
// https://github.com/apple/swift/issues/47610
3636

3737
struct B {
3838
let v: String
@@ -47,7 +47,7 @@ func f3() {
4747
B(v: "").f1(block: { _ in }).f2(keyPath: \B.v) // expected-error{{unable to infer type of a closure parameter '_' in the current context}}
4848
}
4949

50-
// SR-5375
50+
// https://github.com/apple/swift/issues/47949
5151

5252
protocol Bindable: class { }
5353

0 commit comments

Comments
 (0)