Skip to content

Commit 5246fef

Browse files
committed
Sema: Conformance witnesses that only rethrow via closure arguments don't contribute
1 parent e2d4eb6 commit 5246fef

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,23 +137,35 @@ static bool classifyWitness(ModuleDecl *module,
137137
auto declRef = conformance->getWitnessDeclRef(req);
138138
auto witnessDecl = cast<AbstractFunctionDecl>(declRef.getDecl());
139139
switch (witnessDecl->getRethrowingKind()) {
140+
case FunctionRethrowingKind::None:
141+
// Witness doesn't throw at all, so it contributes nothing.
142+
return false;
143+
140144
case FunctionRethrowingKind::ByConformance: {
145+
// Witness throws if the concrete type's @rethrows conformances
146+
// recursively throw.
141147
auto substitutions = conformance->getSubstitutions(module);
142148
for (auto conformanceRef : substitutions.getConformances()) {
143149
if (conformanceRef.classifyAsThrows()) {
144150
return true;
145151
}
146152
}
147-
break;
153+
return false;
148154
}
149-
case FunctionRethrowingKind::None:
150-
break;
155+
156+
case FunctionRethrowingKind::ByClosure:
157+
// Witness only throws if a closure argument throws, so it
158+
// contributes nothng.
159+
return false;
160+
151161
case FunctionRethrowingKind::Throws:
162+
// Witness always throws.
152163
return true;
153-
default:
164+
165+
case FunctionRethrowingKind::Invalid:
166+
// If the code is invalid, just assume it throws.
154167
return true;
155168
}
156-
return false;
157169
}
158170

159171
bool

test/attr/attr_rethrows_protocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func rethrowsWithRethrowsClosure<T : RethrowsClosure>(_ t: T) rethrows {
129129
try t.doIt() {}
130130
}
131131

132-
try rethrowsWithRethrowsClosure(RethrowsClosureWitness())
132+
rethrowsWithRethrowsClosure(RethrowsClosureWitness())
133133

134134
// Empty protocol
135135
@rethrows protocol Empty {}

0 commit comments

Comments
 (0)