mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Disallow ambiguous conversions between number literals and bytesXX types.
This commit is contained in:
-5
@@ -1,5 +0,0 @@
|
||||
contract Foo {
|
||||
bytes32 a = 7;
|
||||
}
|
||||
// ----
|
||||
// Warning: (31-32): Decimal literal assigned to bytesXX variable will be left-aligned. Use an explicit conversion to silence this warning.
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
contract Foo {
|
||||
bytes32 a = 0x1234;
|
||||
}
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
contract Foo {
|
||||
bytes32 a = bytes32(7);
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
contract C {
|
||||
byte b = byte(1);
|
||||
byte b = byte(0x01);
|
||||
bytes1 b1 = b;
|
||||
bytes2 b2 = b1;
|
||||
bytes3 b3 = b2;
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
bytes1 b1 = bytes1(1);
|
||||
bytes2 b2 = bytes2(1);
|
||||
bytes2 b3 = bytes2(256);
|
||||
bytes3 b4 = bytes3(1);
|
||||
bytes3 b5 = bytes3(65536);
|
||||
bytes4 b6 = bytes4(1);
|
||||
bytes4 b7 = bytes4(16777216);
|
||||
bytes16 b8 = bytes16(1);
|
||||
bytes32 b9 = bytes32(1);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (60-69): Explicit type conversion not allowed from "int_const 1" to "bytes1".
|
||||
// TypeError: (88-97): Explicit type conversion not allowed from "int_const 1" to "bytes2".
|
||||
// TypeError: (116-127): Explicit type conversion not allowed from "int_const 256" to "bytes2".
|
||||
// TypeError: (146-155): Explicit type conversion not allowed from "int_const 1" to "bytes3".
|
||||
// TypeError: (174-187): Explicit type conversion not allowed from "int_const 65536" to "bytes3".
|
||||
// TypeError: (206-215): Explicit type conversion not allowed from "int_const 1" to "bytes4".
|
||||
// TypeError: (234-250): Explicit type conversion not allowed from "int_const 16777216" to "bytes4".
|
||||
// TypeError: (270-280): Explicit type conversion not allowed from "int_const 1" to "bytes16".
|
||||
// TypeError: (300-310): Explicit type conversion not allowed from "int_const 1" to "bytes32".
|
||||
@@ -0,0 +1,23 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
bytes1 b1 = 1;
|
||||
bytes2 b2 = 1;
|
||||
bytes2 b3 = 256;
|
||||
bytes3 b4 = 1;
|
||||
bytes3 b5 = 65536;
|
||||
bytes4 b6 = 1;
|
||||
bytes4 b7 = 16777216;
|
||||
bytes16 b8 = 1;
|
||||
bytes32 b9 = 1;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (48-61): Type int_const 1 is not implicitly convertible to expected type bytes1.
|
||||
// TypeError: (68-81): Type int_const 1 is not implicitly convertible to expected type bytes2.
|
||||
// TypeError: (88-103): Type int_const 256 is not implicitly convertible to expected type bytes2.
|
||||
// TypeError: (110-123): Type int_const 1 is not implicitly convertible to expected type bytes3.
|
||||
// TypeError: (130-147): Type int_const 65536 is not implicitly convertible to expected type bytes3.
|
||||
// TypeError: (154-167): Type int_const 1 is not implicitly convertible to expected type bytes4.
|
||||
// TypeError: (174-194): Type int_const 16777216 is not implicitly convertible to expected type bytes4.
|
||||
// TypeError: (201-215): Type int_const 1 is not implicitly convertible to expected type bytes16.
|
||||
// TypeError: (222-236): Type int_const 1 is not implicitly convertible to expected type bytes32.
|
||||
@@ -0,0 +1,31 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
bytes1 b1 = bytes1(0x1);
|
||||
bytes1 b2 = bytes1(0x100);
|
||||
bytes2 b3 = bytes2(0xFF);
|
||||
bytes2 b4 = bytes2(0x100);
|
||||
bytes2 b5 = bytes2(0x10000);
|
||||
bytes3 b6 = bytes3(0xFFFF);
|
||||
bytes3 b7 = bytes3(0x10000);
|
||||
bytes3 b8 = bytes3(0x1000000);
|
||||
bytes4 b9 = bytes4(0xFFFFFF);
|
||||
bytes4 b10 = bytes4(0x1000000);
|
||||
bytes4 b11 = bytes4(0x100000000);
|
||||
bytes16 b12 = bytes16(0x1);
|
||||
bytes32 b13 = bytes32(0x1);
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (60-71): Explicit type conversion not allowed from "int_const 1" to "bytes1".
|
||||
// TypeError: (90-103): Explicit type conversion not allowed from "int_const 256" to "bytes1".
|
||||
// TypeError: (122-134): Explicit type conversion not allowed from "int_const 255" to "bytes2".
|
||||
// TypeError: (153-166): Explicit type conversion not allowed from "int_const 256" to "bytes2".
|
||||
// TypeError: (185-200): Explicit type conversion not allowed from "int_const 65536" to "bytes2".
|
||||
// TypeError: (219-233): Explicit type conversion not allowed from "int_const 65535" to "bytes3".
|
||||
// TypeError: (252-267): Explicit type conversion not allowed from "int_const 65536" to "bytes3".
|
||||
// TypeError: (286-303): Explicit type conversion not allowed from "int_const 16777216" to "bytes3".
|
||||
// TypeError: (322-338): Explicit type conversion not allowed from "int_const 16777215" to "bytes4".
|
||||
// TypeError: (358-375): Explicit type conversion not allowed from "int_const 16777216" to "bytes4".
|
||||
// TypeError: (395-414): Explicit type conversion not allowed from "int_const 4294967296" to "bytes4".
|
||||
// TypeError: (435-447): Explicit type conversion not allowed from "int_const 1" to "bytes16".
|
||||
// TypeError: (468-480): Explicit type conversion not allowed from "int_const 1" to "bytes32".
|
||||
@@ -0,0 +1,31 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
bytes1 b1 = 0x1;
|
||||
bytes1 b2 = 0x100;
|
||||
bytes2 b3 = 0xFF;
|
||||
bytes2 b4 = 0x100;
|
||||
bytes2 b5 = 0x10000;
|
||||
bytes3 b6 = 0xFFFF;
|
||||
bytes3 b7 = 0x10000;
|
||||
bytes3 b8 = 0x1000000;
|
||||
bytes4 b9 = 0xFFFFFF;
|
||||
bytes4 b10 = 0x1000000;
|
||||
bytes4 b11 = 0x100000000;
|
||||
bytes16 b12 = 0x1;
|
||||
bytes32 b13 = 0x1;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (48-63): Type int_const 1 is not implicitly convertible to expected type bytes1.
|
||||
// TypeError: (70-87): Type int_const 256 is not implicitly convertible to expected type bytes1.
|
||||
// TypeError: (94-110): Type int_const 255 is not implicitly convertible to expected type bytes2.
|
||||
// TypeError: (117-134): Type int_const 256 is not implicitly convertible to expected type bytes2.
|
||||
// TypeError: (141-160): Type int_const 65536 is not implicitly convertible to expected type bytes2.
|
||||
// TypeError: (167-185): Type int_const 65535 is not implicitly convertible to expected type bytes3.
|
||||
// TypeError: (192-211): Type int_const 65536 is not implicitly convertible to expected type bytes3.
|
||||
// TypeError: (218-239): Type int_const 16777216 is not implicitly convertible to expected type bytes3.
|
||||
// TypeError: (246-266): Type int_const 16777215 is not implicitly convertible to expected type bytes4.
|
||||
// TypeError: (273-295): Type int_const 16777216 is not implicitly convertible to expected type bytes4.
|
||||
// TypeError: (302-326): Type int_const 4294967296 is not implicitly convertible to expected type bytes4.
|
||||
// TypeError: (333-350): Type int_const 1 is not implicitly convertible to expected type bytes16.
|
||||
// TypeError: (357-374): Type int_const 1 is not implicitly convertible to expected type bytes32.
|
||||
@@ -0,0 +1,13 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
bytes1 b1 = bytes1(0x01);
|
||||
bytes1 b2 = bytes1(0xFF);
|
||||
bytes2 b3 = bytes2(0x0100);
|
||||
bytes2 b4 = bytes2(0xFFFF);
|
||||
bytes3 b5 = bytes3(0x010000);
|
||||
bytes3 b6 = bytes3(0xFFFFFF);
|
||||
bytes4 b7 = bytes4(0x01000000);
|
||||
bytes4 b8 = bytes4(0xFFFFFFFF);
|
||||
b1; b2; b3; b4; b5; b6; b7; b8;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
bytes1 b1 = 0x01;
|
||||
bytes1 b2 = 0xFF;
|
||||
bytes2 b3 = 0x0100;
|
||||
bytes2 b4 = 0xFFFF;
|
||||
bytes3 b5 = 0x010000;
|
||||
bytes3 b6 = 0xFFFFFF;
|
||||
bytes4 b7 = 0x01000000;
|
||||
bytes4 b8 = 0xFFFFFFFF;
|
||||
b1; b2; b3; b4; b5; b6; b7; b8;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
bytes1 b1 = bytes1(0);
|
||||
bytes2 b2 = bytes2(0);
|
||||
bytes3 b3 = bytes3(0);
|
||||
bytes4 b4 = bytes4(0);
|
||||
bytes8 b8 = bytes8(0);
|
||||
bytes16 b16 = bytes16(0);
|
||||
bytes32 b32 = bytes32(0);
|
||||
b1; b2; b3; b4; b8; b16; b32;
|
||||
}
|
||||
function g() public pure {
|
||||
bytes1 b1 = bytes1(0x000);
|
||||
bytes2 b2 = bytes2(0x00000);
|
||||
bytes3 b3 = bytes3(0x0000000);
|
||||
bytes4 b4 = bytes4(0x000000000);
|
||||
bytes8 b8 = bytes8(0x00000000000000000);
|
||||
b1; b2; b3; b4; b8;
|
||||
}
|
||||
function h() public pure {
|
||||
bytes1 b1 = bytes1(0x0);
|
||||
bytes2 b2 = bytes2(0x0);
|
||||
bytes3 b3 = bytes3(0x0);
|
||||
bytes4 b4 = bytes4(0x0);
|
||||
bytes8 b8 = bytes8(0x0);
|
||||
bytes16 b16 = bytes16(0x0);
|
||||
bytes32 b32 = bytes32(0x0);
|
||||
b1; b2; b3; b4; b8; b16; b32;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
bytes1 b1 = 0;
|
||||
bytes2 b2 = 0;
|
||||
bytes3 b3 = 0;
|
||||
bytes4 b4 = 0;
|
||||
bytes8 b8 = 0;
|
||||
bytes16 b16 = 0;
|
||||
bytes32 b32 = 0;
|
||||
b1; b2; b3; b4; b8; b16; b32;
|
||||
}
|
||||
function g() public pure {
|
||||
bytes1 b1 = 0x000;
|
||||
bytes2 b2 = 0x00000;
|
||||
bytes3 b3 = 0x0000000;
|
||||
bytes4 b4 = 0x000000000;
|
||||
bytes8 b8 = 0x00000000000000000;
|
||||
b1; b2; b3; b4; b8;
|
||||
}
|
||||
function h() public pure {
|
||||
bytes1 b1 = 0x0;
|
||||
bytes2 b2 = 0x0;
|
||||
bytes3 b3 = 0x0;
|
||||
bytes4 b4 = 0x0;
|
||||
bytes8 b8 = 0x0;
|
||||
bytes16 b16 = 0x0;
|
||||
bytes32 b32 = 0x0;
|
||||
b1; b2; b3; b4; b8; b16; b32;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ contract C {
|
||||
function g() pure public {
|
||||
bytes32 x = keccak256("abc");
|
||||
bytes32 y = sha256("abc");
|
||||
address z = ecrecover(bytes32(1), uint8(2), bytes32(3), bytes32(4));
|
||||
address z = ecrecover(bytes32(uint256(1)), uint8(2), bytes32(uint256(3)), bytes32(uint256(4)));
|
||||
require(true);
|
||||
assert(true);
|
||||
x; y; z;
|
||||
|
||||
@@ -2,7 +2,7 @@ contract C {
|
||||
function f() view public {
|
||||
bytes32 x = keccak256("abc");
|
||||
bytes32 y = sha256("abc");
|
||||
address z = ecrecover(bytes32(1), uint8(2), bytes32(3), bytes32(4));
|
||||
address z = ecrecover(bytes32(uint256(1)), uint8(2), bytes32(uint256(3)), bytes32(uint256(4)));
|
||||
require(true);
|
||||
assert(true);
|
||||
x; y; z;
|
||||
@@ -10,12 +10,12 @@ contract C {
|
||||
function g() public {
|
||||
bytes32 x = keccak256("abc");
|
||||
bytes32 y = sha256("abc");
|
||||
address z = ecrecover(bytes32(1), uint8(2), bytes32(3), bytes32(4));
|
||||
address z = ecrecover(bytes32(uint256(1)), uint8(2), bytes32(uint256(3)), bytes32(uint256(4)));
|
||||
require(true);
|
||||
assert(true);
|
||||
x; y; z;
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// Warning: (17-261): Function state mutability can be restricted to pure
|
||||
// Warning: (266-505): Function state mutability can be restricted to pure
|
||||
// Warning: (17-288): Function state mutability can be restricted to pure
|
||||
// Warning: (293-559): Function state mutability can be restricted to pure
|
||||
|
||||
Reference in New Issue
Block a user