Skip to content
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

Avoid erroneous missing default diagnosis #161

Merged
merged 3 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 3 additions & 4 deletions Sources/DependenciesMacrosPlugin/DependencyClientMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ public enum DependencyClientMacro: MemberAttributeMacro, MemberMacro {
return []
}
// NB: Ideally `@DependencyEndpoint` would handle this for us, but there are compiler crashes
if let initializer = binding.initializer,
try initializer.diagnose(node, context: context).earlyOut
{
return []
if let initializer = binding.initializer {
guard try !initializer.diagnose(node, context: context).earlyOut
else { return [] }
} else if functionType.effectSpecifiers?.throwsSpecifier == nil,
!functionType.isVoid,
!functionType.isOptional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,33 @@ final class DependencyClientMacroTests: BaseTestCase {
}
}

func testDefaultValue() {
assertMacro {
"""
@DependencyClient
struct Client {
var endpoint: () -> Int = { 42 }
}
"""
} expansion: {
"""
struct Client {
@DependencyEndpoint
var endpoint: () -> Int = { 42 }

init(
endpoint: @escaping () -> Int
) {
self.endpoint = endpoint
}

init() {
}
}
"""
}
}

func testPrivate_WithDefault() {
assertMacro {
"""
Expand Down
Loading