Handle composed and mixed associated type constraints #108
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📝 Summary
This pull request fixes a bug in
MockedMacro.mockGenericParameterClause
where associated types using composition (&
) in their constraints weren’t handled correctly.Previously, the
@Mocked
assumed all inherited types wereIdentifierTypeSyntax
nodes, which holds for comma-separated constraints (e.g.Hashable, Sendable
). However, composed constraints (e.g.Hashable & Sendable
) are represented in the syntax tree asCompositionTypeSyntax
, which nests multipleIdentifierTypeSyntax
elements. As a result, these weren’t being parsed, and the generated generic parameter clause was incomplete or incorrect.To fix this, I've:
mockGenericParameterClause
to correctly extract constraints from bothIdentifierTypeSyntax
and nestedCompositionTypeSyntax
.🛠️ Type of Change
🧪 How Has This Been Tested?
I've tested the
@Mocked
macro expansion when anassociatedtype
has constraints that are comma-separated, composed, or a mix of both. Please see screenshots of the expansion below.I've also added unit tests to validate these scenarios going forward.
@Mocked
expansion🔗 Related PRs or Issues
✅ Checklist
SwiftFormat