aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLu Guanqun <guanqun.lu@gmail.com>2016-01-12 00:00:14 +0800
committerLu Guanqun <guanqun.lu@gmail.com>2016-01-23 01:14:01 +0800
commitd36537e73720f181fae3e3b82a3d751d27782ca1 (patch)
tree5e9ce3f9e00bf3987ec79057cf8c9a21b9e9f07b
parentc8b05339335d8e9166ef6863f7697bcc59f09260 (diff)
downloaddexon-solidity-d36537e73720f181fae3e3b82a3d751d27782ca1.tar
dexon-solidity-d36537e73720f181fae3e3b82a3d751d27782ca1.tar.gz
dexon-solidity-d36537e73720f181fae3e3b82a3d751d27782ca1.tar.bz2
dexon-solidity-d36537e73720f181fae3e3b82a3d751d27782ca1.tar.lz
dexon-solidity-d36537e73720f181fae3e3b82a3d751d27782ca1.tar.xz
dexon-solidity-d36537e73720f181fae3e3b82a3d751d27782ca1.tar.zst
dexon-solidity-d36537e73720f181fae3e3b82a3d751d27782ca1.zip
cond-expr: use the mobile type instead of the original type
-rw-r--r--libsolidity/analysis/TypeChecker.cpp15
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp35
2 files changed, 37 insertions, 13 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 016fe66a..0d74ddba 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -751,19 +751,10 @@ bool TypeChecker::visit(Conditional const& _conditional)
_conditional.trueExpression().accept(*this);
_conditional.falseExpression().accept(*this);
- TypePointer const& trueType = type(_conditional.trueExpression());
- TypePointer const& falseType = type(_conditional.falseExpression());
+ TypePointer trueType = type(_conditional.trueExpression())->mobileType();
+ TypePointer falseType = type(_conditional.falseExpression())->mobileType();
- TypePointer commonType;
- if (*trueType == *falseType)
- commonType = trueType;
- else
- {
- commonType = Type::commonType(trueType, falseType);
- if (!commonType)
- // we fake it as an equal operator, but any other comparison operator can work.
- commonType = trueType->binaryOperatorResult(Token::Equal, falseType);
- }
+ TypePointer commonType = Type::commonType(trueType, falseType);
if (!commonType)
{
typeError(
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 0f0eb417..0907525b 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -141,7 +141,40 @@ BOOST_AUTO_TEST_CASE(conditional_expression_with_return_values)
BOOST_CHECK(callContractFunction("f(bool,uint256)", false, u256(20)) == encodeArgs(u256(0), u256(20)));
}
-BOOST_AUTO_TEST_CASE(conditional_expression_storage_memory)
+BOOST_AUTO_TEST_CASE(conditional_expression_storage_memory_1)
+{
+ char const* sourceCode = R"(
+ contract test {
+ bytes2[2] data1;
+ function f(bool cond) returns (uint) {
+ bytes2[2] memory x;
+ x[0] = "aa";
+ bytes2[2] memory y;
+ y[0] = "bb";
+
+ data1 = cond ? x : y;
+
+ uint ret = 0;
+ if (data1[0] == "aa")
+ {
+ ret = 1;
+ }
+
+ if (data1[0] == "bb")
+ {
+ ret = 2;
+ }
+
+ return ret;
+ }
+ }
+ )";
+ compileAndRun(sourceCode);
+ BOOST_CHECK(callContractFunction("f(bool)", true) == encodeArgs(u256(1)));
+ BOOST_CHECK(callContractFunction("f(bool)", false) == encodeArgs(u256(2)));
+}
+
+BOOST_AUTO_TEST_CASE(conditional_expression_storage_memory_2)
{
char const* sourceCode = R"(
contract test {