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 2.0: assert() containing line breaks results in an syntax error #66535

Closed
Tracked by #40488
ydipeepo opened this issue Sep 28, 2022 · 10 comments · Fixed by #70655
Closed
Tracked by #40488

GDScript 2.0: assert() containing line breaks results in an syntax error #66535

ydipeepo opened this issue Sep 28, 2022 · 10 comments · Fixed by #70655

Comments

@ydipeepo
Copy link

ydipeepo commented Sep 28, 2022

Godot version

v4.0.beta1.official [20d6672]

System information

It's not system specific error.

Issue description

Any condition containing newlines in assert's () will result in a syntax (grammatical?) error.

Steps to reproduce

assert(
    true or
    true) # It raises "Expected expression to assert." at edit time.

But. Its works with \:

assert( \
    true or \
    true)
assert(
    true) # error

Minimal reproduction project

Include line breaks in assert expression.

@TheDuriel
Copy link
Contributor

This is correct? You can't do this in any other context either.

@ydipeepo
Copy link
Author

@TheDuriel Idk but I was wondering if it was allowed cuz it was possible in 3.5.
I hitted this problem when porting my addons.

Normal calls allow line breaks like this:

my_func(
    "text",
    1234,
    true
)

@TheDuriel
Copy link
Contributor

What's letting you do that there, is the comma "escaping the linebreak".

assert(
    true or false)
assert(
    true or \
    false)

Should work.

OR and other operators require your code to continue on the same line.

@ydipeepo
Copy link
Author

Yup, I know. Is it okay to recognize that it has become stricter?

@TheDuriel
Copy link
Contributor

I'm not convinced from your example that is has.

@ydipeepo
Copy link
Author

ydipeepo commented Sep 28, 2022

I checked it again.
It seems that line breaks between operands are not allowed in this version at the or / and, binary and unary operators in any function call arguments.
I don't know if it's a bug or a lang spec change, but I was able to deal with it like this:

assert((
    1 +
    1
)) # works
ceil(
    0.0) # OK
assert(
    true) # Error

@TheDuriel
Copy link
Contributor

It'd be nice if you could do exact comparisons between 3.x and 4.x for this. With normal function calls and asserts.

@ydipeepo
Copy link
Author

Sorry, I looked further and it seems that regardless of the operator, simply cannot break a line.

#66535 (comment)

@Calinou Calinou added this to the 4.0 milestone Sep 29, 2022
@Calinou Calinou changed the title GDScript - assert() containing line breaks results in an syntax error. GDScript 2.0: assert() containing line breaks results in an syntax error. Sep 29, 2022
@Calinou Calinou changed the title GDScript 2.0: assert() containing line breaks results in an syntax error. GDScript 2.0: assert() containing line breaks results in an syntax error Sep 29, 2022
@hsandt
Copy link
Contributor

hsandt commented Nov 6, 2022

To complete use cases, I had this issue when splitting my long assert message over multiple lines:

	assert(is_on_floor(), "_get_floor_tangent: is_on_floor() is true yet get_floor_normal() " +
		"returned Vector2.ZERO.")

Replacing assert with a condition + push_warning for instance, will work.

@adamscott
Copy link
Member

I confirm this issue on master (fcba87e).

Minimal reproduction project

66535.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants