File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
Sources/SwiftSyntaxMacros
Tests/SwiftSyntaxMacroExpansionTest Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -67,6 +67,20 @@ extension SyntaxProtocol {
6767 case let freestandingMacro as FreestandingMacroExpansionSyntax :
6868 return Syntax ( freestandingMacro. detached) as Syntax
6969
70+ // Try and await are preserved: A freestanding expression macro preceded
71+ // by try or await may need to know whether those keywords are present so it
72+ // can propagate them to any expressions in its expansion which were passed
73+ // as arguments to the macro. The expression of the try or await is replaced
74+ // with a trivial placeholder, though.
75+ case var tryExpr as TryExprSyntax :
76+ tryExpr = tryExpr. detached
77+ tryExpr. expression = ExprSyntax ( TypeExprSyntax ( type: IdentifierTypeSyntax ( name: . wildcardToken( ) ) ) )
78+ return Syntax ( tryExpr)
79+ case var awaitExpr as AwaitExprSyntax :
80+ awaitExpr = awaitExpr. detached
81+ awaitExpr. expression = ExprSyntax ( TypeExprSyntax ( type: IdentifierTypeSyntax ( name: . wildcardToken( ) ) ) )
82+ return Syntax ( awaitExpr)
83+
7084 default :
7185 return nil
7286 }
Original file line number Diff line number Diff line change @@ -531,7 +531,7 @@ final class LexicalContextTests: XCTestCase {
531531 struct S {
532532 let arg: C
533533 var contextDescription: String {
534- #lexicalContextDescription
534+ try await #lexicalContextDescription
535535 }
536536 }
537537 return S(arg: c)
@@ -542,7 +542,9 @@ final class LexicalContextTests: XCTestCase {
542542 struct S {
543543 let arg: C
544544 var contextDescription: String {
545- """
545+ try await """
546+ await _
547+ try _
546548 contextDescription: String
547549 struct S {}
548550 { c in
@@ -551,7 +553,7 @@ final class LexicalContextTests: XCTestCase {
551553 struct S {
552554 let arg: C
553555 var contextDescription: String {
554- #lexicalContextDescription
556+ try await #lexicalContextDescription
555557 }
556558 }
557559 return S(arg: c)
You can’t perform that action at this time.
0 commit comments