Godot: Values of named enums can be accessed without the name in Gdscript (generates conflicts)

Created on 19 Jun 2018  路  1Comment  路  Source: godotengine/godot

Godot version:
3.0.2 stable

OS/device including version:
MacBook Air (13-inch, Early 2014) (1,4 GHz Intel Core i5)
MacOS High Sierra 10.13.3

Issue description:
Enums can be named like this:

enum ON { THE_FLOOR, THE_TABLE, THE_ROOF }
enum STATE { ON, OFF, UNCERTAIN }

So it would make sense to use an enum value like this:

ON.THE_TABLE

But in this case, Godot gives an error:

The ON being recognized is not the ON enum, but the ON value inside STATE.

Steps to reproduce:

  1. Create a script with the following contents:
extends Node

enum ON { THE_FLOOR, THE_TABLE, THE_ROOF }
enum STATE { ON, OFF, UNCERTAIN }

func _ready():
    print(ON.THE_TABLE)
  1. Run it
  2. It should run fine, but it gives you an error

Minimal reproduction project:

Enum Bug Test Project.zip

discussion enhancement gdscript

Most helpful comment

This is probably for the same reason as #22293.

@vnen IMO we should force enums to be called as EnumName.EnumValue and drop the support for automatically registering EnumValue as a global constant. It makes enums quite hard to use and -- judging by the number of issues raised since stronger checks were added with typed GDScript -- unintuitive.

>All comments

This is probably for the same reason as #22293.

@vnen IMO we should force enums to be called as EnumName.EnumValue and drop the support for automatically registering EnumValue as a global constant. It makes enums quite hard to use and -- judging by the number of issues raised since stronger checks were added with typed GDScript -- unintuitive.

Was this page helpful?
0 / 5 - 0 ratings