fix: make Unpacker.readUnion usable - #26
Merged
Merged
Conversation
readUnion declared `!?T` while unpackUnion returns `!T`, adding one optional level too many. unpackUnion already handles the optional case internally via NonOptional(T) and the `?u16` map-header path, so the extra `?` made every instantiation a type error: `readUnion(U)` could not coerce `U` to `?U`, and `readUnion(?U)` could not coerce `?U` to `??U`. Return `!T`, matching how readStruct forwards to unpackStruct. Callers wanting the nullable behaviour pass `?U`, which already works. refAllDecls does not instantiate generic functions, so this was never covered. Add a test that reads both a union and an optional union.
|
Warning Review limit reachedNext included review available in 58 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: 📒 Files selected for processing (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Fixes #22.
Unpacker.readUnionpromises one more level of optional thanunpackUnionreturns, so it cannot be instantiated with any type argument:unpackUnionreturns!Tand already handles the optional case internally, viaNonOptional(T)and the?u16map-header path. The extra?makes both readings a type error:readUnion(U)→ "error union payload 'U' cannot cast into error union payload '?U'"readUnion(?U)→ "optional type child 'U' cannot cast into optional type child '?U'"Returning
!Tmatches howreadStructforwards tounpackStruct. Callers wanting the nullable behaviour pass?U, whichunpackUnionalready supports — the added test covers both.Why CI was green
Same reason as #21:
refAllDeclsdoes not instantiate generic functions, so nothing ever type-checked this. Reverting the signature makes the new test fail to compile.I exercised every other method on
PackerandUnpackeronce each while investigating; this andreadArray(#21, PR #25) were the only two that were uninstantiable. Everything else compiles and round trips.zig build test: 154/154 pass.