// RUN: %target-typecheck-verify-swift // Check that all combinations of key paths produce the expected result type // and choose the expected overloads. #if BUILDING_OUTSIDE_STDLIB import Swift #endif func expect(_: inout T, is: T.Type) {} func wellTypedAppends(readOnlyLeft: KeyPath, writableLeft: WritableKeyPath, referenceLeft: ReferenceWritableKeyPath, readOnlyRight: KeyPath, writableRight: WritableKeyPath, referenceRight: ReferenceWritableKeyPath){ var a = readOnlyLeft.appending(path: readOnlyRight) expect(&a, is: KeyPath.self) var b = readOnlyLeft.appending(path: writableRight) expect(&b, is: KeyPath.self) var c = readOnlyLeft.appending(path: referenceRight) expect(&c, is: ReferenceWritableKeyPath.self) var d = writableLeft.appending(path: readOnlyRight) expect(&d, is: KeyPath.self) var e = writableLeft.appending(path: writableRight) expect(&e, is: WritableKeyPath.self) var f = writableLeft.appending(path: referenceRight) expect(&f, is: ReferenceWritableKeyPath.self) var g = referenceLeft.appending(path: readOnlyRight) expect(&g, is: KeyPath.self) var h = referenceLeft.appending(path: writableRight) expect(&h, is: ReferenceWritableKeyPath.self) var i = referenceLeft.appending(path: referenceRight) expect(&i, is: ReferenceWritableKeyPath.self) } func mismatchedAppends(readOnlyLeft: KeyPath, writableLeft: WritableKeyPath, referenceLeft: ReferenceWritableKeyPath, readOnlyRight: KeyPath, writableRight: WritableKeyPath, referenceRight: ReferenceWritableKeyPath){ _ = readOnlyRight.appending(path: readOnlyLeft) // expected-error@-1 {{cannot convert value of type 'KeyPath' to expected argument type 'KeyPath'}} // expected-note@-2 {{arguments to generic parameter 'Root' ('T' and 'V') are expected to be equal}} _ = readOnlyRight.appending(path: writableLeft) // expected-error@-1 {{cannot convert value of type 'KeyPath' to expected argument type 'KeyPath'}} // expected-note@-2 {{arguments to generic parameter 'Root' ('T' and 'V') are expected to be equal}} _ = readOnlyRight.appending(path: referenceLeft) // expected-error@-1 {{no exact matches in call to instance method 'appending'}} _ = writableRight.appending(path: readOnlyLeft) // expected-error@-1 {{instance method 'appending(path:)' requires that 'KeyPath' inherit from 'KeyPath'}} _ = writableRight.appending(path: writableLeft) // expected-error@-1 {{cannot convert value of type 'WritableKeyPath' to expected argument type 'WritableKeyPath'}} // expected-note@-2 {{arguments to generic parameter 'Root' ('T' and 'V') are expected to be equal}} _ = writableRight.appending(path: referenceLeft) // expected-error@-1 {{no exact matches in call to instance method 'appending'}} _ = referenceRight.appending(path: readOnlyLeft) // expected-error@-1 {{instance method 'appending(path:)' requires that 'KeyPath' inherit from 'KeyPath'}} _ = referenceRight.appending(path: writableLeft) // expected-error@-1 {{cannot convert value of type 'WritableKeyPath' to expected argument type 'WritableKeyPath'}} // expected-note@-2 {{arguments to generic parameter 'Root' ('T' and 'V') are expected to be equal}} _ = referenceRight.appending(path: referenceLeft) // expected-error@-1 {{cannot convert value of type 'WritableKeyPath' to expected argument type 'WritableKeyPath'}} // expected-note@-2 {{arguments to generic parameter 'Root' ('T' and 'V') are expected to be equal}} } func partialAppends(partial: PartialKeyPath, concrete: KeyPath, reference: ReferenceWritableKeyPath, any: AnyKeyPath) { var a = any.appending(path: any) expect(&a, is: Optional.self) var b = any.appending(path: partial) expect(&b, is: Optional.self) var c = any.appending(path: concrete) expect(&c, is: Optional.self) var d = any.appending(path: reference) expect(&d, is: Optional.self) var e = partial.appending(path: any) expect(&e, is: Optional>.self) var f = partial.appending(path: partial) expect(&f, is: Optional>.self) var g = partial.appending(path: concrete) expect(&g, is: Optional>.self) var h = partial.appending(path: reference) expect(&h, is: Optional>.self) /* TODO var i = concrete.appending(path: any) expect(&i, is: Optional>.self) var j = concrete.appending(path: partial) expect(&j, is: Optional>.self) var m = reference.appending(path: any) expect(&m, is: Optional>.self) var n = reference.appending(path: partial) expect(&n, is: Optional>.self) */ }