From: Mikko Rasa Date: Sat, 13 Mar 2021 14:22:43 +0000 (+0200) Subject: Better error message for the subscript operator X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=commitdiff_plain;h=ff3b43b6c15c3331d156b147b559892ee7ccdacb Better error message for the subscript operator --- 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' +*/