diff --git a/Sources/ComposableArchitectureMacros/ViewActionMacro.swift b/Sources/ComposableArchitectureMacros/ViewActionMacro.swift index 9f74b745f984..8053cdc168d0 100644 --- a/Sources/ComposableArchitectureMacros/ViewActionMacro.swift +++ b/Sources/ComposableArchitectureMacros/ViewActionMacro.swift @@ -68,7 +68,8 @@ public struct ViewActionMacro: ExtensionMacro { let ext: DeclSyntax = """ - extension \(type.trimmed): ComposableArchitecture.ViewActionSending {} + \(declaration.attributes.availability)extension \(type.trimmed): \ + ComposableArchitecture.ViewActionSending {} """ return [ext.cast(ExtensionDeclSyntax.self)] } diff --git a/Tests/ComposableArchitectureMacrosTests/ViewActionMacroTests.swift b/Tests/ComposableArchitectureMacrosTests/ViewActionMacroTests.swift index a0425a2aa327..b4f404626038 100644 --- a/Tests/ComposableArchitectureMacrosTests/ViewActionMacroTests.swift +++ b/Tests/ComposableArchitectureMacrosTests/ViewActionMacroTests.swift @@ -438,5 +438,33 @@ """ } } + + func testAvailability() { + assertMacro { + """ + @available(iOS 17, macOS 14, tvOS 17, visionOS 1, watchOS 10, *) + @ViewAction(for: Feature.self) + struct FeatureView: View { + @State var store: StoreOf + var body: some View { + EmptyView() + } + } + """ + } expansion: { + """ + @available(iOS 17, macOS 14, tvOS 17, visionOS 1, watchOS 10, *) + struct FeatureView: View { + @State var store: StoreOf + var body: some View { + EmptyView() + } + } + + @available(iOS 17, macOS 14, tvOS 17, visionOS 1, watchOS 10, *) extension FeatureView: ComposableArchitecture.ViewActionSending { + } + """ + } + } } #endif