diff options
-rw-r--r-- | src/sksl/SkSLIRGenerator.cpp | 12 | ||||
-rw-r--r-- | tests/SkSLErrorTest.cpp | 6 | ||||
-rw-r--r-- | tests/SkSLGLSLTest.cpp | 24 |
3 files changed, 36 insertions, 6 deletions
diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp index 0c9ee20328..ec64fa9348 100644 --- a/src/sksl/SkSLIRGenerator.cpp +++ b/src/sksl/SkSLIRGenerator.cpp @@ -1033,13 +1033,13 @@ std::unique_ptr<Expression> IRGenerator::convertConstructor( ASSERT(kind == Type::kVector_Kind || kind == Type::kMatrix_Kind); int actual = 0; for (size_t i = 0; i < args.size(); i++) { - if (args[i]->fType.kind() == Type::kVector_Kind || + if (args[i]->fType.kind() == Type::kVector_Kind || args[i]->fType.kind() == Type::kMatrix_Kind) { - int columns = args[i]->fType.columns(); - int rows = args[i]->fType.rows(); - args[i] = this->coerce(std::move(args[i]), - type.componentType().toCompound(fContext, columns, rows)); - if (!args[i]) { + if (type.componentType().isNumber() != + args[i]->fType.componentType().isNumber()) { + fErrors.error(position, "'" + args[i]->fType.description() + "' is not a valid " + "parameter to '" + type.description() + + "' constructor"); return nullptr; } actual += args[i]->fType.rows() * args[i]->fType.columns(); diff --git a/tests/SkSLErrorTest.cpp b/tests/SkSLErrorTest.cpp index 3afb64fe61..9e89b71473 100644 --- a/tests/SkSLErrorTest.cpp +++ b/tests/SkSLErrorTest.cpp @@ -94,6 +94,12 @@ DEF_TEST(SkSLConstructorTypeMismatch, r) { "void main() { vec2 x = vec2(1.0, false); }", "error: 1: expected 'float', but found 'bool'\n1 error\n"); test_failure(r, + "void main() { vec2 x = vec2(bvec2(false)); }", + "error: 1: 'bvec2' is not a valid parameter to 'vec2' constructor\n1 error\n"); + test_failure(r, + "void main() { bvec2 x = bvec2(vec2(1)); }", + "error: 1: 'vec2' is not a valid parameter to 'bvec2' constructor\n1 error\n"); + test_failure(r, "void main() { bool x = bool(1.0); }", "error: 1: cannot construct 'bool'\n1 error\n"); test_failure(r, diff --git a/tests/SkSLGLSLTest.cpp b/tests/SkSLGLSLTest.cpp index ad1fe0d901..610ff2b5ab 100644 --- a/tests/SkSLGLSLTest.cpp +++ b/tests/SkSLGLSLTest.cpp @@ -368,6 +368,30 @@ DEF_TEST(SkSLHex, r) { "}\n"); } +DEF_TEST(SkSLVectorConstructors, r) { + test(r, + "vec2 v1 = vec2(1);" + "vec2 v2 = vec2(1, 2);" + "vec2 v3 = vec2(vec2(1));" + "vec2 v4 = vec2(vec3(1));" + "vec3 v5 = vec3(vec2(1), 1.0);" + "vec3 v6 = vec3(vec4(1, 2, 3, 4));" + "ivec2 v7 = ivec2(1);" + "ivec2 v8 = ivec2(vec2(1, 2));" + "vec2 v9 = vec2(ivec2(1, 2));", + default_caps(), + "#version 400\n" + "vec2 v1 = vec2(1.0);\n" + "vec2 v2 = vec2(1.0, 2.0);\n" + "vec2 v3 = vec2(1.0);\n" + "vec2 v4 = vec2(vec3(1.0));\n" + "vec3 v5 = vec3(vec2(1.0), 1.0);\n" + "vec3 v6 = vec3(vec4(1.0, 2.0, 3.0, 4.0));\n" + "ivec2 v7 = ivec2(1);\n" + "ivec2 v8 = ivec2(vec2(1.0, 2.0));\n" + "vec2 v9 = vec2(ivec2(1, 2));\n"); +} + DEF_TEST(SkSLArrayConstructors, r) { test(r, "float test1[] = float[](1, 2, 3, 4);" |