Improve GDScript Parser error messages#114188
Improve GDScript Parser error messages#114188voylin wants to merge 1 commit intogodotengine:masterfrom
Conversation
88b10df to
f1bfc87
Compare
dalexeev
left a comment
There was a problem hiding this comment.
Thanks for the PR! Improvements like these should be accompanied by unit tests.
| // TODO: The analyzer can see if this is actually a Callable and give better error message. | ||
| push_error(R"*(Cannot call on an expression. Use ".call()" if it's a Callable.)*"); | ||
| String type_name = call->callee->get_datatype().to_string(); | ||
| if (type_name != "Variant" && type_name != "Callable") { | ||
| push_error(vformat(R"*(Type "%s" is not callable. Use ".call()" if it's a dynamic Callable.)*", type_name)); | ||
| } else { | ||
| push_error(R"*(Cannot call on this expression. Use ".call()" if it's a Callable.)*"); | ||
| } |
There was a problem hiding this comment.
This TODO refers to improving error checking at the static analysis stage. At the parsing stage, data types are not yet resolved.
There was a problem hiding this comment.
I'll look into this if I can achieve this or not.
There was a problem hiding this comment.
I've added the changes to gdscript_analyzer.cpp which are hopefully what was requested from this TODO.
Thanks! I'll get working on that when I find the time in the next few days. |
f1bfc87 to
6fec5ed
Compare
|
@dalexeev I added the necessary changes to the scripts and added some unit tests. (I hope that I did it correctly, added images to have more visual feedback. extends Control
# Unit test for set/get errors.
var x:
set(value): x = value
invalid_keyword: pass
var y:
get: return y
invalid_keyword: pass
var z:
invalid_keyword: pass
# Unreachable test
var test_var: int:
get:
return 0
print("unreachable getter")
set(val):
test_var = val
return
print("unreachable setter")
func _ready() -> void:
# Lambda unreachable test
var callable: Callable = func() -> void:
print("yes")
return
print("no")
# Function unreachable test
print("yes")
return
print("no") |
|
Doesn't look like you added any unit tests? |
699af45 to
f1e901d
Compare
7ba8ba3 to
99e1ce1
Compare
My bad, understood it wrong and thought results of the different prints should be mentioned in the PR. ^^" Added the unit tests, but I had to give up on |
Update modules/gdscript/gdscript_parser.cpp Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
99e1ce1 to
a5ab190
Compare
|
@AThousandShips Is there anything else I should do for this PR to get merged or doesn't it add enough value so it's better to close this PR? ^^" |
|
I can't speak to that, it still needs approval from the GDScript team |
Fixed/improved following TODO's inside of gdscript_parser.cpp
Line 3421: // TODO: The analyzer can see if this is actually a Callable and give better error message.Let me know if some need better wording or more information.
The set/get message:
Unreachable code of property setters and getters