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: Allow using local constants as types #80964

Merged

Conversation

dalexeev
Copy link
Member

@dalexeev dalexeev commented Aug 24, 2023

In master you can only use member constants as types. Now it's possible:

enum MyEnum {A, B, C}

func _ready() -> void:
    const X = preload("1.gd")
    const Y = MyEnum
    var x: X
    var y: Y

I recommend hide whitespace changes for the review, since I increased the indentation level in a large block.

@dalexeev dalexeev added this to the 4.2 milestone Aug 24, 2023
@dalexeev dalexeev requested a review from a team as a code owner August 24, 2023 16:10
@dalexeev dalexeev added the bug label Aug 24, 2023
@dalexeev dalexeev force-pushed the gds-allow-use-local-consts-as-types branch from 23e72b6 to 8c7d161 Compare August 24, 2023 17:07
@adamscott
Copy link
Member

@dalexeev Is it cherry-pickable?

@dalexeev
Copy link
Member Author

@adamscott I think yes, with a small change in the parser from #79880 (add the IdentifierNode::suite property). However, I think it's more of an inconvenience than a significant limitation (it's easy to workaround by using member constant instead of local constant). In addition, we regularly publish 4.2 dev snapshots. But if production team thinks it's important enough for a cherry-pick, then I don't mind.

Copy link
Member

@adamscott adamscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems nice! Let's test it out.

@dalexeev dalexeev force-pushed the gds-allow-use-local-consts-as-types branch from 8c7d161 to 68a567b Compare August 25, 2023 14:04
@YuriSizov YuriSizov merged commit b6c4efe into godotengine:master Aug 25, 2023
@YuriSizov
Copy link
Contributor

Thanks!

@dalexeev dalexeev deleted the gds-allow-use-local-consts-as-types branch August 25, 2023 19:53
@akien-mga akien-mga changed the title GDScript: Allow use local constants as types GDScript: Allow using local constants as types Sep 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't use local constant as type
3 participants