Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect typechecking when preprocessors are used #182

Open
Martomate opened this issue Jul 2, 2023 · 1 comment
Open

Incorrect typechecking when preprocessors are used #182

Martomate opened this issue Jul 2, 2023 · 1 comment
Labels

Comments

@Martomate
Copy link

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.

@Martomate Martomate added the bug label Jul 2, 2023
@Darkyenus
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants