Closed
Conversation
Adds a high-level `revert<T: Encode<Sol> + AbiSize>(T) -> !` function that ABI-encodes the value and reverts, and an `EvmResultExt` extension trait on `Result` providing `unwrap_or_revert()` for ergonomic error handling in recv handlers.
Collaborator
Author
|
@sbillig in this PR the new |
abi_static_size_bytes() only handled primitives and structs/tuples, causing encoded_size<T>() to fail at codegen when T is an enum. The extern intrinsic has no body, so when the compile-time constant folding failed, the call fell through to a missing function. Add enum support: discriminant word (32 bytes) + max variant payload, mirroring the pattern in layout::ty_size_bytes.
Collaborator
Author
|
@codex review |
Collaborator
Author
|
This landed in a slightly different way as #1342 |
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.
Add
revert<T>()andEvmResultExttrait to std librarySummary
revert<T: Encode<Sol> + AbiSize>(T) -> !function that ABI-encodes the value and reverts with the encoded bytes as revert dataEvmResultExtextension trait onResultprovidingunwrap_or_revert()— onOkit returns the value, onErrit ABI-encodes the error and revertsstd::evm::{revert, EvmResultExt})encoded_size<T>()intrinsic for enum types —abi_static_size_bytes()only handled primitives and structs/tuples, causing a codegen failure ("unknown function: encoded_size__...") whenTis anenum. Added enum support: discriminant word (32 bytes) + max variant payload
revertandunwrap_or_revertAPITest plan
test_revert_with_error—revert()with a custom error enum (should_revert)test_revert_with_u256—revert()with a primitiveu256value (should_revert)test_unwrap_or_revert_ok—unwrap_or_revert()onOkreturns the inner valuetest_unwrap_or_revert_err—unwrap_or_revert()onErrreverts (should_revert)