swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.27k stars 10.33k forks source link

Macro is not working with #if os #72648

Open miku1958 opened 5 months ago

miku1958 commented 5 months ago

Description

I added the interface of OptionSetMacro to my code

@attached(member, names: named(RawValue), named(rawValue), named(`init`), arbitrary)
@attached(extension, conformances: OptionSet)
macro OptionSet<RawType>() = #externalMacro(module: "SwiftMacros", type: "OptionSetMacro")

And use it to create a OptionSet:

  @OptionSet<Int>
  struct Log {
    private enum Options: Int, CaseIterable {
      case debug, native, console
#if os(macOS)
      case inspect
#endif
    }
  }

Then it gives me this error: Type 'Log' has no member 'inspect'

Reproduction

  @OptionSet<Int>
  struct Log {
    private enum Options: Int, CaseIterable {
      case debug, native, console
#if os(macOS)
      case inspect
#endif
    }
  }

Expected behavior

No error

Environment

swift-driver version: 1.87.3 Apple Swift version 5.9.2 (swiftlang-5.9.2.2.56 clang-1500.1.0.2.5) Target: arm64-apple-macosx14.0

Additional information

No response

miku1958 commented 5 months ago

I actually can access Log.inspect in the same file, but not in others

miku1958 commented 5 months ago

And I don't see it in the extended content

image