Skip to content

Improve GDScript Parser error messages#114188

Open
voylin wants to merge 1 commit intogodotengine:masterfrom
voylin:improve_not_callable_error
Open

Improve GDScript Parser error messages#114188
voylin wants to merge 1 commit intogodotengine:masterfrom
voylin:improve_not_callable_error

Conversation

@voylin
Copy link
Copy Markdown
Contributor

@voylin voylin commented Dec 19, 2025

Fixed/improved following TODO's inside of gdscript_parser.cpp

  • Line 1246: // TODO: Update message to only have the missing one if it's the case.
  • Line 2131: // TODO: Properties setters and getters with unreachable code are not being warned
  • 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:

image Results in: `SCRIPT ERROR: Parse Error: Expected "get" after "set" in property declaration.` and `SCRIPT ERROR: Parse Error: Expected "set" after "get" in property declaration.` image SCRIPT ERROR: Parse Error: Expected "get" after "set" in property declaration.

Unreachable code of property setters and getters

image image image image

@voylin voylin requested a review from a team as a code owner December 19, 2025 08:35
@dalexeev dalexeev added this to the 4.x milestone Dec 19, 2025
Comment thread modules/gdscript/gdscript_parser.cpp Outdated
@voylin voylin force-pushed the improve_not_callable_error branch from 88b10df to f1bfc87 Compare December 19, 2025 09:02
Copy link
Copy Markdown
Member

@dalexeev dalexeev left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Improvements like these should be accompanied by unit tests.

Comment thread modules/gdscript/gdscript_parser.cpp Outdated
Comment on lines +3421 to +3434
// 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.)*");
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This TODO refers to improving error checking at the static analysis stage. At the parsing stage, data types are not yet resolved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'll look into this if I can achieve this or not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've added the changes to gdscript_analyzer.cpp which are hopefully what was requested from this TODO.

@voylin
Copy link
Copy Markdown
Contributor Author

voylin commented Dec 19, 2025

Thanks for the PR! Improvements like these should be accompanied by unit tests.

Thanks! I'll get working on that when I find the time in the next few days.

@voylin voylin force-pushed the improve_not_callable_error branch from f1bfc87 to 6fec5ed Compare December 19, 2025 11:07
@voylin
Copy link
Copy Markdown
Contributor Author

voylin commented Dec 19, 2025

@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")

Comment thread modules/gdscript/gdscript_analyzer.cpp Outdated
@AThousandShips
Copy link
Copy Markdown
Member

Doesn't look like you added any unit tests?

@voylin voylin force-pushed the improve_not_callable_error branch 2 times, most recently from 699af45 to f1e901d Compare December 19, 2025 11:57
@voylin voylin requested a review from a team as a code owner December 19, 2025 11:57
@voylin voylin force-pushed the improve_not_callable_error branch 2 times, most recently from 7ba8ba3 to 99e1ce1 Compare December 19, 2025 12:31
@voylin
Copy link
Copy Markdown
Contributor Author

voylin commented Dec 19, 2025

Doesn't look like you added any unit tests?

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 Line 3421: // TODO: The analyzer can see if this is actually a Callable and give better error message. It's too much beyond what I can do at this point. Been trying to get it to print a better error message from gdscript_analyzer, but the unit tests and my own testing kept returning the standard "can't find function ...". So giving up on that one, but hopefully the other 2 are okay now.

Update modules/gdscript/gdscript_parser.cpp

Co-authored-by: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com>
@voylin voylin force-pushed the improve_not_callable_error branch from 99e1ce1 to a5ab190 Compare December 30, 2025 11:51
@voylin
Copy link
Copy Markdown
Contributor Author

voylin commented Feb 26, 2026

@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? ^^"

@AThousandShips
Copy link
Copy Markdown
Member

I can't speak to that, it still needs approval from the GDScript team

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.

3 participants