Disallow conversions between bytesX and uintY of different size.

This commit is contained in:
Daniel Kirchner
2018-05-16 18:32:47 +02:00
committed by chriseth
parent 76fc4f8e00
commit 5c59d56335
12 changed files with 73 additions and 19 deletions
+9
View File
@@ -975,6 +975,15 @@ cut off::
uint32 a = 0x12345678;
uint16 b = uint16(a); // b will be 0x5678 now
Since 0.5.0 explicit conversions between integers and fixed-size byte arrays
are only allowed, if both have the same size. To convert between integers and
fixed-size byte arrays of different size, they first have to be explicitly
converted to a matching size. This makes alignment and padding explicit::
uint16 x = 0xffff;
bytes32(uint256(x)); // pad on the left
bytes32(bytes2(x)); // pad on the right
.. index:: ! type;deduction, ! var
.. _type-deduction: