-
Notifications
You must be signed in to change notification settings - Fork 8
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
Cannot have a name shared by a static and local variable in function #4449
Comments
This is not a bug - statics and locals cannot have the same name |
Even though only one can exist at any time? In my example, the static is only created if a macro is set to a certain value, otherwise a local variable is created instead of the static, so there's either a static variable or a local, not both together. I would assume that if I'm not creating the static, then the local should be able to use the name? |
statics are hoisted from the declaration so it would be created no matter what - the hoisting happens before the optimizer would remove the All statics are declared at the top of the function and do not participate in code flow. |
Hahaha, ok, I'll let Alynne know because Input is using that behaviour. |
* develop: (62 commits) docs(feature): GPU texture compression YoYoGames/GameMaker-Bugs#5495 docs(feature): Review PR #117 docs(feature): GPU texture compression YoYoGames/GameMaker-Bugs#5495 docs(general): Fix gamepad axis and button constant links YoYoGames/GameMaker-Bugs#5134 docs(general): Fix code in example of asset_get_index docs(general): debug_event note on memory usage YoYoGames/GameMaker-Bugs#5649 docs(feature): GPU Hardware Texture Compression YoYoGames/GameMaker-Bugs#5495 docs(general): Made it clearer that bbox values are +1 from sprite bbox, linked to on bbox_ var pages YoYoGames/GameMaker-Bugs#5101 docs(general): Manual overview page for "Surfaces" doesn't mention freeing them after use YoYoGames/GameMaker-Bugs#5622 docs(feature): Manual page for "wallpaper_set_config()" contains spelling error in code example YoYoGames/GameMaker-Bugs#5621 docs(general): Document that static variables cannot be defined conditionally YoYoGames/GameMaker-Bugs#4449 docs(general): Description error for ds_queue_tail() YoYoGames/GameMaker-Bugs#5500 docs(general): Draw Sprite sub-image mistake fix YoYoGames/GameMaker-Bugs#5565 docs(general): mentioned Ctrl + Comma and Ctrl + Period for workspace overview navigation on macOS YoYoGames/GameMaker-Bugs#5595 docs(general): updated shortcuts CSS style, workspace navigation dirs set to 4 YoYoGames/GameMaker-Bugs#5595 final fix fixes for pushing to s3 fixes for pushing to s3 fixes for pushing to s3 adding some logging ...
…tionally YoYoGames/GameMaker-Bugs#4449 (cherry picked from commit 87b8eb5)
Description
There are cases where you may want to either create a static or create a local variable in a function. If you want to do this in the Beta, they cannot share a name (despite only one ever being initialised, not both). This is changed functionality from the stable build.
Steps To Reproduce
Create a script with a conditional that branches into either creating a static or a local variable. Make sure they have the same name. Try to do anything with that variable and the game will crash, i.e.:
#macro STATIC_FUNCTION true
function Script1(){
if (STATIC_FUNCTION) {
static _result = {
x: 0,
y: 0
}
}
else {
var _result = {
x: 0,
y: 0
}
}
return _result;
}
cc822a2d-30ea-4bac-963c-990e4e3adaf0
The text was updated successfully, but these errors were encountered: