feat: add polymorphic support#45
Merged
fish-sammy merged 2 commits intorefactor/rename-functionsfrom Oct 16, 2025
Merged
Conversation
5620673 to
3ec2de0
Compare
5b5d9da to
b065359
Compare
3ec2de0 to
9d7c67b
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR adds polymorphic support to the TypedEncoder library, enabling structs to be encoded as arrays where each element's nested structs are encoded as bytes. This allows for handling different struct types within the same array structure.
Key changes:
- Added
EncodingTypeenum withStructandPolymorphicArrayoptions - Enhanced the
Structtype to include anencodingTypefield - Implemented polymorphic array encoding logic with specialized handling for struct-to-bytes conversion
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/libs/TypedEncoder.sol | Core implementation of polymorphic encoding support with new enum, struct field, and encoding logic |
| test/libs/TypedEncoderPolymorphic.t.sol | Comprehensive test suite for polymorphic functionality with complex nested structures |
| test/libs/TypedEncoderHash.t.sol | Updated existing hash tests to include the new encodingType field |
| test/libs/TypedEncoderEncode.t.sol | Updated existing encoding tests to include the new encodingType field |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
re1ro
reviewed
Oct 9, 2025
| struct Struct { | ||
| bytes32 typeHash; | ||
| Chunk[] chunks; | ||
| EncodingType encodingType; |
Collaborator
There was a problem hiding this comment.
I would put encodingType as the first or second field in the struct. Before Chunk[] chunks
re1ro
reviewed
Oct 9, 2025
src/libs/TypedEncoder.sol
Outdated
Comment on lines
92
to
93
| if (s.chunks[i].primitives.length > 0 || s.chunks[i].arrays.length > 0) { | ||
| revert("PolymorphicArray only supports struct fields"); |
Collaborator
There was a problem hiding this comment.
We should use custom errors instead of revert strings
re1ro
approved these changes
Oct 16, 2025
re1ro
pushed a commit
that referenced
this pull request
Oct 28, 2025
* feat: add polymorphic support * address PR 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.
No description provided.