Avatar
Avatar
koher
伝播の実験 @swift-5.7.3 @rethrows protocol P { func foo() throws } @rethrows protocol Q { associatedtype PType1: P associatedtype PType2: P func makeP1() -> PType1 func makeP2() -> PType2 } struct S1: P { func foo() { print("S1") } } struct S2: P { func foo() throws { print("S2") } } struct T1: Q { func makeP1() -> S1 { S1() } func makeP2() -> S2 { S2() } } struct T2: Q { func makeP1() -> S2 { S2() } func makeP2() -> S1 { S1() } } func callFooOfP1<T: Q>(from q: T) rethrows { try q.makeP1().foo() } callFooOfP1(from: T1()) do { try callFooOfP1(from: T2()) } catch { print(error) }
exit status: 1 with stderr:<stdin>:48:1: error: call can throw but is not marked with 'try' callFooOfP1(from: T1()) ^~~~~~~~~~~~~~~~~~~~~~~ <stdin>:48:1: note: call is to 'rethrows' function, but a conformance has a throwing witness callFooOfP1(from: T1()) ^