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: Make array literal typed if for loop variable type is specified #82030

Merged

Conversation

dalexeev
Copy link
Member

Treat an array literal as typed if the for loop variable type is specified:

for x: int in [1, 2, 3]:
#             ^^^^^^^^^
#             Array[int]

This is an implicit behavior that I don't really like, but I think it's consistent with other cases.

@dalexeev dalexeev added this to the 4.2 milestone Sep 21, 2023
@dalexeev dalexeev requested a review from a team as a code owner September 21, 2023 08:23
@dalexeev dalexeev force-pushed the gds-make-for-loop-array-literal-typed branch from 2bbca6c to 3c35e7f Compare September 21, 2023 08:27
@vnen
Copy link
Member

vnen commented Sep 28, 2023

This is an implicit behavior that I don't really like, but I think it's consistent with other cases.

Note that this array cannot be accessed or changed by the user, so in practice it makes no difference if it's implicitly typed or not. In the context of the for loop, it makes sense to infer the list to the strictest type possible.

@YuriSizov YuriSizov merged commit 7325266 into godotengine:master Sep 28, 2023
15 checks passed
@YuriSizov
Copy link
Contributor

Thanks!

@dalexeev dalexeev deleted the gds-make-for-loop-array-literal-typed branch September 28, 2023 20:08
@dalexeev dalexeev mentioned this pull request Aug 29, 2024
10 tasks
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.

Statically incorrect type annotations are permitted on for loop variables
3 participants