From 556199fbe67cab9992489618d7a9632aab268020 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81bastien=20pe=CC=81coul?= Date: Tue, 11 Mar 2025 17:03:00 +0100 Subject: [PATCH 1/4] fix: Handle package ACL when generating method equivalent with DependencyEndpointMacro --- .../DependenciesMacrosPlugin/DependencyEndpointMacro.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/DependenciesMacrosPlugin/DependencyEndpointMacro.swift b/Sources/DependenciesMacrosPlugin/DependencyEndpointMacro.swift index b8b9456a..a2f38136 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] = [] From 3bff31a65a6f0268cf32ec3bd092786b48251f42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81bastien=20pe=CC=81coul?= Date: Tue, 11 Mar 2025 17:05:14 +0100 Subject: [PATCH 2/4] add: tests --- .../DependencyEndpointMacroTests.swift | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Tests/DependenciesMacrosPluginTests/DependencyEndpointMacroTests.swift b/Tests/DependenciesMacrosPluginTests/DependencyEndpointMacroTests.swift index 7833d002..268efa46 100644 --- a/Tests/DependenciesMacrosPluginTests/DependencyEndpointMacroTests.swift +++ b/Tests/DependenciesMacrosPluginTests/DependencyEndpointMacroTests.swift @@ -1010,6 +1010,42 @@ final class DependencyEndpointMacroTests: BaseTestCase { """# } } + + func testAccessPackageWithMethodsEquivalent() { + 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 { From e8fcc500fdab1207f7e7adcbd0176c7099ab9c00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81bastien=20pe=CC=81coul?= Date: Tue, 11 Mar 2025 17:08:21 +0100 Subject: [PATCH 3/4] fix: typo --- .../DependencyEndpointMacroTests.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/DependenciesMacrosPluginTests/DependencyEndpointMacroTests.swift b/Tests/DependenciesMacrosPluginTests/DependencyEndpointMacroTests.swift index 268efa46..80a26c4d 100644 --- a/Tests/DependenciesMacrosPluginTests/DependencyEndpointMacroTests.swift +++ b/Tests/DependenciesMacrosPluginTests/DependencyEndpointMacroTests.swift @@ -1011,7 +1011,7 @@ final class DependencyEndpointMacroTests: BaseTestCase { } } - func testAccessPackageWithMethodsEquivalent() { + func testAccessPackageWithMethodEquivalent() { assertMacro { """ package struct Client { From a9aafa4adcb137aa9a88eb972ba873146830c7e1 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Tue, 11 Mar 2025 11:28:32 -0700 Subject: [PATCH 4/4] One more test --- .../DependencyEndpointMacro.swift | 2 +- Tests/DependenciesMacrosPluginTests/MacroTests.swift | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 Tests/DependenciesMacrosPluginTests/MacroTests.swift diff --git a/Sources/DependenciesMacrosPlugin/DependencyEndpointMacro.swift b/Sources/DependenciesMacrosPlugin/DependencyEndpointMacro.swift index a2f38136..025ccae4 100644 --- a/Sources/DependenciesMacrosPlugin/DependencyEndpointMacro.swift +++ b/Sources/DependenciesMacrosPlugin/DependencyEndpointMacro.swift @@ -145,7 +145,7 @@ public enum DependencyEndpointMacro: AccessorMacro, PeerMacro { } let access = property.modifiers.first { - [.keyword(.public), .keyword(.package)].contains($0.name.tokenKind) + [.keyword(.public), .keyword(.package)].contains($0.name.tokenKind) } var decls: [DeclSyntax] = [] 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 + } +}