Skip to content
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

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

Open
miv391 opened this issue Oct 17, 2024 · 4 comments
Open

Comments

@miv391
Copy link
Contributor

miv391 commented Oct 17, 2024

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

@dalexeev
Copy link
Member

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

signal signal_using_enum_from_another_class1(foo: SubNode.Foo)

@miv391
Copy link
Contributor Author

miv391 commented Oct 17, 2024

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.

@KoBeWi
Copy link
Member

KoBeWi commented Oct 18, 2024

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.

@dalexeev
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: For team assessment
Development

No branches or pull requests

3 participants