Skip to content

Commit af370f1

Browse files
[test] Add regression tests for SR-14096
1 parent 0bca6ce commit af370f1

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

test/expr/unary/keypath/keypath.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,7 @@ func test_keypath_with_method_refs() {
795795
}
796796

797797
let _: KeyPath<S, Int> = \.foo // expected-error {{key path cannot refer to instance method 'foo()'}}
798+
// expected-error@-1 {{key path value type '() -> Int' cannot be converted to contextual type 'Int'}}
798799
let _: KeyPath<S, Int> = \.bar // expected-error {{key path cannot refer to static member 'bar()'}}
799800
let _ = \S.Type.bar // expected-error {{key path cannot refer to static method 'bar()'}}
800801

@@ -1094,3 +1095,19 @@ func rdar74711236() {
10941095
}()
10951096
}
10961097
}
1098+
1099+
extension String {
1100+
var filterOut : (Self) throws -> Bool {
1101+
{ $0.contains("a") }
1102+
}
1103+
}
1104+
1105+
func test_kp_as_function_mismatch() {
1106+
let a : [String] = [ "asd", "bcd", "def" ]
1107+
1108+
let _ : (String) -> Bool = \.filterOut // expected-error{{key path value type '(String) throws -> Bool' cannot be converted to contextual type 'Bool'}}
1109+
_ = a.filter(\.filterOut) // expected-error{{key path value type '(String) throws -> Bool' cannot be converted to contextual type 'Bool'}}
1110+
let _ : (String) -> Bool = \String.filterOut // expected-error{{key path value type '(String) throws -> Bool' cannot be converted to contextual type 'Bool'}}
1111+
_ = a.filter(\String.filterOut) // expected-error{{key path value type '(String) throws -> Bool' cannot be converted to contextual type 'Bool'}}
1112+
1113+
}

0 commit comments

Comments
 (0)