Skip to content

Commit

Permalink
[TypeChecker] Effects: Don't diagnose implicit AST nodes
Browse files Browse the repository at this point in the history
Implicitly generated code requires checking but it doesn't have
to produce a diagnostic into the void.
  • Loading branch information
xedin committed May 31, 2022
1 parent 0989cd9 commit d461eab
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
6 changes: 6 additions & 0 deletions lib/Sema/TypeCheckEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1787,6 +1787,9 @@ class Context {
void diagnoseUnhandledThrowSite(DiagnosticEngine &Diags, ASTNode E,
bool isTryCovered,
const PotentialEffectReason &reason) {
if (E.isImplicit())
return;

switch (getKind()) {
case Kind::PotentiallyHandled:
if (IsNonExhaustiveCatch) {
Expand Down Expand Up @@ -1966,6 +1969,9 @@ class Context {
void diagnoseUnhandledAsyncSite(DiagnosticEngine &Diags, ASTNode node,
Optional<PotentialEffectReason> maybeReason,
bool forAwait = false) {
if (node.isImplicit())
return;

switch (getKind()) {
case Kind::PotentiallyHandled: {
Diags.diagnose(node.getStartLoc(), diag::async_in_nonasync_function,
Expand Down
1 change: 0 additions & 1 deletion test/decl/var/async_let.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ func test() async {

struct X {
async let x = 1 // expected-error{{'async let' can only be used on local declarations}}
// FIXME: expected-error@-1{{'async' call cannot occur in a property initializer}}
}

func testAsyncFunc() async {
Expand Down
3 changes: 1 addition & 2 deletions test/expr/unary/async_await.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,9 @@ func testAsyncLet() async throws {
_ = await x5
}

// expected-note@+1 4{{add 'async' to function 'testAsyncLetOutOfAsync()' to make it asynchronous}} {{30-30= async}}
// expected-note@+1 3{{add 'async' to function 'testAsyncLetOutOfAsync()' to make it asynchronous}} {{30-30= async}}
func testAsyncLetOutOfAsync() {
async let x = 1 // expected-error{{'async let' in a function that does not support concurrency}}
// FIXME: expected-error@-1{{'async' call in a function that does not support concurrency}}

_ = await x // expected-error{{'async let' in a function that does not support concurrency}}
_ = x // expected-error{{'async let' in a function that does not support concurrency}}
Expand Down
3 changes: 1 addition & 2 deletions test/stmt/async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ func omnom(_ x: Int)

func f() async -> Int { 0 }

func syncContext() { // expected-note 4 {{add 'async' to function 'syncContext()' to make it asynchronous}}
func syncContext() { // expected-note 3 {{add 'async' to function 'syncContext()' to make it asynchronous}}
_ = await f() // expected-error{{'async' call in a function that does not support concurrency}}
async let y = await f() // expected-error{{'async let' in a function that does not support concurrency}}
// expected-error@-1{{'async' call in a function that does not support concurrency}}
await omnom(y) // expected-error{{'async let' in a function that does not support concurrency}}
}

0 comments on commit d461eab

Please sign in to comment.