[Sema] Don't ignore implicit AST nodes in diagnoseUnhandledThrowSite (#61392)

This commit is contained in:
Suyash Srijan
2022-10-06 09:47:50 +01:00
committed by GitHub
parent 959e5dece3
commit d124b3581b
4 changed files with 22 additions and 9 deletions

View File

@@ -4043,10 +4043,10 @@ generateForEachStmtConstraints(
// `.next()`. `next()` is called on each iteration of the loop.
{
auto *nextRef = UnresolvedDotExpr::createImplicit(
ctx,
new (ctx) DeclRefExpr(makeIteratorVar, DeclNameLoc(),
/*Implicit=*/true),
ctx.Id_next, /*labels=*/ArrayRef<Identifier>());
ctx,
new (ctx) DeclRefExpr(makeIteratorVar, DeclNameLoc(stmt->getForLoc()),
/*Implicit=*/true),
ctx.Id_next, /*labels=*/ArrayRef<Identifier>());
nextRef->setFunctionRefKind(FunctionRefKind::SingleApply);
Expr *nextCall = CallExpr::createImplicitEmpty(ctx, nextRef);

View File

@@ -1775,9 +1775,6 @@ public:
void diagnoseUnhandledThrowSite(DiagnosticEngine &Diags, ASTNode E,
bool isTryCovered,
const PotentialEffectReason &reason) {
if (E.isImplicit())
return;
switch (getKind()) {
case Kind::PotentiallyHandled:
if (IsNonExhaustiveCatch) {

View File

@@ -9,7 +9,10 @@ func missingAsync<T : AsyncSequence>(_ seq: T) throws {
@available(SwiftStdlib 5.1, *)
func missingThrows<T : AsyncSequence>(_ seq: T) async {
for try await _ in seq { } // expected-error{{error is not handled because the enclosing function is not declared 'throws'}}
for try await _ in seq { }
// expected-error@-1 {{error is not handled because the enclosing function is not declared 'throws'}}
// expected-error@-2 {{call can throw, but the error is not handled}}
// expected-note@-3 {{call is to 'rethrows' function, but a conformance has a throwing witness}}
}
@available(SwiftStdlib 5.1, *)
@@ -27,7 +30,9 @@ func missingThrowingInBlock<T : AsyncSequence>(_ seq: T) {
@available(SwiftStdlib 5.1, *)
func missingTryInBlock<T : AsyncSequence>(_ seq: T) {
executeAsync {
for await _ in seq { } // expected-error{{call can throw, but the error is not handled}}
for await _ in seq { }
// expected-error@-1 2{{call can throw, but the error is not handled}}
// expected-note@-2 {{call is to 'rethrows' function, but a conformance has a throwing witness}}
}
}

View File

@@ -279,3 +279,14 @@ struct FunctionHolder {
}
}
// https://github.com/apple/swift/issues/61368
@propertyWrapper
struct Wrapper {
var wrappedValue: Int?
init() throws {}
}
struct Repro {
@Wrapper var x // expected-error {{call can throw, but errors cannot be thrown out of a property initializer}}
}