-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Add an optional warning to type inferred variables and parameters #59428
Conversation
The checks are failing because the documentation hasn't been updated yet, I'll get them up to date tomorrow. |
0620c44
to
ded90b8
Compare
Fixed 👍 |
186c98e
to
12654f5
Compare
Changed the property info for 'Enforce Static Types' warnings to use 'Disabled' instead of 'Ignore' for the enum strings. |
Docs need to be updated, I'll get to it soon |
bb674d0
to
79ca41c
Compare
Looks good! In addition to the review comment above, I suggest also renaming "Enforce Static Parameter Types" to "Enforce Static Method Parameter Types" to be more explicit. PS: It seems this pull request actually closes godotengine/godot-proposals#173, not godotengine/godot-proposals#3284. |
79ca41c
to
4f791d3
Compare
Gotcha, I've renamed it and edited the referenced proposal. The docs should be correct now too. |
1a2644c
to
a8d3fda
Compare
ddb3051
to
bbd4fa1
Compare
Correct me if I'm wrong, but I think you could also specify the type as |
This comment was marked as off-topic.
This comment was marked as off-topic.
4dfcf97
to
12654f5
Compare
I separated the enum warnings commit to #59943. |
d46e269
to
c38cc24
Compare
|
1a008a9
to
3b1fb0e
Compare
The checks are failing because the documentation uses int instead of bool. The int comes from #59943 |
3b1fb0e
to
486a175
Compare
Rebased to be up to date with master. |
The existing warnings are named after what triggers them, for example "shadowed member variable" or "int assigned to enum". |
Sounds like a good idea. I'll change it along with any other needed changes. |
Waiting for this to get merged 👀 |
I'm not sure if this would be merged right now because of the feature freeze. I believe the changes from the PR review have been implemented, so I think this is just waiting to be reviewed again. |
What about polymorphic types? Will this PR produce a warning in the last line of the following code:
Static typing would result in compile time error here but what GDScript does is a runtime type check (which may or may not result in an error). I'm asking because this PR is allegedly adressing godotengine/godot-proposals#173. |
This is probably obvious but does typing GDScript statically improve performance? Is that the main reason for this? If so, I think this would be an excellent feature as people can get the GDScript integration combined with the speed of a statically typed language like C#. More discussion: https://www.reddit.com/r/godot/comments/vj4cs8/is_there_a_way_to_force_static_typing_in_godot_40/ |
Since 4.0, it does thanks to typed instructions. Prior to 4.0, there was no performance impact whatsoever.
The main reason is easier code maintenance and better autocompletion, rather than performance. People like TypeScript a lot, yet it doesn't make your code any faster than JavaScript 🙂 |
Superseded by:
Thanks for the contribution nonetheless! |
Relies on #59943
Closes godotengine/godot-proposals#173 and godotengine/godot-proposals#3531
Warnings are now enum values (Ignore, Warn, Error) to allow setting whether you want a warning to be treated as either an error, a warning, or ignored.
The way warnings are initialized in gdscript.cpp has been improved to offer more flexibility. (Support for property info per warning and different default values.)
Type Inferencing
Added new warnings that will let the user know if a variable or parameter they defined is not statically typed (Set to 'Ignore' by default)
Variables that are assigned to null when declared are ignored so that if you absolutely need to, you can still have a dynamically typed variable.