mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Error on invalid arithmetic with constant expressions.
This commit is contained in:
@@ -7847,12 +7847,12 @@ BOOST_AUTO_TEST_CASE(addmod_mulmod_zero)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract C {
|
||||
function f() pure returns (uint) {
|
||||
addmod(1, 2, 0);
|
||||
function f(uint d) pure returns (uint) {
|
||||
addmod(1, 2, d);
|
||||
return 2;
|
||||
}
|
||||
function g() pure returns (uint) {
|
||||
mulmod(1, 2, 0);
|
||||
function g(uint d) pure returns (uint) {
|
||||
mulmod(1, 2, d);
|
||||
return 2;
|
||||
}
|
||||
function h() pure returns (uint) {
|
||||
@@ -7865,8 +7865,8 @@ BOOST_AUTO_TEST_CASE(addmod_mulmod_zero)
|
||||
}
|
||||
)";
|
||||
compileAndRun(sourceCode);
|
||||
ABI_CHECK(callContractFunction("f()"), encodeArgs());
|
||||
ABI_CHECK(callContractFunction("g()"), encodeArgs());
|
||||
ABI_CHECK(callContractFunction("f(uint)", 0), encodeArgs());
|
||||
ABI_CHECK(callContractFunction("g(uint)", 0), encodeArgs());
|
||||
ABI_CHECK(callContractFunction("h()"), encodeArgs(2));
|
||||
}
|
||||
|
||||
|
||||
@@ -4920,20 +4920,6 @@ BOOST_AUTO_TEST_CASE(integer_and_fixed_interaction)
|
||||
CHECK_SUCCESS(text);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(signed_rational_modulus)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract test {
|
||||
function f() public {
|
||||
fixed a = 0.42578125 % -0.4271087646484375;
|
||||
fixed b = .5 % a;
|
||||
fixed c = a % b;
|
||||
}
|
||||
}
|
||||
)";
|
||||
CHECK_SUCCESS(text);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(one_divided_by_three_integer_conversion)
|
||||
{
|
||||
char const* text = R"(
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
contract C {
|
||||
uint constant a = addmod(3, 4, 0.1);
|
||||
uint constant b = mulmod(3, 4, 0.1);
|
||||
}
|
||||
// ----
|
||||
// TypeError: (48-51): Invalid type for argument in function call. Invalid implicit conversion from rational_const 1 / 10 to uint256 requested.
|
||||
// TypeError: (89-92): Invalid type for argument in function call. Invalid implicit conversion from rational_const 1 / 10 to uint256 requested.
|
||||
@@ -0,0 +1,11 @@
|
||||
contract c {
|
||||
uint constant a1 = 0;
|
||||
uint constant a2 = 1;
|
||||
uint constant b1 = addmod(3, 4, 0);
|
||||
uint constant b2 = addmod(3, 4, a1);
|
||||
uint constant b3 = addmod(3, 4, a2 - 1);
|
||||
}
|
||||
// ----
|
||||
// TypeError: (88-103): Arithmetic modulo zero.
|
||||
// TypeError: (128-144): Arithmetic modulo zero.
|
||||
// TypeError: (169-189): Arithmetic modulo zero.
|
||||
@@ -0,0 +1,9 @@
|
||||
contract c {
|
||||
uint constant a1 = 0;
|
||||
uint constant a2 = 1;
|
||||
uint constant b1 = 7 / a1;
|
||||
uint constant b2 = 7 / (a2 - 1);
|
||||
}
|
||||
// ----
|
||||
// TypeError: (88-94): Division by zero.
|
||||
// TypeError: (119-131): Division by zero.
|
||||
@@ -0,0 +1,6 @@
|
||||
contract C {
|
||||
fixed a1 = 0.1 % -0.4271087646484375;
|
||||
fixed a2 = 0.1 % 0.4271087646484375;
|
||||
fixed a3 = 0 / 0.123;
|
||||
fixed a4 = 0 / -0.123;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
contract c {
|
||||
uint constant a1 = 0;
|
||||
uint constant a2 = 1;
|
||||
uint constant b1 = 3 % a1;
|
||||
uint constant b2 = 3 % (a2 - 1);
|
||||
}
|
||||
// ----
|
||||
// TypeError: (88-94): Modulo zero.
|
||||
// TypeError: (119-131): Modulo zero.
|
||||
@@ -0,0 +1,11 @@
|
||||
contract c {
|
||||
uint constant a1 = 0;
|
||||
uint constant a2 = 1;
|
||||
uint constant b1 = mulmod(3, 4, 0);
|
||||
uint constant b2 = mulmod(3, 4, a1);
|
||||
uint constant b3 = mulmod(3, 4, a2 - 1);
|
||||
}
|
||||
// ----
|
||||
// TypeError: (88-103): Arithmetic modulo zero.
|
||||
// TypeError: (128-144): Arithmetic modulo zero.
|
||||
// TypeError: (169-189): Arithmetic modulo zero.
|
||||
@@ -0,0 +1,8 @@
|
||||
contract test {
|
||||
function f() public pure {
|
||||
fixed a = 0.42578125 % -0.4271087646484375;
|
||||
fixed b = .5 % a;
|
||||
fixed c = a % b;
|
||||
a; b; c;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user