Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a macro code generation issue where comments and extra whitespace in type annotations were being incorrectly included in the generated code. The fix wraps type syntax nodes with parentheses and applies .trimmed to remove leading/trailing trivia (comments and spaces).
- Wraps all type references in generated assertion calls with parentheses to handle types that contain trivia
- Applies
.trimmedto TokenSyntax and TypeSyntax nodes to remove comments and whitespace - Removes
nonisolated(unsafe)modifier from test macros constant
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/BinaryParseKitMacroTests/Misc.swift | Removed nonisolated(unsafe) modifier from testMacros constant |
| Tests/BinaryParseKitMacroTests/BinaryParseKitStructTests.swift | Updated test expectations with parentheses around types and added new test for comment/space handling |
| Tests/BinaryParseKitMacroTests/BinaryParseKitEnumTests.swift | Updated test expectations with parentheses around types and added new test for comment handling |
| Sources/BinaryParseKitMacros/Macros/Supports/Utilities.swift | Wrapped type syntax in parentheses in all assertion calls to handle trivia correctly |
| Sources/BinaryParseKitMacros/Macros/Supports/ParseMacroInfo.swift | Applied .trimmed to endianness and byteCount expressions to remove trivia |
| Sources/BinaryParseKitMacros/Macros/ParseStruct/ParseStructField.swift | Added init that trims type and variable name, applied trimming to variable name |
| Sources/BinaryParseKitMacros/Macros/ParseEnum/EnumCaseParseInfo.swift | Added inits that trim firstName, type, and caseElementName tokens |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR
(1) strips comments in macro code generation output, which had led to invalid syntax. For instance
generates
__assertParsable(Int // some comment.self)(2) wraps types in
()before applying.selfFor instance,
A & Bwill previously generateA & B.selfinstead of(A & B).self