mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Disallow conversions between bytesX and uintY of different size.
This commit is contained in:
committed by
chriseth
parent
76fc4f8e00
commit
5c59d56335
@@ -263,7 +263,7 @@ library RLP {
|
||||
var (rStartPos, len) = _decode(self);
|
||||
if (len != 1)
|
||||
throw;
|
||||
uint temp;
|
||||
uint8 temp;
|
||||
assembly {
|
||||
temp := byte(0, mload(rStartPos))
|
||||
}
|
||||
|
||||
@@ -3859,19 +3859,6 @@ BOOST_AUTO_TEST_CASE(conditional_with_all_types)
|
||||
CHECK_SUCCESS(text);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(index_access_for_bytes)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract C {
|
||||
bytes20 x;
|
||||
function f(bytes16 b) public {
|
||||
b[uint(x[2])];
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_SUCCESS(text);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(uint7_and_uintM_as_identifier)
|
||||
{
|
||||
char const* text = R"(
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
function f() public pure returns(uint256) {
|
||||
return uint256(bytes1(''));
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (76-95): Explicit type conversion not allowed from "bytes1" to "uint256".
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
function f() public pure returns(uint32) {
|
||||
return uint32(bytes32(''));
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (75-94): Explicit type conversion not allowed from "bytes32" to "uint32".
|
||||
@@ -1,7 +1,7 @@
|
||||
contract C {
|
||||
function f() public pure {
|
||||
C(bytes20(0x1234));
|
||||
C(bytes20(uint160(0x1234)));
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (64-82): Explicit type conversion not allowed from "bytes20" to "contract C".
|
||||
// TypeError: (64-91): Explicit type conversion not allowed from "bytes20" to "contract C".
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
contract C {
|
||||
function f() public pure returns (uint256) {
|
||||
return uint256(bytes32(uint256(0)));
|
||||
}
|
||||
function g() public pure returns (uint128) {
|
||||
return uint128(bytes16(uint128(0)));
|
||||
}
|
||||
function h() public pure returns (uint64) {
|
||||
return uint64(bytes8(uint64(0)));
|
||||
}
|
||||
function i() public pure returns (uint32) {
|
||||
return uint32(bytes4(uint32(0)));
|
||||
}
|
||||
function j() public pure returns (uint16) {
|
||||
return uint16(bytes2(uint16(0)));
|
||||
}
|
||||
function k() public pure returns (uint8) {
|
||||
return uint8(bytes1(uint8(0)));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
contract C {
|
||||
bytes20 x;
|
||||
function f(bytes16 b) public view {
|
||||
b[uint8(x[2])];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
function f() public pure returns(bytes1) {
|
||||
return bytes1(uint256(0));
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (75-93): Explicit type conversion not allowed from "uint256" to "bytes1".
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
function f() public pure returns(bytes32) {
|
||||
return bytes32(uint32(0));
|
||||
}
|
||||
}
|
||||
// ----
|
||||
// TypeError: (76-94): Explicit type conversion not allowed from "uint32" to "bytes32".
|
||||
Reference in New Issue
Block a user