Skip to content

feat: add polymorphic support#45

Merged
fish-sammy merged 2 commits intorefactor/rename-functionsfrom
feat/add-polymorphic-support
Oct 16, 2025
Merged

feat: add polymorphic support#45
fish-sammy merged 2 commits intorefactor/rename-functionsfrom
feat/add-polymorphic-support

Conversation

@fish-sammy
Copy link
Contributor

@fish-sammy fish-sammy commented Oct 6, 2025

No description provided.

@fish-sammy fish-sammy changed the title feat/add polymorphic support feat: add polymorphic support Oct 6, 2025
@fish-sammy fish-sammy force-pushed the feat/add-polymorphic-support branch from 5620673 to 3ec2de0 Compare October 6, 2025 06:52
@fish-sammy fish-sammy changed the base branch from feat/typed-encoder to refactor/rename-functions October 6, 2025 06:52
@fish-sammy fish-sammy force-pushed the refactor/rename-functions branch from 5b5d9da to b065359 Compare October 6, 2025 06:55
@fish-sammy fish-sammy force-pushed the feat/add-polymorphic-support branch from 3ec2de0 to 9d7c67b Compare October 6, 2025 06:55
@fish-sammy fish-sammy requested a review from Copilot October 6, 2025 06:56
Copy link

Copilot AI left a 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 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 EncodingType enum with Struct and PolymorphicArray options
  • Enhanced the Struct type to include an encodingType field
  • 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.

struct Struct {
bytes32 typeHash;
Chunk[] chunks;
EncodingType encodingType;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put encodingType as the first or second field in the struct. Before Chunk[] chunks

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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use custom errors instead of revert strings

@fish-sammy fish-sammy merged commit e74eac5 into refactor/rename-functions Oct 16, 2025
2 checks passed
@fish-sammy fish-sammy deleted the feat/add-polymorphic-support branch October 16, 2025 17:10
re1ro pushed a commit that referenced this pull request Oct 28, 2025
* feat: add polymorphic support

* address PR comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants