Skip to content

Commit de15dc6

Browse files
Merge pull request #81671 from AnthonyLatsis/caranx-melampygus
InFlightDiagnostic: Minor improvement to `fixItAddAttribute`
2 parents 0d0ba1d + eedc774 commit de15dc6

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

lib/AST/DiagnosticEngine.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,20 @@ InFlightDiagnostic::fixItAddAttribute(const DeclAttribute *Attr,
414414
if (insertionLoc.isValid()) {
415415
return fixItInsert(insertionLoc, "%0 ", {Attr});
416416
} else {
417-
insertionLoc = E->getBody()->getLBraceLoc();
417+
auto *body = E->getBody();
418+
419+
insertionLoc = body->getLBraceLoc();
418420
ASSERT(insertionLoc.isValid());
419-
return fixItInsertAfter(insertionLoc, " %0 in ", {Attr});
421+
422+
StringRef fixIt = " %0 in";
423+
// If the first token in the body literally begins with the next char after
424+
// '{', play it safe with a trailing space.
425+
if (body->getContentStartLoc() ==
426+
insertionLoc.getAdvancedLoc(/*ByteOffset=*/1)) {
427+
fixIt = " %0 in ";
428+
}
429+
430+
return fixItInsertAfter(insertionLoc, fixIt, {Attr});
420431
}
421432
}
422433

test/Concurrency/attr_execution/adoption_mode.swift

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,22 @@ do {
325325
// 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}}
326326
test { a, b async in await asyncOnly(a, b) }
327327
test { @concurrent a, b async in await asyncOnly(a, b) }
328-
// 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}}
328+
329+
// No space after 'in' necessary.
330+
// 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}}
329331
test { try await asyncThrows($0, $1) }
332+
// No space after 'in' necessary.
333+
// 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}}
334+
test { try await asyncThrows($0, $1) }
335+
// No space after 'in' necessary.
336+
// 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}}
337+
test {
338+
try await asyncThrows($0, $1)
339+
}
340+
// Add a space after in.
341+
// 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}}
342+
test {try await asyncThrows($0, $1)}
343+
330344
test { @concurrent in try await asyncThrows($0, $1) }
331345
// 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}}
332346
test { [x] in try await asyncThrows($0, $1 + x) }

0 commit comments

Comments
 (0)