mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
add two overloaded function test cases
This commit is contained in:
parent
b87c5547a5
commit
1da211920e
@ -3218,10 +3218,13 @@ BOOST_AUTO_TEST_CASE(derived_overload_base_function_direct)
|
|||||||
{
|
{
|
||||||
char const* sourceCode = R"(
|
char const* sourceCode = R"(
|
||||||
contract B { function f() returns(uint) { return 10; } }
|
contract B { function f() returns(uint) { return 10; } }
|
||||||
contract C is B { function f(uint i) returns(uint) { return 2 * i; } }
|
contract C is B {
|
||||||
|
function f(uint i) returns(uint) { return 2 * i; }
|
||||||
|
function g() returns(uint) { return f(1); }
|
||||||
|
}
|
||||||
)";
|
)";
|
||||||
compileAndRun(sourceCode, "C");
|
compileAndRun(sourceCode, 0, "C");
|
||||||
BOOST_CHECK(callContractFunction("f(uint)", 1) == encodeArgs(2));
|
BOOST_CHECK(callContractFunction("g()") == encodeArgs(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(derived_overload_base_function_indirect)
|
BOOST_AUTO_TEST_CASE(derived_overload_base_function_indirect)
|
||||||
@ -3229,11 +3232,14 @@ BOOST_AUTO_TEST_CASE(derived_overload_base_function_indirect)
|
|||||||
char const* sourceCode = R"(
|
char const* sourceCode = R"(
|
||||||
contract A { function f(uint a) returns(uint) { return 2 * a; } }
|
contract A { function f(uint a) returns(uint) { return 2 * a; } }
|
||||||
contract B { function f() returns(uint) { return 10; } }
|
contract B { function f() returns(uint) { return 10; } }
|
||||||
contract C is A, B { }
|
contract C is A, B {
|
||||||
|
function g() returns(uint) { return f(); }
|
||||||
|
function h() returns(uint) { return f(1); }
|
||||||
|
}
|
||||||
)";
|
)";
|
||||||
compileAndRun(sourceCode, "C");
|
compileAndRun(sourceCode, 0, "C");
|
||||||
BOOST_CHECK(callContractFunction("f(uint)", 1) == encodeArgs(2));
|
BOOST_CHECK(callContractFunction("g()") == encodeArgs(10));
|
||||||
BOOST_CHECK(callContractFunction("f()") == encodeArgs(10));
|
BOOST_CHECK(callContractFunction("h()") == encodeArgs(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
@ -1287,6 +1287,31 @@ BOOST_AUTO_TEST_CASE(storage_variable_initialization_with_incorrect_type_string)
|
|||||||
BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
|
BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(overloaded_function_cannot_resolve)
|
||||||
|
{
|
||||||
|
char const* sourceCode = R"(
|
||||||
|
contract test {
|
||||||
|
function f() returns(uint) { return 1; }
|
||||||
|
function f(uint a) returns(uint) { return a; }
|
||||||
|
function g() returns(uint) { return f(3, 5); }
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(ambiguous_overloaded_function)
|
||||||
|
{
|
||||||
|
// literal 1 can be both converted to uint8 and uint8, so it's ambiguous.
|
||||||
|
char const* sourceCode = R"(
|
||||||
|
contract test {
|
||||||
|
function f(uint8 a) returns(uint) { return a; }
|
||||||
|
function f(uint a) returns(uint) { return 2*a; }
|
||||||
|
function g() returns(uint) { return f(1); }
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
BOOST_CHECK_THROW(parseTextAndResolveNames(sourceCode), TypeError);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user