Versions
(list all versions where you have replicated the bug)
- Godot: 4.7.0
- GUT: 9.7.0
- OS: Windows 11
The Bug
Functions of a double that have a while loop within them with an await will cause an error to be produced. The error will not stop the execution of the test and asserts will pass, but the test will still fail because an uncaught error was thrown. The error:
ERROR: Compiler bug: Unresolved return.
at: write_return (modules/gdscript/gdscript_byte_codegen.cpp:1846)
GDScript backtrace (most recent call first):
[0] create_script_from_source (res://addons/gut/dynamic_gdscript.gd:28)
[1] create_script_from_source (res://addons/gut/utils.gd:368)
[2] _create_script_no_warnings (res://addons/gut/doubler.gd:185)
[3] _create_double (res://addons/gut/doubler.gd:215)
[4] _partial_double (res://addons/gut/doubler.gd:308)
[5] partial_double (res://addons/gut/doubler.gd:321)
[6] _smart_double (res://addons/gut/test.gd:372)
[7] partial_double (res://addons/gut/test.gd:2662)
[8] test_name_does_not_matter (res://tests/unit/test_dbl_fail.gd:6)
[9] _run_test (res://addons/gut/gut.gd:622)
[10] _test_the_scripts (res://addons/gut/gut.gd:835)
[11] test_scripts (res://addons/gut/gut.gd:1045)
[12] run_tests (res://addons/gut/gui/GutRunner.gd:198)
[13] _run_tests (res://addons/gut/cli/gut_cli.gd:239)
[14] main (res://addons/gut/cli/gut_cli.gd:297)
[15] _init (res://addons/gut/gut_cmdln.gd:39)
Steps To Reproduce
Have a class to be doubled:
class_name FailTestClass
extends Node
var should_stop_waiting: bool = false
func wait_with_while() -> bool:
while not should_stop_waiting:
await get_tree().create_timer(1.0).timeout
should_stop_waiting = true
return true
Have a test:
extends GutTest
func test_name_does_not_matter() -> void:
# Arrange
var dbl: FailTestClass = partial_double(FailTestClass).new()
# Assert
assert_not_null(dbl)
Run the text and get the error listed above.
Extra context
- Same behavior if a double is used instead of the partial double.
- If
await get_tree().create_timer(1.0).timeout is removed from the function - the error disappears.
Versions
(list all versions where you have replicated the bug)
The Bug
Functions of a double that have a
whileloop within them with an await will cause an error to be produced. The error will not stop the execution of the test and asserts will pass, but the test will still fail because an uncaught error was thrown. The error:Steps To Reproduce
Have a class to be doubled:
Have a test:
Run the text and get the error listed above.
Extra context
await get_tree().create_timer(1.0).timeoutis removed from the function - the error disappears.Status
For anyone making your way here from the output of your tests, here's what's happening.
As of GUT 9.7.1, the error is being ignored and will no longer cause tests to fail. The error still appears in the log. Godot's source indicates that this message shouldn't be reachable, but everyone knows that if you comment "should not get here", someone will eventually end up there.
Workaround
If you remove the return type from the method generating the error, then the error will go away. It's not a great workaround, but its the only one we got.
Full Solution
Maybe Godot will remove the error. If not, a complete fix will require adding return type clauses to methods when generating the source…