Skip to content

[NFC][tests] Add regression tests for SR-14499 #37471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions test/expr/unary/keypath/keypath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1111,3 +1111,42 @@ func test_kp_as_function_mismatch() {
_ = a.filter(\String.filterOut) // expected-error{{key path value type '(String) throws -> Bool' cannot be converted to contextual type 'Bool'}}

}

// SR-14499
struct SR14499_A { }
struct SR14499_B { }

func sr14499() {
func reproduceA() -> [(SR14499_A, SR14499_B)] {
[
(true, .init(), SR14499_B.init()) // expected-error {{cannot infer contextual base in reference to member 'init'}}
]
.filter(\.0) // expected-error {{value of type 'Any' has no member '0'}}
// expected-note@-1 {{cast 'Any' to 'AnyObject' or use 'as!' to force downcast to a more specific type to access members}}
.prefix(3)
.map { ($0.1, $0.2) } // expected-error {{value of type 'Any' has no member '1'}} expected-error{{value of type 'Any' has no member '2'}}
// expected-note@-1 2 {{cast 'Any' to 'AnyObject' or use 'as!' to force downcast to a more specific type to access members}}
}

func reproduceB() -> [(SR14499_A, SR14499_B)] {
[
(true, SR14499_A.init(), .init()) // expected-error {{cannot infer contextual base in reference to member 'init'}}
]
.filter(\.0) // expected-error {{value of type 'Any' has no member '0'}}
// expected-note@-1 {{cast 'Any' to 'AnyObject' or use 'as!' to force downcast to a more specific type to access members}}
.prefix(3)
.map { ($0.1, $0.2) } // expected-error {{value of type 'Any' has no member '1'}} expected-error{{value of type 'Any' has no member '2'}}
// expected-note@-1 2 {{cast 'Any' to 'AnyObject' or use 'as!' to force downcast to a more specific type to access members}}
}

func reproduceC() -> [(SR14499_A, SR14499_B)] {
[
(true, .init(), .init()) // expected-error 2 {{cannot infer contextual base in reference to member 'init'}}
]
.filter(\.0) // expected-error {{value of type 'Any' has no member '0'}}
// expected-note@-1 {{cast 'Any' to 'AnyObject' or use 'as!' to force downcast to a more specific type to access members}}
.prefix(3)
.map { ($0.1, $0.2) } // expected-error {{value of type 'Any' has no member '1'}} expected-error{{value of type 'Any' has no member '2'}}
// expected-note@-1 2 {{cast 'Any' to 'AnyObject' or use 'as!' to force downcast to a more specific type to access members}}
}
}