Skip to content

Compiler bug: Unresolved return on doubled functions with while loops with await within #842

Description

@Scraprogrammer

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.
Pinned by bitwes

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions