Skip to content

Commit a70ef07

Browse files
committed
Sema: Add more rethrows test cases
1 parent f3c9b00 commit a70ef07

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

test/attr/attr_rethrows_protocol.swift

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,51 @@ func rethrowsWithThrowsClosure<T : ThrowsClosure>(_ t: T) rethrows {
115115

116116
try rethrowsWithThrowsClosure(ThrowsClosureWitness())
117117

118+
@rethrows protocol RethrowsClosure {
119+
func doIt() throws
120+
func doIt(_: () throws -> ()) rethrows
121+
}
122+
123+
struct RethrowsClosureWitness : RethrowsClosure {
124+
func doIt() {}
125+
func doIt(_: () throws -> ()) rethrows {}
126+
}
127+
128+
func rethrowsWithRethrowsClosure<T : RethrowsClosure>(_ t: T) rethrows {
129+
try t.doIt() {}
130+
}
131+
132+
try rethrowsWithRethrowsClosure(RethrowsClosureWitness())
133+
118134
// Empty protocol
119135
@rethrows protocol Empty {}
120136
struct EmptyWitness : Empty {}
121137

122138
func takesEmpty<T : Empty>(_: T) rethrows {}
123139

124-
takesEmpty(EmptyWitness())
140+
takesEmpty(EmptyWitness())
141+
142+
// FIXME: Fix this soundness hole
143+
144+
// Note: SimpleThrowsClosure is not @rethrows
145+
protocol SimpleThrowsClosure {
146+
func doIt(_: () throws -> ()) rethrows
147+
}
148+
149+
struct ConformsToSimpleThrowsClosure<T : RethrowingProtocol> : SimpleThrowsClosure {
150+
let t: T
151+
152+
// This cannot witness SimpleThrowsClosure.doIt(), because the
153+
// T : RethrowingProtocol conformance is a source here, but that
154+
// is not captured in the protocol's requirement signature.
155+
func doIt(_: () throws -> ()) rethrows {
156+
try t.source()
157+
}
158+
}
159+
160+
func soundnessHole<T : SimpleThrowsClosure>(_ t: T) {
161+
t.doIt {}
162+
}
163+
164+
// This actually can throw...
165+
soundnessHole(ConformsToSimpleThrowsClosure(t: Throws()))

0 commit comments

Comments
 (0)