]> git.tdb.fi Git - libs/gl.git/commitdiff
Better error message for the subscript operator
authorMikko Rasa <tdb@tdb.fi>
Sat, 13 Mar 2021 14:22:43 +0000 (16:22 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sat, 13 Mar 2021 14:22:43 +0000 (16:22 +0200)
source/glsl/validate.cpp
tests/glsl/invalid_subscript.glsl [new file with mode: 0644]

index 13cb5ccb23ad15e4d6e56798552ffcd35fefd381..4b38c5b755e935f0e3f477c0ecd092202e411c7f 100644 (file)
@@ -338,8 +338,14 @@ void ExpressionValidator::visit(UnaryExpression &unary)
 void ExpressionValidator::visit(BinaryExpression &binary)
 {
        if(!binary.type && binary.left->type && binary.right->type)
-               error(binary, format("No matching operator '%s' found for '%s' and '%s'",
-                       binary.oper->token, binary.left->type->name, binary.right->type->name));
+       {
+               if(binary.oper->token[0]=='[')
+                       error(binary, format("Can't index element of '%s' with '%s'",
+                               binary.left->type->name, binary.right->type->name));
+               else
+                       error(binary, format("No matching operator '%s' found for '%s' and '%s'",
+                               binary.oper->token, binary.left->type->name, binary.right->type->name));
+       }
        TraversingVisitor::visit(binary);
 }
 
diff --git a/tests/glsl/invalid_subscript.glsl b/tests/glsl/invalid_subscript.glsl
new file mode 100644 (file)
index 0000000..6826fef
--- /dev/null
@@ -0,0 +1,13 @@
+#pragma MSP stage(vertex)
+layout(location=0) in vec4 position;
+layout(location=1) in float scale;
+int main()
+{
+       gl_Position = position[scale];
+       gl_Position = scale[position];
+}
+
+/* Expected error:
+<test>:6: Can't index element of 'vec4' with 'float'
+<test>:7: Can't index element of 'float' with 'vec4'
+*/