godot
godot copied to clipboard
[3.x] Check duplicate keys in dictionary literals: enums and const variables
Implement checking of identifiers (const variables and unnamed enums) and named enums when parsing dictionary literals whether the keys are not duplicated.
In case of duplicate key is encountered, highlight the line with it and print error message:
Duplicate key "foo" found in Dictionary literal
This commit is a logical continuation of the commit https://github.com/godotengine/godot/commit/dab73c701a9785be443977a613e57600d1e136c8 which implemented such checks only for literal keys and fixed #7034.
Apart from that, this commit also fixes the issue that the line below the duplicated key was highlighted with the error in case it was the last one in the dictionary literal and there was no hanging comma. That is, in the following example:
var foo = {
1: "1",
2: "2",
1: "3"
}
the last line (with the }
) was highlighted as the error instead of the line abobe with 1: "3"
. Now it's fixed.
Also, the format of the error message has been changed so that now the error message also contains the value of the key which is duplicated. Instead of:
Duplicate key found in Dictionary literal
now it prints
Duplicate key "<value>" found in Dictionary literal
Fixes #50971
Some of the tests for this PR are in this Gist
Please, note that in this PR I've also changed the error message so that now it also prints the value of the hey which is duplicated. That is, instead of:
Duplicate key found in Dictionary literal
now it will prints
Duplicate key "<value>" found in Dictionary literal
This looks okay to me as far as I can see, but I'm not familiar with the gdscript parser at all.
@vnen would you be able to take a quick look to confirm this is okay (am guessing you are familiar)?
Needs a rebase, just in case
Rebase done
Thanks!
No response from gdscript team, but this looks fairly straightforward and I'm satisfied if there are problems we can revert and fix. :+1: