aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorLu Guanqun <guanqun.lu@gmail.com>2016-01-11 15:08:28 +0800
committerLu Guanqun <guanqun.lu@gmail.com>2016-01-23 01:14:00 +0800
commitbf7daf0814ac17fece679a9d1aa187a8bdcf901b (patch)
tree54a0d2556c61d5efb27f3bc12394429da70f7328 /libsolidity
parentb003290638e16e595c25e433f2f65648ea6644da (diff)
downloaddexon-solidity-bf7daf0814ac17fece679a9d1aa187a8bdcf901b.tar
dexon-solidity-bf7daf0814ac17fece679a9d1aa187a8bdcf901b.tar.gz
dexon-solidity-bf7daf0814ac17fece679a9d1aa187a8bdcf901b.tar.bz2
dexon-solidity-bf7daf0814ac17fece679a9d1aa187a8bdcf901b.tar.lz
dexon-solidity-bf7daf0814ac17fece679a9d1aa187a8bdcf901b.tar.xz
dexon-solidity-bf7daf0814ac17fece679a9d1aa187a8bdcf901b.tar.zst
dexon-solidity-bf7daf0814ac17fece679a9d1aa187a8bdcf901b.zip
[cond-expr] don't allow conditional as left value for the first stage
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/analysis/TypeChecker.cpp68
1 files changed, 25 insertions, 43 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index f3840675..8f1b2b9d 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -748,55 +748,37 @@ bool TypeChecker::visit(Conditional const& _conditional)
{
expectType(_conditional.condition(), BoolType());
- if (_conditional.annotation().lValueRequested)
- {
- requireLValue(_conditional.trueExpression());
- requireLValue(_conditional.falseExpression());
-
- TypePointer const& trueType = type(_conditional.trueExpression());
- TypePointer const& falseType = type(_conditional.falseExpression());
+ _conditional.trueExpression().accept(*this);
+ _conditional.falseExpression().accept(*this);
- // as a left value, we require exact match to prevent subtle conversion issues.
- if (*trueType != *falseType)
- typeError(
- _conditional.location(),
- "True expression's type " +
- trueType->toString() +
- " doesn't match false expression's type " +
- falseType->toString() +
- "."
- );
+ TypePointer const& trueType = type(_conditional.trueExpression());
+ TypePointer const& falseType = type(_conditional.falseExpression());
- _conditional.annotation().type = trueType;
- _conditional.annotation().isLValue = true;
- }
- else
+ // we fake it as an equal operator, but any other comparison operator can work.
+ TypePointer commonType = trueType->binaryOperatorResult(Token::Equal, falseType);
+ if (!commonType)
{
- _conditional.trueExpression().accept(*this);
- _conditional.falseExpression().accept(*this);
+ typeError(
+ _conditional.location(),
+ "True expression's type " +
+ trueType->toString() +
+ " doesn't match false expression's type " +
+ falseType->toString() +
+ "."
+ );
+ // even we can't find a common type, we have to set a type here,
+ // otherwise the upper statement will not be able to check the type.
+ commonType = trueType;
+ }
- TypePointer const& trueType = type(_conditional.trueExpression());
- TypePointer const& falseType = type(_conditional.falseExpression());
+ _conditional.annotation().type = commonType;
- // we fake it as an equal operator, but any other comparison operator can work.
- TypePointer commonType = trueType->binaryOperatorResult(Token::Equal, falseType);
- if (!commonType)
- {
- typeError(
- _conditional.location(),
- "True expression's type " +
- trueType->toString() +
- " doesn't match false expression's type " +
- falseType->toString() +
- "."
- );
- // even we can't find a common type, we have to set a type here,
- // otherwise the upper statement will not be able to check the type.
- commonType = trueType;
- }
+ if (_conditional.annotation().lValueRequested)
+ typeError(
+ _conditional.location(),
+ "Conditional expression as left value is not supported yet."
+ );
- _conditional.annotation().type = commonType;
- }
return false;
}