Skip to content

Commit 972dc99

Browse files
authored
Merge pull request swiftlang#36543 from slavapestov/for-try-await-rdar75274975
Sema: Fix effect checking bug with 'for try await'
2 parents a2cb5a8 + 286927d commit 972dc99

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,13 +2598,21 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
25982598
auto classification = classifier.classifyConformance(
25992599
S->getSequenceConformance(), EffectKind::Throws);
26002600
auto throwsKind = classification.getConditionalKind(EffectKind::Throws);
2601+
2602+
if (throwsKind != ConditionalEffectKind::None)
2603+
Flags.set(ContextFlags::HasAnyThrowSite);
2604+
26012605
if (!CurContext.handlesThrows(throwsKind))
26022606
CurContext.diagnoseUnhandledThrowStmt(Ctx.Diags, S);
26032607
}
26042608

26052609
auto classification = classifier.classifyConformance(
26062610
S->getSequenceConformance(), EffectKind::Async);
26072611
auto asyncKind = classification.getConditionalKind(EffectKind::Async);
2612+
2613+
if (asyncKind != ConditionalEffectKind::None)
2614+
Flags.set(ContextFlags::HasAnyAsyncSite);
2615+
26082616
if (!CurContext.handlesAsync(asyncKind))
26092617
CurContext.diagnoseUnhandledAsyncSite(Ctx.Diags, S, Context::Unspecified);
26102618

test/Concurrency/async_sequence_syntax.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,13 @@ func doubleDiagCheckConcrete(_ seq: ThrowingAsyncSequence) async {
5454
var it = seq.makeAsyncIterator()
5555
// expected-error@+1{{call can throw, but it is not marked with 'try' and the error is not handled}}
5656
let _ = await it.next()
57-
}
57+
}
58+
59+
// rdar://75274975
60+
func forAwaitInsideDoCatch<Source: AsyncSequence>(_ source: Source) async {
61+
do {
62+
for try await item in source {
63+
print(item)
64+
}
65+
} catch {} // no-warning
66+
}

0 commit comments

Comments
 (0)