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

GDScript enums override constants. #13175

Closed
ghost opened this issue Nov 22, 2017 · 11 comments
Closed

GDScript enums override constants. #13175

ghost opened this issue Nov 22, 2017 · 11 comments
Assignees
Milestone

Comments

@ghost
Copy link

ghost commented Nov 22, 2017

I'm using Windows version of 2.1.

The problem I ran into is that enums using the same names as constants will replace their value.

Such as:

const NUMBER = 100

enum INT { NUMBER = 2 }

func _ready():
	print(NUMBER) # Shows 2
@akien-mga akien-mga added this to the 3.0 milestone Nov 22, 2017
@akien-mga
Copy link
Member

I haven't tested but it's likely the same in master too, so should be fixed for both. cc @bojidar-bg

@neikeq
Copy link
Contributor

neikeq commented Nov 22, 2017

AFAIK, this is expected. It's similar to C++ enums. It should error because NUMBER is already declared though.

@akien-mga
Copy link
Member

Yeah, I tagged "bug" because it's a bug that it allows this shadowing instead of erroring out.

@vnen
Copy link
Member

vnen commented Nov 22, 2017

Related to #6221.

@Sslaxx
Copy link

Sslaxx commented Nov 22, 2017

Per #6221 (comment) @reduz intends (intended?) to leave this issue for 3.1.

@bojidar-bg
Copy link
Contributor

bojidar-bg commented Nov 22, 2017

I think we should add some way to mark enums as "to-be-kept-as-dictionary-only". Some examples to explain it:

enum {INT = 1, STRING}
# equivalent to:
const INT = 1; const STRING = 2

# ---

enum Type {INT = 1, STRING}
# equivalent to:
const INT = 1; const STRING = 2
const Type = {INT = 1, STRING = 2}

# ---

!enum Type {INT = 1, STRING} # some cool proposal here
# equivalent to:
const Type = {INT = 1, STRING = 2}

Now, the question is how to mark those enums, feel free to propose the syntax 😃 .

@akien-mga
Copy link
Member

No, we don't need to add support for half shadowing. Just trigger a syntax error when an enum shadows a constant.

@vnen
Copy link
Member

vnen commented Nov 22, 2017

@bojidar-bg I don't get the point, if you need just a dictionary you can simply make one. There's no much gain in avoiding to set the values manually.

@reduz
Copy link
Member

reduz commented Dec 26, 2017

@bojidar-bg guess popular demand here just wants an error to be triggered :)

@akien-mga
Copy link
Member

We have now entered release freeze for Godot 3.0 and want to focus only on release critical issues for that milestone. Therefore, we're moving this issue to the 3.1 milestone, though a fix may be made available for a 3.0.x maintenance release after it has been tested in the master branch during 3.1 development. If you consider that this issue is critical enough to warrant blocking the 3.0 release until fixed, please comment so that we can assess it more in-depth.

@akien-mga akien-mga modified the milestones: 3.0, 3.1 Jan 5, 2018
@reduz
Copy link
Member

reduz commented Sep 6, 2018

@vnen , @bojidar-bg what to do with this?

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

No branches or pull requests

6 participants