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

Parser bug when using "and" and "or", or equality operators in return statements with return types. #82765

Closed
Turnovus opened this issue Oct 4, 2023 · 2 comments · Fixed by #82789

Comments

@Turnovus
Copy link

Turnovus commented Oct 4, 2023

Godot version

v4.1.1.stable.official [bd6af8e]

System information

Windows 10

Issue description

The exact error I receive is:
Parser bug (please report): Trying to check compatibility of unset value type

The error occurs whenever I have a func with a strict return type defined using ->, and when I use the and or or operators, or an equality operator (==, !=, etc.) in a return statement.

The parser seems to be choking on the operators themselves. The issue only seems to occur when only the first (left-hand) operand is present.

Steps to reproduce

Step-by-step guide

  • Write the header for a function
  • Give it any strict return type. bool is the most viable since the affected operators return bools, but you can use any return type. The bug occurs regardless of whether or not the code is valid.
  • In the function body, add a return statement.
  • Put any primitive or a variant name after return.
  • Add either the or or and operator.
  • Wait a moment for the parser to notice the operator. As soon as it does, the error message will appear in the output.
  • Hold down the control key. The error will be output repeatedly, as long as you hold the key, and as long as the script editor is focused (you may need to place your mouse cursor over some text for this to work).

Specific examples
Using the editor's default GDScript editor, type this:

func my_func() -> bool:
	return true or

Give the editor a moment to process after you type the "r" in or. You can substitute or with and for the same result.

Equality comparisons also cause the error

func foo() -> bool:
	return true !=

All of the affected operators, as I've been able to find so far, are:

  • and
  • or
  • ==
  • !=
  • <=
  • >=

You can also substitute true for a variant or any other primitive, the result is the same.

func foo() -> int:
	return "something" and

func bar() -> RandomNumberGenerator:
	var a = "something"
	return a and

The following code does not cause the error to occur. It simply causes an "Expected end of statement after return" error in the editor, as expected.

func foo() -> bool:
	return and true

Typing anything after the operator does not cause the error. The following code is perfectly fine as it appears, but will cause the error as it is being typed-out.

func foo() -> bool:
	return true or false

Typing a whitespace character (space or indent) after the operator will not cause the error to appear immediately. It will cause the error if you hold down the control key, assuming you haven't typed anything else after the whitespace.

The operators is and as do not appear to cause this error. Most arithmetic operators (+-/*%) also seem fine, as do the non-equal inequality operators (< and >) I do not know about any other operators at this time.

Minimal reproduction project

func my_func() -> bool:
	return true or
@miv391
Copy link
Contributor

miv391 commented Oct 4, 2023

Doesn't seem to happen in v4.2.dev6.official [57a6813]

kuva

@dalexeev
Copy link
Member

dalexeev commented Oct 4, 2023

Reproducible in master. You need to type something, but not save the script.

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

Successfully merging a pull request may close this issue.

4 participants