eclipse-langium / langium

Next-gen language engineering / DSL framework
https://langium.org/
MIT License
753 stars 68 forks source link

False positive in grammar multiple assignments validation #1756

Open cdietrich opened 1 week ago

cdietrich commented 1 week ago

Langium version: 3.3

given the grammar

entry Model:
    expr=Expression;

Expression: Equality;

Equality infers Expression:
    Literal (({infer Equals.left=current} '==' | {infer NotEquals.left=current} '!=')  right=Literal)*;

Literal: value=INT;

the validator complains about

src/language/hello-world.langium:9:88 - Found multiple assignments to 'right' with the '=' assignment operator. Consider using '+=' instead to prevent data loss.

imho this is a false positive with the ast rewrite. maybe it is not properly detected if happing on all branches of an alternative.

cdietrich commented 1 week ago

cc @JohannesMeierSE

JohannesMeierSE commented 1 week ago

@cdietrich thanks for the bug report! I will investigate it, but I will need to find some free time for that. Is it urgent on your side?

with the ast rewrite. maybe it is not properly detected if happing on all branches of an alternative

I agree: ( ... right=Literal )* looks critical for the validation. A check for creating new objects inside ( ... )* is probably the solution.