mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
[cond-expr] fixup according to code review
This commit is contained in:
@@ -765,7 +765,7 @@ bool TypeChecker::visit(Conditional const& _conditional)
|
||||
" doesn't match false expression's type " +
|
||||
falseType->toString() +
|
||||
"."
|
||||
);
|
||||
);
|
||||
|
||||
_conditional.annotation().type = trueType;
|
||||
_conditional.annotation().isLValue = true;
|
||||
@@ -781,6 +781,7 @@ bool TypeChecker::visit(Conditional const& _conditional)
|
||||
// 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 " +
|
||||
@@ -788,7 +789,11 @@ bool TypeChecker::visit(Conditional const& _conditional)
|
||||
" 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;
|
||||
}
|
||||
|
||||
_conditional.annotation().type = commonType;
|
||||
}
|
||||
|
||||
@@ -182,10 +182,12 @@ bool ExpressionCompiler::visit(Conditional const& _condition)
|
||||
_condition.condition().accept(*this);
|
||||
eth::AssemblyItem trueTag = m_context.appendConditionalJump();
|
||||
_condition.falseExpression().accept(*this);
|
||||
utils().convertType(*_condition.falseExpression().annotation().type, *_condition.annotation().type);
|
||||
eth::AssemblyItem endTag = m_context.appendJumpToNew();
|
||||
m_context << trueTag;
|
||||
m_context.adjustStackOffset(-1);
|
||||
m_context.adjustStackOffset(-_condition.annotation().type->sizeOnStack());
|
||||
_condition.trueExpression().accept(*this);
|
||||
utils().convertType(*_condition.trueExpression().annotation().type, *_condition.annotation().type);
|
||||
m_context << endTag;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -947,7 +947,7 @@ ASTPointer<Expression> Parser::parseExpression(
|
||||
expectToken(Token::Colon);
|
||||
ASTPointer<Expression> falseExpression = parseExpression();
|
||||
ASTNodeFactory nodeFactory(*this, expression);
|
||||
nodeFactory.setEndPositionFromNode(falseExpression); // TODO:
|
||||
nodeFactory.setEndPositionFromNode(falseExpression);
|
||||
return nodeFactory.createNode<Conditional>(expression, trueExpression, falseExpression);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user