swift-syntax icon indicating copy to clipboard operation
swift-syntax copied to clipboard

MemberAttributeMacro do not visit members that are guarded with IfConfigDecl

Open jaredgrubb opened this issue 6 months ago • 1 comments

Description

The MemberAttributeMacro does not get invoked for members that are inside #if guards.

Steps to Reproduce

Looking at the unit tests, I can add a new one to the MemberAttributeMacroTests:

  func testAttributeWithIfConfigDecl() {
    assertMacroExpansion(
      """
      @wrapAllProperties struct S {
        #if true
        var value = 1
        #endif
      }
      """,
      expandedSource: """
        struct S {
          #if true     
          @Wrapper
          var value = 1
          #endif
        }
        """,
      macros: ["wrapAllProperties": WrapAllProperties.self],
      indentationWidth: indentationWidth
    )
  }

Actual results is the macro never gets visited for value at all.

jaredgrubb avatar Jun 18 '25 01:06 jaredgrubb

We should be able to handle this now with SwiftIfConfig with eg. an extra BuildConfiguration to the assertion. Note that this behaves as you'd expect during actual compilation, just not in the testing infrastructure.

bnbarham avatar Jun 27 '25 23:06 bnbarham