Skip to content

Commit ed1589d

Browse files
committed
[Sema] Walk MacroExpansionDecls in BaseDiagnosticWalker
I missed this in my previous PR, but this is needed to ensure we visit macro arguments for macro expansion exprs that have substitute MacroExpansionDecls since we prefer to visit the arguments on the decl once the expression has been expanded.
1 parent b2dcf1e commit ed1589d

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

lib/Sema/MiscDiagnostics.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,11 @@ namespace swift {
135135

136136
class BaseDiagnosticWalker : public ASTWalker {
137137
PreWalkAction walkToDeclPre(Decl *D) override {
138-
return Action::VisitNodeIf(isa<PatternBindingDecl>(D));
138+
// We don't walk into any nested local decls, except PatternBindingDecls,
139+
// which are type-checked along with the parent, and MacroExpansionDecl,
140+
// which needs to be visited to visit the macro arguments.
141+
return Action::VisitNodeIf(isa<PatternBindingDecl>(D) ||
142+
isa<MacroExpansionDecl>(D));
139143
}
140144

141145
MacroWalking getMacroWalkingBehavior() const override {

test/Macros/macro_misc_diags.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,16 @@ _ = #identity(deprecatedFunc())
7777
// CHECK-DIAG: @__swiftmacro_6Client0017Clientswift_yEEFcfMX[[@LINE-2]]{{.*}}identityfMf1_.swift:1:1: warning: 'deprecatedFunc()' is deprecated
7878
// CHECK-DIAG: Client.swift:[[@LINE-2]]:15: warning: 'deprecatedFunc()' is deprecated
7979

80-
#makeBinding(deprecatedFunc())
81-
// CHECK-DIAG: Client.swift:[[@LINE-1]]:14: warning: 'deprecatedFunc()' is deprecated
82-
// CHECK-DIAG: @__swiftmacro_6Client0017Clientswift_yEEFcfMX[[@LINE-3]]{{.*}}makeBindingfMf_.swift:1:9: warning: 'deprecatedFunc()' is deprecated
83-
// CHECK-DIAG: @__swiftmacro_6Client0017Clientswift_yEEFcfMX[[@LINE-4]]{{.*}}makeBindingfMf_.swift:1:5: warning: initialization of immutable value 'x' was never used
80+
#makeBinding((deprecatedFunc(), Int, {
81+
if let _ = takesClosure {} {}
82+
}()))
83+
// CHECK-DIAG: Client.swift:[[@LINE-2]]:27: warning: trailing closure in this context is confusable with the body of the statement
84+
// CHECK-DIAG: Client.swift:[[@LINE-4]]:33: error: expected member name or initializer call after type name
85+
// CHECK-DIAG: Client.swift:[[@LINE-5]]:15: warning: 'deprecatedFunc()' is deprecated
86+
// CHECK-DIAG: @__swiftmacro_6Client0017Clientswift_yEEFcfMX[[@LINE-7]]{{.*}}makeBindingfMf_.swift:2:27: warning: trailing closure in this context is confusable with the body of the statement; pass as a parenthesized argument to silence this warning
87+
// CHECK-DIAG: @__swiftmacro_6Client0017Clientswift_yEEFcfMX[[@LINE-8]]{{.*}}makeBindingfMf_.swift:1:28: error: expected member name or initializer call after type name
88+
// CHECK-DIAG: @__swiftmacro_6Client0017Clientswift_yEEFcfMX[[@LINE-9]]{{.*}}makeBindingfMf_.swift:1:10: warning: 'deprecatedFunc()' is deprecated
89+
// CHECK-DIAG: @__swiftmacro_6Client0017Clientswift_yEEFcfMX[[@LINE-10]]{{.*}}makeBindingfMf_.swift:1:5: warning: initialization of immutable value
8490

8591
struct S1 {
8692
#makeBinding(deprecatedFunc())

0 commit comments

Comments
 (0)