]> git.tdb.fi Git - libs/gl.git/commitdiff
Improve reporting of function name conflicts
authorMikko Rasa <tdb@tdb.fi>
Mon, 8 Mar 2021 00:49:40 +0000 (02:49 +0200)
committerMikko Rasa <tdb@tdb.fi>
Mon, 8 Mar 2021 13:28:54 +0000 (15:28 +0200)
Prototype declarations were not being recorded, and definitions were
causing multiple definition errors to be reported in double.

source/glsl/validate.cpp
tests/glsl/identifier_conflict.glsl

index 2f02400ee675a5bc159362d9e85fec755a92c9d7..fcccb526e0dc3bc62831e3c949f8bb767b929591 100644 (file)
@@ -156,11 +156,16 @@ void DeclarationValidator::visit(InterfaceBlock &iface)
 void DeclarationValidator::visit(FunctionDeclaration &func)
 {
        if(Statement *previous = find_definition(func.name))
 void DeclarationValidator::visit(FunctionDeclaration &func)
 {
        if(Statement *previous = find_definition(func.name))
-               if(!dynamic_cast<FunctionDeclaration *>(previous))
+       {
+               FunctionDeclaration *prev_func = dynamic_cast<FunctionDeclaration *>(previous);
+               if(prev_func && prev_func->definition==&func)
+                       declarations[current_block][func.name] = &func;
+               else
                        multiple_definition(format("'%s'", func.name), func, *previous);
                        multiple_definition(format("'%s'", func.name), func, *previous);
+       }
+       else
+               record_definition(func.name, func);
 
 
-       if(func.definition==&func)
-               check_definition(func.name, func);
        TraversingVisitor::visit(func);
 }
 
        TraversingVisitor::visit(func);
 }
 
index 3e10089b0f61899f0fd8e430174b8a092b8c15cf..b0cd34a6922985a1b7e6477fedb2cc44e36f7421 100644 (file)
@@ -4,6 +4,7 @@ out VertexOut
 {
        vec2 texcoord;
 } vs_out;
 {
        vec2 texcoord;
 } vs_out;
+vec3 normal();
 vec3 normal;
 out VertexOut2
 {
 vec3 normal;
 out VertexOut2
 {
@@ -22,10 +23,12 @@ vec2 texcoord()
 }
 
 /* Expected error:
 }
 
 /* Expected error:
-<test>:11: Multiple definition of 'normal'
+<test>:8: Multiple definition of 'normal'
 <test>:7: Previous definition is here
 <test>:7: Previous definition is here
-<test>:13: Multiple definition of 'texcoord'
-<test>:10: Previous definition is here
-<test>:19: Multiple definition of 'texcoord'
-<test>:10: Previous definition is here
+<test>:12: Multiple definition of 'normal'
+<test>:7: Previous definition is here
+<test>:14: Multiple definition of 'texcoord'
+<test>:11: Previous definition is here
+<test>:20: Multiple definition of 'texcoord'
+<test>:11: Previous definition is here
 */
 */