[cond-expr] fix the crash in ExpressionStatement

This commit is contained in:
Lu Guanqun 2015-12-23 15:48:10 +00:00
parent 08493589c1
commit 36a758e224

View File

@ -760,6 +760,7 @@ void TypeChecker::endVisit(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 " +
@ -768,6 +769,10 @@ void TypeChecker::endVisit(Conditional const& _conditional)
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;
if (_conditional.annotation().lValueRequested)