Skip to content

Commit d124b35

Browse files
authored
[Sema] Don't ignore implicit AST nodes in diagnoseUnhandledThrowSite (#61392)
1 parent 959e5de commit d124b35

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

lib/Sema/CSGen.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4043,10 +4043,10 @@ generateForEachStmtConstraints(
40434043
// `.next()`. `next()` is called on each iteration of the loop.
40444044
{
40454045
auto *nextRef = UnresolvedDotExpr::createImplicit(
4046-
ctx,
4047-
new (ctx) DeclRefExpr(makeIteratorVar, DeclNameLoc(),
4048-
/*Implicit=*/true),
4049-
ctx.Id_next, /*labels=*/ArrayRef<Identifier>());
4046+
ctx,
4047+
new (ctx) DeclRefExpr(makeIteratorVar, DeclNameLoc(stmt->getForLoc()),
4048+
/*Implicit=*/true),
4049+
ctx.Id_next, /*labels=*/ArrayRef<Identifier>());
40504050
nextRef->setFunctionRefKind(FunctionRefKind::SingleApply);
40514051

40524052
Expr *nextCall = CallExpr::createImplicitEmpty(ctx, nextRef);

lib/Sema/TypeCheckEffects.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,9 +1775,6 @@ class Context {
17751775
void diagnoseUnhandledThrowSite(DiagnosticEngine &Diags, ASTNode E,
17761776
bool isTryCovered,
17771777
const PotentialEffectReason &reason) {
1778-
if (E.isImplicit())
1779-
return;
1780-
17811778
switch (getKind()) {
17821779
case Kind::PotentiallyHandled:
17831780
if (IsNonExhaustiveCatch) {

test/Concurrency/async_sequence_syntax.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ func missingAsync<T : AsyncSequence>(_ seq: T) throws {
99

1010
@available(SwiftStdlib 5.1, *)
1111
func missingThrows<T : AsyncSequence>(_ seq: T) async {
12-
for try await _ in seq { } // expected-error{{error is not handled because the enclosing function is not declared 'throws'}}
12+
for try await _ in seq { }
13+
// expected-error@-1 {{error is not handled because the enclosing function is not declared 'throws'}}
14+
// expected-error@-2 {{call can throw, but the error is not handled}}
15+
// expected-note@-3 {{call is to 'rethrows' function, but a conformance has a throwing witness}}
1316
}
1417

1518
@available(SwiftStdlib 5.1, *)
@@ -27,7 +30,9 @@ func missingThrowingInBlock<T : AsyncSequence>(_ seq: T) {
2730
@available(SwiftStdlib 5.1, *)
2831
func missingTryInBlock<T : AsyncSequence>(_ seq: T) {
2932
executeAsync {
30-
for await _ in seq { } // expected-error{{call can throw, but the error is not handled}}
33+
for await _ in seq { }
34+
// expected-error@-1 2{{call can throw, but the error is not handled}}
35+
// expected-note@-2 {{call is to 'rethrows' function, but a conformance has a throwing witness}}
3136
}
3237
}
3338

test/decl/func/throwing_functions.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,3 +279,14 @@ struct FunctionHolder {
279279
}
280280
}
281281

282+
// https://github.com/apple/swift/issues/61368
283+
284+
@propertyWrapper
285+
struct Wrapper {
286+
var wrappedValue: Int?
287+
init() throws {}
288+
}
289+
290+
struct Repro {
291+
@Wrapper var x // expected-error {{call can throw, but errors cannot be thrown out of a property initializer}}
292+
}

0 commit comments

Comments
 (0)