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

GDScript: Fix multiline and trailing comma for assert #70655

Merged
merged 1 commit into from
Jan 9, 2023

Conversation

vonagam
Copy link
Contributor

@vonagam vonagam commented Dec 28, 2022

Fixed parsing of assert with multiline and/or trailing comma.

Fixes #66535.

@vonagam vonagam requested a review from a team as a code owner December 28, 2022 02:37
@KoBeWi KoBeWi added this to the 4.0 milestone Dec 28, 2022
Comment on lines +5 to +22
assert(x > 0,)
assert(x > 0, 'message')
assert(x > 0, 'message',)

assert(
x > 0
)
assert(
x > 0,
)
assert(
x > 0,
'message'
)
assert(
x > 0,
'message',
)
Copy link
Member

Choose a reason for hiding this comment

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

Why are the trailing commas allowed? It doesn't make any sense to me, I'd expect an error when there's a trailing comma.

Copy link
Member

Choose a reason for hiding this comment

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

I agree, the trailing comma doesn't really make sense.

Copy link
Contributor Author

@vonagam vonagam Dec 29, 2022

Choose a reason for hiding this comment

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

I'm not sure I understand the surprise:

func method(a, b = 'c',) -> void:
  print(a, b,)

func _ready() -> void:
  method('a',)
  method('a', 'b',)
  print(['a',],)

Trailing commas and multi-line are supported by method calls and arrays. That's just make it behave consistent with those. What am I missing?

Copy link
Member

Choose a reason for hiding this comment

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

@vnen Is this a bug or a feature?

Copy link
Contributor Author

@vonagam vonagam Dec 29, 2022

Choose a reason for hiding this comment

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

It is a feature. Search for "// Allow for trailing comma." comment in parser - parse_call, parse_signal, parse_enum, parse_function_signature, parse_array, parse_dictionary all have that comment for code that allows trailing comma.

The utility is visual consistency and smaller more relevant diffs/blame in git. So for example, you can write code like:

assert(
  condition,
)

And then later in a separate commit add an error message, that would be 1 line addition instead of addition of 2 lines and removal of 1.

Copy link
Contributor

@anvilfolk anvilfolk left a comment

Choose a reason for hiding this comment

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

LGTM! :) Batch reviewing these smaller PRs to see if we get some momentum going, hehe :)

modules/gdscript/gdscript_parser.cpp Show resolved Hide resolved
modules/gdscript/gdscript_parser.cpp Show resolved Hide resolved
Copy link
Member

@vnen vnen left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@akien-mga akien-mga merged commit c2f7c2d into godotengine:master Jan 9, 2023
@akien-mga
Copy link
Member

Thanks!

@vonagam vonagam deleted the fix-assert-multiline branch January 12, 2023 14:53
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.

GDScript 2.0: assert() containing line breaks results in an syntax error
7 participants