Skip to content

Commit 00f6af1

Browse files
committed
Remove potential for duplicate diagnosis on rethrows
1 parent 9a3d613 commit 00f6af1

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,13 @@ class ApplyClassifier {
528528
}
529529

530530
if (classifiedAsThrows) {
531+
// multiple passes can occur, so ensure that any sub-expressions of this
532+
// call are marked as throws to mimic the closure variant.
533+
if (auto subExpr = dyn_cast<ApplyExpr>(E->getFn())) {
534+
if (!subExpr->isThrowsSet()) {
535+
subExpr->setThrows(true);
536+
}
537+
}
531538
return Classification::forRethrowingOnly(
532539
PotentialThrowReason::forRethrowsConformance(E), isAsync);
533540
}

test/Concurrency/async_sequence_syntax.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,27 @@ func missingAsyncInBlock<T : AsyncSequence>(_ seq: T) {
3131
for try await _ in seq { }
3232
} catch { }
3333
}
34+
}
35+
36+
func doubleDiagCheckGeneric<T : AsyncSequence>(_ seq: T) async {
37+
var it = seq.makeAsyncIterator()
38+
// expected-note@+2{{call is to 'rethrows' function, but a conformance has a throwing witness}}
39+
// expected-error@+1{{call can throw, but it is not marked with 'try' and the error is not handled}}
40+
let _ = await it.next()
41+
}
42+
43+
struct ThrowingAsyncSequence: AsyncSequence, AsyncIteratorProtocol {
44+
typealias Element = Int
45+
typealias AsyncIterator = Self
46+
mutating func next() async throws -> Int? {
47+
return nil
48+
}
49+
50+
func makeAsyncIterator() -> Self { return self }
51+
}
52+
53+
func doubleDiagCheckConcrete(_ seq: ThrowingAsyncSequence) async {
54+
var it = seq.makeAsyncIterator()
55+
// expected-error@+1{{call can throw, but it is not marked with 'try' and the error is not handled}}
56+
let _ = await it.next()
3457
}

0 commit comments

Comments
 (0)