Godot version: 3.1 561a777
Issue description: Since a recent commit, writing
enum A {test = 0}
enum B {test = 1}
results in the parsing error "Error (at the second test): A constant named 'test' already exists in this class."
This is intended. Enums are mostly a syntax sugar for constants, so in this case you are defining the constant test twice.
If you need this you can simply make a constant dictionary:
const A = { test = 0 }
const B = { test = 1 }
This way it doesn't generate to constants in the class scope.
If you think that worked previously, what it actually did was override the previously defined constant. So test would be equal to 1 in this example because the last defined value override the previous one.
In the stable 3.0.6 version,
enum A {test = 3}
enum B {test = 5}
func _ready():
print(A.test)
print(B.test)
Prints 3 then 5, so the constants had to be stored/parsed separately, no? Easier fix in my case is probably to just use different names altogether, but this would have been a cool behavior as opposed to C. Thanks!
Prints 3 then 5, so the constants had to be stored/parsed separately, no?
Yes if you do print(A.test) and print(B.test) (because you're accessing different dictionaries), but not if you do simply print(test), since then there's no way to disambiguate.
This is also related to #13175.
Most helpful comment
This is intended. Enums are mostly a syntax sugar for constants, so in this case you are defining the constant
testtwice.If you need this you can simply make a constant dictionary:
This way it doesn't generate to constants in the class scope.
If you think that worked previously, what it actually did was override the previously defined constant. So
testwould be equal to1in this example because the last defined value override the previous one.