From ff3b43b6c15c3331d156b147b559892ee7ccdacb Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 13 Mar 2021 16:22:43 +0200 Subject: [PATCH] Better error message for the subscript operator --- source/glsl/validate.cpp | 10 ++++++++-- tests/glsl/invalid_subscript.glsl | 13 +++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 tests/glsl/invalid_subscript.glsl diff --git a/source/glsl/validate.cpp b/source/glsl/validate.cpp index 13cb5ccb..4b38c5b7 100644 --- a/source/glsl/validate.cpp +++ b/source/glsl/validate.cpp @@ -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 index 00000000..6826feff --- /dev/null +++ b/tests/glsl/invalid_subscript.glsl @@ -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: +:6: Can't index element of 'vec4' with 'float' +:7: Can't index element of 'float' with 'vec4' +*/ -- 2.43.0