mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
add test cases for functions in derived overload functions in base
This commit is contained in:
parent
7d7f9ec67f
commit
b87c5547a5
@ -3214,6 +3214,30 @@ BOOST_AUTO_TEST_CASE(overloaded_function_call_with_if_else)
|
||||
BOOST_CHECK(callContractFunction("g(bool)", false) == encodeArgs(10));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(derived_overload_base_function_direct)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract B { function f() returns(uint) { return 10; } }
|
||||
contract C is B { function f(uint i) returns(uint) { return 2 * i; } }
|
||||
)";
|
||||
compileAndRun(sourceCode, "C");
|
||||
BOOST_CHECK(callContractFunction("f(uint)", 1) == encodeArgs(2));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(derived_overload_base_function_indirect)
|
||||
{
|
||||
char const* sourceCode = R"(
|
||||
contract A { function f(uint a) returns(uint) { return 2 * a; } }
|
||||
contract B { function f() returns(uint) { return 10; } }
|
||||
contract C is A, B { }
|
||||
)";
|
||||
compileAndRun(sourceCode, "C");
|
||||
BOOST_CHECK(callContractFunction("f(uint)", 1) == encodeArgs(2));
|
||||
BOOST_CHECK(callContractFunction("f()") == encodeArgs(10));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
}
|
||||
}
|
||||
} // end namespaces
|
||||
|
@ -424,23 +424,23 @@ BOOST_AUTO_TEST_CASE(cyclic_inheritance)
|
||||
BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(illegal_override_direct)
|
||||
BOOST_AUTO_TEST_CASE(legal_override_direct)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract B { function f() {} }
|
||||
contract C is B { function f(uint i) {} }
|
||||
)";
|
||||
BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
|
||||
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(illegal_override_indirect)
|
||||
BOOST_AUTO_TEST_CASE(legal_override_indirect)
|
||||
{
|
||||
char const* text = R"(
|
||||
contract A { function f(uint a) {} }
|
||||
contract B { function f() {} }
|
||||
contract C is A, B { }
|
||||
)";
|
||||
BOOST_CHECK_THROW(parseTextAndResolveNames(text), TypeError);
|
||||
BOOST_CHECK_NO_THROW(parseTextAndResolveNames(text));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(illegal_override_visibility)
|
||||
|
Loading…
Reference in New Issue
Block a user