godot icon indicating copy to clipboard operation
godot copied to clipboard

Using enum from other class as a signal parameter type doesn't work as expected

Open miv391 opened this issue 1 year ago • 4 comments

Tested versions

  • Reproducible in Godot v4.4.dev3.mono

System information

Godot v4.4.dev3.mono - Windows 10.0.19045 - Multi-window, 1 monitor - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1060 6GB (NVIDIA; 32.0.15.6094) - Intel(R) Core(TM) i5-3570K CPU @ 3.40GHz (4 threads)

Issue description

Creating a signal that uses enum from some other class (SubNode in this case) works weirdly. My expectation is that you should use the full path of the enum, in this case SubNode.Foo:

signal signal_using_enum_from_another_class1(SubNode.Foo) 

But you get an error message:

Parse Error: Expected closing ")" after signal parameters.

However, if only the enum name without class is given, signal definition works:

signal signal_using_enum_from_another_class2(Foo)

Using enum from the same class also works.

I didn't test what happens if multiple classes have an enum with same name.

Steps to reproduce

kuva

subnode.gd:

class_name SubNode
extends Node2D

enum Foo {BAR}

main.gd

extends Node2D

enum MyEnum {ZAP}
signal signal_using_my_enum(MyEnum)

var a: SubNode.Foo

signal signal_using_enum_from_another_class1(SubNode.Foo)  # <---- error
signal signal_using_enum_from_another_class2(Foo)          # <---- for some reason this works

Minimal reproduction project (MRP)

signal_enum_test.zip

miv391 avatar Oct 17 '24 17:10 miv391

You forgot the parameter name, it should be something like:

signal signal_using_enum_from_another_class1(foo: SubNode.Foo)

dalexeev avatar Oct 17 '24 19:10 dalexeev

Interesting, I have succesfully used signals with only types, or so have I though. Apparently this signal

signal my_signal(String)

just has a single parameter named String. It is quite confusing that String is allowed parameter name as this obviously doesn't work:

var String: int

But well, this works:

func foo(String):
    print(String)

Maybe type names should not be allowed as parameter names in any situation.

miv391 avatar Oct 17 '24 20:10 miv391

Technically signals don't support type hints. They are allowed, but not used for anything. This might be the reason why they also lack proper checks.

KoBeWi avatar Oct 18 '24 01:10 KoBeWi

Interesting, I have succesfully used signals with only types, or so have I though.

GDScript is not C++, you can't use pure signatures, parameter names are mandatory. The closest we can get is prefixing unused parameters with underscores. Maybe someday we'll support something like:

func test(_: String, _: Array = []) -> void

But I don't think we'll be able to omit parameter names entirely, especially since static typing is optional.

dalexeev avatar Oct 21 '24 14:10 dalexeev