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

Move "Expected indented block" error message's line number back to where the error is #85488

Conversation

miv391
Copy link
Contributor

@miv391 miv391 commented Nov 28, 2023

Fixes #81046

In master "Expected indented block ..." error messages are assigned to code lines likes this:

kuva

The error message at line 7 tells that "Expected indented block after class declaration". The class declaration mentioned in error messages in not at line 7, it is at line 4. Other errors in screenshot are similar. The most confusing (I have seen this at Reddit discussions several times) is the error at line 16 which mentions function declaration. But the problem is not the function declaration at line 16, the problematic function declaration is at line 11.

In master, the error message line is obviously the line where the missing indented block is noticed.

This PR fixes this problem and now the same errors look like this:

kuva

Now all "Expected indented block ..." error messages are pointing to lines which are actually expecting something.

Other kind of errors seem to be unaffected by this change:

kuva

But I haven't tested with every different error message and I don't have deep understanding about GDScript parser, so something may have broken. If there exists somewhere a test project which contains all possible GDScript error, I would be interested about that.

It might also be worth considering about changing these "Expected indented block ..." error messages a bit.

"Expected indented block after class declaration"
-->
"Expected indented block after this class declaration"

Adding "this" would emphasize the fact that it is exactly this function that needs indented block after it. But I may be overcautious here.

@miv391 miv391 requested a review from a team as a code owner November 28, 2023 21:29
@AThousandShips AThousandShips added this to the 4.3 milestone Nov 28, 2023
@miv391 miv391 changed the title Moving "Expected indented block" error message lines numbers back to where the error is Moving "Expected indented block" error message's line number back to where the error is Dec 7, 2023
Copy link
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.

Makes sense to me since the current token can be separated from previous by empty lines or comments. I rebased and tested it locally, looks correct.

It would be nice to add some tests for the parser to prevent regressions:

800: 74: 	if (multiline && !consume(GDScriptTokenizer::Token::INDENT, R"(Expected indented block after class declaration.)")) {
1105: 62: 		if (!consume(GDScriptTokenizer::Token::INDENT, R"(Expected indented block for property after ":".)")) {
1127: 56: 			push_error("Property with inline code must go to an indented block.");
1180: 64: 		consume(GDScriptTokenizer::Token::DEDENT, R"(Expected end of indented block for property.)");
1679: 70: 		if (!consume(GDScriptTokenizer::Token::INDENT, vformat(R"(Expected indented block after %s.)", p_context))) {
2099: 64: 	if (!consume(GDScriptTokenizer::Token::INDENT, R"(Expected an indented block after "match" statement.)")) {
2151: 59: 	consume(GDScriptTokenizer::Token::DEDENT, R"(Expected an indented block after "match" statement.)");

@AThousandShips
Copy link
Member

Should probably also resolve:

@dalexeev
Copy link
Member

dalexeev commented Jun 4, 2024

Should probably also resolve:

No, I checked. #92681 is about a runtime error. It looks like it's being handled elsewhere, I'll take a look later.

@akien-mga akien-mga merged commit 09a0376 into godotengine:master Jun 10, 2024
15 checks passed
@akien-mga
Copy link
Member

Thanks!

@akien-mga akien-mga changed the title Moving "Expected indented block" error message's line number back to where the error is Move "Expected indented block" error message's line number back to where the error is Jun 20, 2024
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.

Error message "expected indented block" on misleading line
4 participants