fix skslc crash when ternary parameter types don't match

BUG=skia:5968

Change-Id: I541c7925ac83e830bd53015961312810042046c5
Reviewed-on: https://skia-review.googlesource.com/6545
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
This commit is contained in:
Ethan Nicholas 2017-01-03 16:44:39 -05:00 committed by Skia Commit-Bot
parent 5dfb4e45ef
commit 2be687af58
2 changed files with 10 additions and 2 deletions

View File

@ -984,15 +984,20 @@ std::unique_ptr<Expression> IRGenerator::convertTernaryExpression(
const Type* falseType;
const Type* resultType;
if (!determine_binary_type(fContext, Token::EQEQ, ifTrue->fType, ifFalse->fType, &trueType,
&falseType, &resultType, true)) {
&falseType, &resultType, true) || trueType != falseType) {
fErrors.error(expression.fPosition, "ternary operator result mismatch: '" +
ifTrue->fType.fName + "', '" +
ifFalse->fType.fName + "'");
return nullptr;
}
ASSERT(trueType == falseType);
ifTrue = this->coerce(std::move(ifTrue), *trueType);
if (!ifTrue) {
return nullptr;
}
ifFalse = this->coerce(std::move(ifFalse), *falseType);
if (!ifFalse) {
return nullptr;
}
if (test->fKind == Expression::kBoolLiteral_Kind) {
// static boolean test, just return one of the branches
if (((BoolLiteral&) *test).fValue) {

View File

@ -307,6 +307,9 @@ DEF_TEST(SkSLTernaryMismatch, r) {
test_failure(r,
"void main() { int x = 5 > 2 ? true : 1.0; }",
"error: 1: ternary operator result mismatch: 'bool', 'float'\n1 error\n");
test_failure(r,
"void main() { int x = 5 > 2 ? vec3(1) : 1.0; }",
"error: 1: ternary operator result mismatch: 'vec3', 'float'\n1 error\n");
}
DEF_TEST(SkSLInterfaceBlockStorageModifiers, r) {