Skip to content

Add support for macro conditions to named enums #247

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 1 commit into from
May 7, 2025

Conversation

skorulis-ap
Copy link
Collaborator

@skorulis-ap skorulis-ap commented Feb 12, 2025

  • If a group of named registrations all have the same #if condition then the resolver and the enum are both wrapped in the same condition.
  • If registrations in the group have different #if conditions, the resolver will not have a condition and the enum cases will be wrapped in #if conditions from the individual registrations.

@skorulis-ap skorulis-ap force-pushed the skorulis/conditional-enums branch from 78088be to 254ac4c Compare February 12, 2025 00:28
extension DeclSyntaxProtocol {

// Wrap the declaration in an #if where needed
func maybeWithCondition(ifConfigCondition: ExprSyntax?) -> DeclSyntaxProtocol {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This helper prevents some duplication

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is nice, thanks


extension NamedRegistrationGroup {
// Generate the enum for this group of named registrations
func enumSourceCode(assemblyName: String) throws -> DeclSyntaxProtocol {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved this out of TypeSafetySourceFile to make this code easier to test in isolation.

Copy link
Collaborator

@bradfol bradfol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

extension DeclSyntaxProtocol {

// Wrap the declaration in an #if where needed
func maybeWithCondition(ifConfigCondition: ExprSyntax?) -> DeclSyntaxProtocol {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this is nice, thanks

@skorulis-ap skorulis-ap force-pushed the skorulis/conditional-enums branch from 9f5205e to 8536ec7 Compare March 18, 2025 23:57
@skorulis-ap skorulis-ap force-pushed the skorulis/conditional-enums branch from 8536ec7 to 35f3e64 Compare May 6, 2025 22:25
@skorulis-ap skorulis-ap force-pushed the skorulis/conditional-enums branch from 35f3e64 to 656fc56 Compare May 6, 2025 23:52
@skorulis-ap skorulis-ap merged commit 9674684 into main May 7, 2025
2 checks passed
@skorulis-ap skorulis-ap deleted the skorulis/conditional-enums branch May 7, 2025 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants