fix(widget): decode array-of-object entryFields into Codable, not String (#5070)#5155
Conversation
iOS-widget SwiftUI codegen emitted the entry struct field for an array-of-objects `entryFields` member with the correct nested-Codable type (`[<Name><Field>Item]`), but the TimelineProvider decode site cast the JSON value to `String` (`entryDict["x"] as? String ?? ""`), so the generated Swift failed to compile. Factor the per-field decode into `entry_field_decode` (shared by both the native and AppIntent provider paths) and round-trip array/object/optional fields through JSONSerialization + JSONDecoder into the nested Codable struct. Scalars and scalar arrays keep their direct `as?` casts. This also unblocks `ForEach(entry.<field>, ...)` in render bodies. Fixes #5070
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
✅ Files skipped from review due to trivial changes (2)
📝 WalkthroughWalkthroughThe Swift emitter gains two new private helpers, ChangesSwiftUI Entry Field Decode Fix
Android Link Path Formatting
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Pre-existing fmt drift from #5154 (Android NDK `.cmd` if-else); rustfmt 1.96.0 expands the single-line if/else. Unrelated to the widget fix but required to get `cargo fmt --all -- --check` (the lint gate) green.
|
Added a second commit ( |
Summary
Fixes #5070. An iOS-widget
perry/widgetentryFieldsmember that is an array of objects generated the correct nested-Codabletype for the entry-struct field ([<Name><Field>Item]), but theTimelineProviderdecode site cast the JSON value toString:…so the generated Swift didn't compile.
Fix
Factor the per-field decode logic out of the two duplicated inline
matchblocks (native + AppIntent provider paths) into a singleentry_field_decodehelper.Array-of-object (and other JSON-backed nested) fields now round-trip through
JSONSerialization+JSONDecoderinto the nestedCodablestruct(s):Arrays of scalars now cast to
[String]/[Double]/[Bool](previously also fell through to theStringcast).Optionals of scalars cast to the matching optional type.
Scalars are unchanged.
This also unblocks
ForEach(entry.<field>, ...)in render bodies.Testing
test_timeline_decode_array_of_objectsasserts the decode site no longer casts the object array toStringand instead decodes into[TopSitesSitesItem].cargo test -p perry-codegen-swiftui— 19 passed.cargo fmt+cargo clippy -p perry-codegen-swiftuiclean.Per maintainer policy for this PR, no version bump or changelog entry is included.
Summary by CodeRabbit
Codableresults instead of being coerced toString.Codabledecoding path..cmdhandling.