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

Constants are not very constant #6221

Closed
Remixful opened this issue Aug 20, 2016 · 8 comments · Fixed by #7390
Closed

Constants are not very constant #6221

Remixful opened this issue Aug 20, 2016 · 8 comments · Fixed by #7390

Comments

@Remixful
Copy link

Operating system or device - Godot version:
Windows 10 - v2.1.stable.official on Steam

Issue description (what happened, and what was expected):
I'm not sure if this is intentional or not since I can't find any documentation on it. I'm able to modify the value of constants after they are declared, including the @Gloabl Scope constants. Usually in other languages constants aren't variables and may not be modified.

Steps to reproduce:
Try this in any function that will get called:

print(TYPE_BOOL)
TYPE_BOOL = 999
print(TYPE_BOOL)

Output:

1
999

You can even try declaring your own constants.

@reduz
Copy link
Member

reduz commented Aug 20, 2016

heh, I never added a check for that, you must be the first person to find
out.
this will be fun to fix, but I wonder if anyone ever is using it to his/her
advantage

On Sat, Aug 20, 2016 at 6:00 PM, Remixful notifications@github.com wrote:

Operating system or device - Godot version:
Windows 10 - v2.1.stable.official on Steam

Issue description (what happened, and what was expected):
I'm not sure if this is intentional or not since I can't find any
documentation on it. I'm able to modify the value of constants after they
are declared, including the @gloabl Scope
http://docs.godotengine.org/en/latest/classes/class_@global%20scope.html
constants. Usually in other languages constants aren't variables and may
not be modified
.

Steps to reproduce:
Try this in any function that will get called:

print(TYPE_BOOL)
TYPE_BOOL = 999
print(TYPE_BOOL)

Output:

1
999

You can even try declaring your own constants.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#6221, or mute the thread
https://github.com/notifications/unsubscribe-auth/AF-Z22kedSgFiCaqaWNqKyA57uf8o6ncks5qh2rngaJpZM4JpKb6
.

@Zylann
Copy link
Contributor

Zylann commented Aug 20, 2016

Wow, I thought constants were a compile-time feature? (can they even be?)

@reduz
Copy link
Member

reduz commented Aug 20, 2016

I think they are, expressions using them will be reduced properly at
compile time

On Aug 20, 2016 18:09, "Marc" notifications@github.com wrote:

Wow, I thought constants were a compile-time feature? (can they even be?)


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#6221 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AF-Z26QxvDeNHuQPwpoKP-WNGf7feSvdks5qh2z8gaJpZM4JpKb6
.

@Zylann
Copy link
Contributor

Zylann commented Aug 20, 2016

I mean, if they are processed at compile time, how can they even be modified? Why a check at runtime would even be required? (like writing 1 = 999 is impossible) But I'm not sure if it's technically possible to do that way in GDScript (correct me if I'm wrong)

@manokara
Copy link
Contributor

I think they are indeed processed at compile time, but reduz didn't write a check for an assignment statement involving constants, changing their value. This is probably what's happening:

print(TYPE_BOOL) # reduced to print(1)
TYPE_BOOL = 999 # changes value of constant at compile time
print(TYPE_BOOL) # reduced to print(999)

@akien-mga
Copy link
Member

Reopening as the change was reverted.

@reduz
Copy link
Member

reduz commented Aug 8, 2017

I will kick to 3.1, since at some point want to add optional typing checks. Those checks will be assignment verifications, so will have the chance to add this code there too (which is also an assignment verification)

@vnen
Copy link
Member

vnen commented Jul 21, 2018

Should be solved by #19264.

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

Successfully merging a pull request may close this issue.

7 participants