-
Notifications
You must be signed in to change notification settings - Fork 46
Fix PartiallyGenerated for array properties #88
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
Conversation
|
Thank you, @ethanhuang13! Taking a look now... |
|
Thanks for pushing this through, @ethanhuang13! The array partial type fix is great. One short‑term issue I noticed: the new Looking at |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes the @Generable macro to generate correct partial types for array properties, aligning with FoundationModels' macro behavior. Previously, arrays like [CatProfile] were synthesized as [CatProfile] in the PartiallyGenerated struct, but now they correctly become [CatProfile.PartiallyGenerated]? for non-primitive element types.
Changes:
- Added type analysis utilities to distinguish arrays, dictionaries, and primitives
- Modified partial type generation to recursively handle array elements
- Updated property decoding to initialize arrays with partially generated element types
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| Tests/AnyLanguageModelTests/GenerableMacroTests.swift | Adds test coverage for array properties with both complex and primitive element types |
| Sources/AnyLanguageModelMacros/GenerableMacro.swift | Implements type analysis helpers and updates partial type generation logic for arrays |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 9 comments.
Comments suppressed due to low confidence (1)
Sources/AnyLanguageModelMacros/GenerableMacro.swift:1
- The depth check at line 194 occurs inside the loop but after the switch statement, which means negative depth from mismatched brackets won't be caught until after processing the current character. For example, with input
]:[String], the function would decrement depth to -1 but continue processing. The check should occur after each depth modification to catch structural errors earlier. Move the depth check inside each case that modifies totalDepth.
import SwiftCompilerPlugin
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@ethanhuang13 Thanks again for your help. Merging this PR now. |
Summary
[Element.PartiallyGenerated]instead of[Element].Problem
When a
@Generablestruct has an array property (e.g.[CatProfile]), the AnyLanguageModel macro previously synthesized the partially generated property as[CatProfile], not a partially generated array. This breaks SwiftUI usage and diverges from FoundationModels’ macro output.FoundationModels’
GenerableMacroproduces a partially generated property of type[CatProfile.PartiallyGenerated]?, and AnyLanguageModel needed to align with that output.Example
Before
public var catProfiles: [CatProfile](not partially generated)ForEach(catProfiles.asPartiallyGenerated())to get the correct shape for SwiftUI.After
public var catProfiles: [CatProfile.PartiallyGenerated]?ForEach(catProfiles)with no extra conversion.Testing
swift test(new GenerableMacro test passes).