mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[cond-expr] add a test for different types
This commit is contained in:
parent
1cd3288311
commit
ac3019298a
@ -759,7 +759,7 @@ bool TypeChecker::visit(Conditional const& _conditional)
|
|||||||
commonType = trueType;
|
commonType = trueType;
|
||||||
else
|
else
|
||||||
// we fake it as an equal operator, but any other comparison operator can work.
|
// we fake it as an equal operator, but any other comparison operator can work.
|
||||||
TypePointer commonType = trueType->binaryOperatorResult(Token::Equal, falseType);
|
commonType = trueType->binaryOperatorResult(Token::Equal, falseType);
|
||||||
if (!commonType)
|
if (!commonType)
|
||||||
{
|
{
|
||||||
typeError(
|
typeError(
|
||||||
|
@ -174,6 +174,21 @@ BOOST_AUTO_TEST_CASE(conditional_expression_storage_memory)
|
|||||||
BOOST_CHECK(callContractFunction("f(bool)", false) == encodeArgs(u256(2)));
|
BOOST_CHECK(callContractFunction("f(bool)", false) == encodeArgs(u256(2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(conditional_expression_different_types)
|
||||||
|
{
|
||||||
|
char const* sourceCode = R"(
|
||||||
|
contract test {
|
||||||
|
function f(bool cond) returns (uint) {
|
||||||
|
uint8 x = 0xcd;
|
||||||
|
uint16 y = 0xabab;
|
||||||
|
return cond ? x : y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
compileAndRun(sourceCode);
|
||||||
|
BOOST_CHECK(callContractFunction("f(bool)", true) == encodeArgs(u256(0xcd)));
|
||||||
|
BOOST_CHECK(callContractFunction("f(bool)", false) == encodeArgs(u256(0xabab)));
|
||||||
|
}
|
||||||
BOOST_AUTO_TEST_CASE(recursive_calls)
|
BOOST_AUTO_TEST_CASE(recursive_calls)
|
||||||
{
|
{
|
||||||
char const* sourceCode = "contract test {\n"
|
char const* sourceCode = "contract test {\n"
|
||||||
|
Loading…
Reference in New Issue
Block a user