Skip to content

Add opt-in GDScript warning for when calling coroutine without await #107936

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mihe
Copy link
Contributor

@mihe mihe commented Jun 24, 2025

Resolves godotengine/godot-proposals#12653.

This adds a new MISSING_AWAIT warning to GDScript, which is set to IGNORE by default, and which will be emitted when you try to call a coroutine as a "root" expression in a statement block without using await, meaning a scenario like this:

func _delay(time: float) -> void:
    await get_tree().create_timer(time).timeout

func _ready() -> void:
    _delay(1.0) # Warning: "await" keyword might be desired because the expression is a coroutine.
    print("Surely we must have waited a full second by now, right?")

This is of course a perfectly valid thing to want to do sometimes, in which case you can just disable the warning, like any other:

func _flash_red() -> void:
    modulate = Color.RED
    await get_tree().create_timer(0.2).timeout
    modulate = Color.WHITE

func take_damage(amount: float) -> void:
    health -= amount
    @warning_ignore("missing_await")
    _flash_red()

Note that this does not affect the already existing (and different) error that you get when trying to call coroutines within another expression (e.g. another function call):

func _find_meaning_eventually() -> int:
    await get_tree().process_frame
    return 42

func _ready() -> void:
    @warning_ignore("missing_await")
    print(_find_meaning_eventually()) # Error: Function "_find_meaning_eventually()" is a coroutine, so it must be called with "await".

@mihe mihe added this to the 4.x milestone Jun 24, 2025
@mihe mihe requested review from a team as code owners June 24, 2025 13:39
@mihe mihe force-pushed the missing-await-warning branch 2 times, most recently from d906012 to 80bf871 Compare June 24, 2025 14:15
@mihe mihe requested a review from a team as a code owner June 24, 2025 14:15
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.

LGTM

@mihe mihe force-pushed the missing-await-warning branch from 80bf871 to a3e58a3 Compare June 27, 2025 18:34
@mihe
Copy link
Contributor Author

mihe commented Jun 27, 2025

Rebased to resolve conflict.

@mihe mihe modified the milestones: 4.x, 4.6 Jun 27, 2025
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.

Add opt-in GDScript warning for when calling a coroutine without await
2 participants