Skip to content

InFlightDiagnostic: Minor improvement to fixItAddAttribute #81671

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/AST/DiagnosticEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,20 @@ InFlightDiagnostic::fixItAddAttribute(const DeclAttribute *Attr,
if (insertionLoc.isValid()) {
return fixItInsert(insertionLoc, "%0 ", {Attr});
} else {
insertionLoc = E->getBody()->getLBraceLoc();
auto *body = E->getBody();

insertionLoc = body->getLBraceLoc();
ASSERT(insertionLoc.isValid());
return fixItInsertAfter(insertionLoc, " %0 in ", {Attr});

StringRef fixIt = " %0 in";
// If the first token in the body literally begins with the next char after
// '{', play it safe with a trailing space.
if (body->getContentStartLoc() ==
insertionLoc.getAdvancedLoc(/*ByteOffset=*/1)) {
fixIt = " %0 in ";
}

return fixItInsertAfter(insertionLoc, fixIt, {Attr});
}
}

Expand Down
16 changes: 15 additions & 1 deletion test/Concurrency/attr_execution/adoption_mode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,22 @@ do {
// expected-warning@+1:10 {{feature 'NonisolatedNonsendingByDefault' will cause nonisolated async closure to run on the caller's actor; use '@concurrent' to preserve behavior}}{{12-12=@concurrent }}{{none}}
test { a, b async in await asyncOnly(a, b) }
test { @concurrent a, b async in await asyncOnly(a, b) }
// expected-warning@+1:10 {{feature 'NonisolatedNonsendingByDefault' will cause nonisolated async closure to run on the caller's actor; use '@concurrent' to preserve behavior}}{{11-11= @concurrent in }}{{none}}

// No space after 'in' necessary.
// expected-warning@+1:10 {{feature 'NonisolatedNonsendingByDefault' will cause nonisolated async closure to run on the caller's actor; use '@concurrent' to preserve behavior}}{{11-11= @concurrent in}}{{none}}
test { try await asyncThrows($0, $1) }
// No space after 'in' necessary.
// expected-warning@+1:10 {{feature 'NonisolatedNonsendingByDefault' will cause nonisolated async closure to run on the caller's actor; use '@concurrent' to preserve behavior}}{{11-11= @concurrent in}}{{none}}
test { try await asyncThrows($0, $1) }
// No space after 'in' necessary.
// expected-warning@+1:10 {{feature 'NonisolatedNonsendingByDefault' will cause nonisolated async closure to run on the caller's actor; use '@concurrent' to preserve behavior}}{{11-11= @concurrent in}}{{none}}
test {
try await asyncThrows($0, $1)
}
// Add a space after in.
// expected-warning@+1:10 {{feature 'NonisolatedNonsendingByDefault' will cause nonisolated async closure to run on the caller's actor; use '@concurrent' to preserve behavior}}{{11-11= @concurrent in }}{{none}}
test {try await asyncThrows($0, $1)}

test { @concurrent in try await asyncThrows($0, $1) }
// expected-warning@+1:10 {{feature 'NonisolatedNonsendingByDefault' will cause nonisolated async closure to run on the caller's actor; use '@concurrent' to preserve behavior}}{{12-12=@concurrent }}{{none}}
test { [x] in try await asyncThrows($0, $1 + x) }
Expand Down