Repository navigation
Fix @Generable description literal handling in macro expansion - #61
Conversation
Problem\n- @generable type/enum descriptions were parsed via quote trimming and injected into generated code without robust literal escaping.\n- Descriptions containing escaped quotes/newlines could produce malformed expanded code or lossy schema descriptions.\n\nTDD\n- Added regression coverage in ConduitMacrosTests for:\n - intentional leading/trailing quoted descriptions\n - escaped quotes, backslashes, and newlines in type-level @generable descriptions\n- Verified the new tests fail before fix and pass after fix.\n\nFix\n- Switched description extraction in GenerableMacro to segment-based string literal parsing (matching GuideMacro behavior) instead of trimming quote characters.\n- Added centralized Swift string literal escaping for schema description emission.\n- Applied escaping to both struct and enum generationSchema emitters.\n\nVerification\n- swift test --filter GenerableMacroTests\n- swift test\n- swift build
There was a problem hiding this comment.
馃挕 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 51e6c36c80
鈩癸笍 About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 馃憤.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return literal.segments.compactMap { segment in | ||
| segment.as(StringSegmentSyntax.self)?.content.text | ||
| }.joined() |
There was a problem hiding this comment.
Preserve interpolation segments in string literal parsing
stringLiteralValue(from:) now joins only StringSegmentSyntax tokens and silently drops ExpressionSegmentSyntax, so any interpolated description (for example @Generable(description: "Build \(1)") or @Guide(description: "v\(major)")) loses the interpolated content in generated schema output. This is a regression from the previous behavior, which preserved the full literal syntax text; after this change, descriptions can be truncated or materially incorrect whenever interpolation appears.
Useful? React with 馃憤聽/ 馃憥.
- Make generated PartiallyGenerated initializer non-throwing\n- Update generated asPartiallyGenerated() to avoid try!\n- Preserve ConvertibleFromGeneratedContent conformance while removing crash-prone forced try in generated code\n\nVerification:\n- swift test --filter GenerableMacroTests\n- swift test\n- swift build
|
Added a follow-up fix for the remaining forced-try path in macro-generated code. What changed:
Re-verified:
All green. |
Summary
Fixes a macro-expansion correctness bug in
GenerableMacrofor type/enum@Generable(description: ...)strings.Root cause
GenerableMacroused quote trimming on literal syntax text.unterminated string literal) or lose intended content.Changes
stringLiteralValue(from:).escapeSwiftStringLiteralContent(_:)and used it when emitting schema descriptions.generationSchemageneration paths.Tests/ConduitMacrosTests/GenerableMacroTests.swiftfor:Verification
swift test --filter GenerableMacroTestsswift testswift buildAll pass on this branch.