diff options
-rw-r--r-- | src/sksl/SkSLIRGenerator.cpp | 9 | ||||
-rw-r--r-- | tests/SkSLErrorTest.cpp | 3 |
2 files changed, 10 insertions, 2 deletions
diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp index 0f035af32e..992db6e239 100644 --- a/src/sksl/SkSLIRGenerator.cpp +++ b/src/sksl/SkSLIRGenerator.cpp @@ -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) { diff --git a/tests/SkSLErrorTest.cpp b/tests/SkSLErrorTest.cpp index 4dd92f3e77..a33e6f16e6 100644 --- a/tests/SkSLErrorTest.cpp +++ b/tests/SkSLErrorTest.cpp @@ -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) { |