-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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 untyped_declaration
warning
#81355
Add an optional untyped_declaration
warning
#81355
Conversation
2af43ab
to
074831e
Compare
074831e
to
bdcc2b9
Compare
(also the failure of the "Test Godot Project" isn't related to this PR but a random error) |
bdcc2b9
to
0277011
Compare
0277011
to
07322a9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My requests were done, but someone from the GDScript team should do the proper review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment and code style and phrasings look good to me, haven't tested the code specifically
bf09cab
to
ec188d7
Compare
Went ahead and tested this with my own project. Everything appears to work as expected! 🥳 EDIT: I need to investigate an issue with lambdas |
ec188d7
to
9f2bb09
Compare
Issue with lambdas is fixed! I think it would now be ready for review! |
Don't currently have time for a more thorough review, but since I didn't notice any explicit mention of class members, I assume this already works with them, because their declaration might work as an assignable? :) |
I'm not sure return values fall under "static typing" and warrants a separate error setting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved
The bug with setter should be fixed this way:
godot/modules/gdscript/gdscript_analyzer.cpp
Line 1280 in 0a7f75e
if (member.variable->getter != nullptr) { |
if (member.variable->getter != nullptr) {
- member.variable->getter->set_datatype(member.variable->datatype);
+ member.variable->getter->return_type = member.variable->datatype_specifier;
+ member.variable->getter->set_datatype(member.get_datatype());
resolve_function_body(member.variable->getter);
}
if (member.variable->setter != nullptr) {
- resolve_function_signature(member.variable->setter);
-
- if (member.variable->setter->parameters.size() > 0) {
- member.variable->setter->parameters[0]->datatype_specifier = member.variable->datatype_specifier;
- member.variable->setter->parameters[0]->set_datatype(member.get_datatype());
- }
+ ERR_CONTINUE_MSG(member.variable->setter->parameters.is_empty(), "Parser bug: Setter must have an argument.");
+ member.variable->setter->parameters[0]->datatype_specifier = member.variable->datatype_specifier;
+ member.variable->setter->parameters[0]->set_datatype(member.get_datatype());
resolve_function_body(member.variable->setter);
}
Also note that you can optionally specify a type for the for
loop variable (see #80247). This is a bit different from the rest of the cases, so please don't do anything about it just yet. I will think about it and write my opinion later.
@AThousandShips Since this PR is ready and approved, would it be possible to update the milestone to 4.2? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed during the GDScript Team meeting. Looks good! Thanks for the PR, @ryanabx!
Needs a rebase. |
e69ff06
to
14edf04
Compare
Done! |
untyped_declaration
warning
Thanks! |
I am using 4.2 beta 3 and for some reason I get warnings when I don't specify the
Did this changed at some point? |
Init doesn't have a return type, and I think it actually warns you if you do use one, not sure. For any other method, a warning is issued if there's no return type specified |
If I remember correctly, this was originally implemented incorrectly. I've updated the first post. I don't think we should make an exception for |
What I'd suggest is to make And autocompletion helps, but only when implementing already defined functions that it can suggest. For new functions it won't know that you want it to be For instance TypeScript works the way I suggest. In the following code it will complain if I don't type the argument function f(a: string) {
console.log(a)
} if we still see value in forcing the developer to explicitly type |
I added a feature request to Infer implicit void return type in GDScript for functions without return values |
Addresses (and may close) godotengine/godot-proposals#173
Adds a new property to ProjectSettings: debug/gdscript/warnings/untyped_declaration, which will print a warning or error if there are variables, parameters, or constants that aren't explicitly typed using
: <type>
or during initialization,:=
.A warning will also be thrown if a function does not have an explicit return type.
This does not affect _init() as it shouldn't have a return type other than void anyways, and is always implicitly void.Feel free to test!
Bugsquad edit: Outdated information removed.