Avatar
Avatar
koher
throws を持つメソッドが複数あった場合、両方に働きそう。 @swift-5.7.3 @rethrows protocol P { func foo() throws func bar() throws } @rethrows protocol Q { associatedtype PType: P func makeP() -> PType } struct S1: P { func foo() { print("S1.foo") } func bar() { print("S1.bar") } } struct S2: P { func foo() throws { print("S2.foo") } func bar() throws { print("S2.bar") } } struct T1: Q { func makeP() -> S1 { S1() } } struct T2: Q { func makeP() -> S2 { S2() } } func callFoo<T: Q>(from q: T) rethrows { try q.makeP().foo() } callFoo(from: T1()) do { try callFoo(from: T2()) } catch { print(error) }
S1.foo S2.foo