diff options
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 2 | ||||
-rw-r--r-- | test/libsolidity/SolidityEndToEndTest.cpp | 15 |
2 files changed, 16 insertions, 1 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index b4896b49..a8125573 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -759,7 +759,7 @@ bool TypeChecker::visit(Conditional const& _conditional) commonType = trueType; else // 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) { typeError( diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp index 8bf309df..d7827946 100644 --- a/test/libsolidity/SolidityEndToEndTest.cpp +++ b/test/libsolidity/SolidityEndToEndTest.cpp @@ -174,6 +174,21 @@ BOOST_AUTO_TEST_CASE(conditional_expression_storage_memory) 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) { char const* sourceCode = "contract test {\n" |