godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
89.15k stars 20.21k forks source link

Parser Error: Cannot infer the type of return value of `await signal` to retrieve passed arguments #95424

Open hsandt opened 1 month ago

hsandt commented 1 month ago

Tested versions

System information

Godot v4.3.rc2 - Ubuntu 22.04.4 LTS 22.04 - X11 - GLES3 (Compatibility) - NVIDIA GeForce GTX 860M (nvidia; 535.183.01) - Intel(R) Core(TM) i7-4710HQ CPU @ 2.50GHz (8 Threads)

Issue description

I'm trying to retrieve the parameters/arguments passed to a signal as I await the signal. For convenience, I use type deducation:

signal my_signal(i: int)

func _ready():
    var signal_arg := await my_signal

I get a parser error on the line using type deduction:

Parser Error: Cannot infer the type of "anim_name" variable because the value doesn't have a set type.

Yet, said type can be deduced from the signal's signature.

Signals don't allow default values so there is no ambiguity on the number of arguments passed either.

Steps to reproduce

  1. Create project with new script and paste the code snippet above
  2. See Parser Error

Note: this is a dummy example and is not functional. If you really want to see the code in action you need to emit my_signal from somewhere else, then print signal_arg. But if you only want to check the Parser Error, this is not required.

Minimal reproduction project (MRP)

N/A

AThousandShips commented 1 month ago

According to the source this is a limitation: https://github.com/godotengine/godot/blob/88f3b5f9d52f740b24fabfb8bc01b8b7026ba279/modules/gdscript/gdscript_analyzer.cpp#L2877-L2880

akien-mga commented 1 month ago

Seems reproducible in 4.3.rc3 and 4.2.2.stable.

dalexeev commented 1 month ago

Yet, said type can be deduced from the signal's signature.

The signal signature is nominal (used in documentation and by the editor when generating a callback). Neither core nor GDScript checks the number and types of arguments passed to emit().