diff --git a/Sources/DependenciesMacrosPlugin/DependencyEndpointMacro.swift b/Sources/DependenciesMacrosPlugin/DependencyEndpointMacro.swift index b8b9456a..025ccae4 100644 --- a/Sources/DependenciesMacrosPlugin/DependencyEndpointMacro.swift +++ b/Sources/DependenciesMacrosPlugin/DependencyEndpointMacro.swift @@ -143,7 +143,10 @@ public enum DependencyEndpointMacro: AccessorMacro, PeerMacro { if functionType.effectSpecifiers?.asyncSpecifier != nil { effectSpecifiers.append("await ") } - let access = property.modifiers.first { $0.name.tokenKind == .keyword(.public) } + + let access = property.modifiers.first { + [.keyword(.public), .keyword(.package)].contains($0.name.tokenKind) + } var decls: [DeclSyntax] = [] diff --git a/Tests/DependenciesMacrosPluginTests/DependencyEndpointMacroTests.swift b/Tests/DependenciesMacrosPluginTests/DependencyEndpointMacroTests.swift index 7833d002..80a26c4d 100644 --- a/Tests/DependenciesMacrosPluginTests/DependencyEndpointMacroTests.swift +++ b/Tests/DependenciesMacrosPluginTests/DependencyEndpointMacroTests.swift @@ -1010,6 +1010,42 @@ final class DependencyEndpointMacroTests: BaseTestCase { """# } } + + func testAccessPackageWithMethodEquivalent() { + assertMacro { + """ + package struct Client { + @DependencyEndpoint + package var endpoint: (_ id: Int) -> Void + } + """ + } expansion: { + #""" + package struct Client { + package var endpoint: (_ id: Int) -> Void { + @storageRestrictions(initializes: _endpoint) + init(initialValue) { + _endpoint = initialValue + } + get { + _endpoint + } + set { + _endpoint = newValue + } + } + + package func endpoint(id p0: Int) -> Void { + self.endpoint(p0) + } + + private var _endpoint: (_ id: Int) -> Void = { _ in + IssueReporting.reportIssue("Unimplemented: '\(Self.self).endpoint'") + } + } + """# + } + } func testComments() { assertMacro { diff --git a/Tests/DependenciesMacrosPluginTests/MacroTests.swift b/Tests/DependenciesMacrosPluginTests/MacroTests.swift new file mode 100644 index 00000000..eb2a7f42 --- /dev/null +++ b/Tests/DependenciesMacrosPluginTests/MacroTests.swift @@ -0,0 +1,10 @@ +import Dependencies +import DependenciesMacros + +private enum PackageACL { + @DependencyClient + package struct Client { + @DependencyEndpoint + package var endpoint: (_ id: Int) -> Void + } +}