-
Notifications
You must be signed in to change notification settings - Fork 5.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bytes to bytesNN conversion #11047
Bytes to bytesNN conversion #11047
Conversation
Please also fix https://github.com/ethereum/solidity/pull/9167/files |
6e8ab8e
to
de8e09f
Compare
889bae1
to
79dc623
Compare
This is now ready for review |
Changelog.md
Outdated
@@ -1,7 +1,7 @@ | |||
### 0.8.3 (unreleased) | |||
|
|||
Language Features: | |||
|
|||
* Allowing conversion from ``bytes`` to ``bytes1``/.../``bytes32``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has to be moved.
db4ef20
to
ff0c772
Compare
PR is updated to truncate instead of panic. |
4feaade
to
776ed2e
Compare
Changelog.md
Outdated
@@ -1,6 +1,7 @@ | |||
### 0.8.5 (unreleased) | |||
|
|||
Language Features: | |||
* Allowing conversion from ``bytes`` to ``bytes1``/.../``bytes32``. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and byte array slices?
@@ -99,6 +99,27 @@ rules explicit:: | |||
uint8 d = uint8(uint16(a)); // d will be 0x34 | |||
uint8 e = uint8(bytes1(a)); // e will be 0x12 | |||
|
|||
``bytes`` arrays and ``bytes`` calldata slices can be converted explicitly to fixed bytes types (``bytes1``/.../``bytes32``). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we usually list the allowed explicit conversions in the sections about the individual types. Can you check and maybe add something there as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find anything for bytes
but will check once more
Looks good apart from the documentation bits! |
776ed2e
to
fc82f3a
Compare
11d3291
to
42bd89e
Compare
solAssert( | ||
argArrayType->location() != DataLocation::Storage || | ||
( | ||
if (auto resultArrayType = dynamic_cast<ArrayType const*>(resultType)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Holy... this assertion is complicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't change it, but yes, it is too complicated. I can maybe refactor it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pulling the variable declaration inside does not make it simpler :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry, I thought it was an if (x; y)
if (_convertTo.category() != category()) | ||
return false; | ||
return isByteArray() && !isString() && _convertTo.category() == Type::Category::FixedBytes; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is isByteArray()
true for bytes1[]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, it is regular array type of bytes1
typeOnStack.isByteArray() && !typeOnStack.isString(), | ||
"Array types other than bytes not convertible to bytesNN." | ||
); | ||
solAssert(typeOnStack.isDynamicallySized(), ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These three settings suggest to me we may want to have something like isDynamicBytes()
at some point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely, we need to check if it occurs in multiple places and add such helper
Co-authored-by: Alex Beregszaszi <[email protected]>
Co-authored-by: chriseth <[email protected]> Co-authored-by: Alex Beregszaszi <[email protected]>
c54ec13
to
337adee
Compare
Fixes #9170
TODO: