glsl4idea
glsl4idea copied to clipboard
Incorrect typechecking when preprocessors are used
Describe the bug When a variable is defined multiple times in a file the first definition seems to be used for type checking. This can be a problem if multiple shader stages are written in the same file.
To Reproduce
#if VERTEX_SHADER
#version 330
in vec3 color;
out vec3 fragColor;
void main() {
fragColor = color;
}
#else
#version 330
in vec3 fragColor;
out vec4 color;
void main() {
color = vec4(fragColor, 1); // error: Incompatible types as operands of '=': 'vec3' and 'vec4'
}
#endif
Expected behavior Ideally there would be no complaints from Intellij for the above code.
If multiple shader stages in the same file is not supported, then I could of course put in them in separate files instead, or use another name for the variable. It would be a reasonable workaround for now.
Versions
- IDE: IntelliJ IDEA Community Edition 2023.1.3
- Plugin: 1.24
Extra context
My real code uses #pragma shader vert
instead of #if
, but I found that both versions had the same problem.
If multiple shader stages in the same file is not supported
The plugin does not care about shader stages, the problem is that the plugin always processes both branches of the #if. This is not trivial to fix (at least for me) because of the fairly complex interactions between the preprocessor and the lexer. Basically the code is parsed as if the #if-else was not there.
PR's welcome.