Skip to content

fix: Use proper access control when generating method with package ACL #350

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions Tests/DependenciesMacrosPluginTests/MacroTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Dependencies
import DependenciesMacros

private enum PackageACL {
@DependencyClient
package struct Client {
@DependencyEndpoint
package var endpoint: (_ id: Int) -> Void
}
}