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

Weird error messages if trying to make a static get_name() function #84326

Open
miv391 opened this issue Nov 1, 2023 · 6 comments
Open

Weird error messages if trying to make a static get_name() function #84326

miv391 opened this issue Nov 1, 2023 · 6 comments

Comments

@miv391
Copy link
Contributor

miv391 commented Nov 1, 2023

Godot version

v4.2.beta3.mono.official [e8d57af]

System information

Godot v4.2.beta3.mono - Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1060 6GB (NVIDIA; 31.0.15.3640) - Intel(R) Core(TM) i5-3570K CPU @ 3.40GHz (4 Threads)

Issue description

foobar.gd:

class_name Foobar
extends Object

static func get_name(i: int) -> String:
	return str(i)

node_2d.gd which uses Foobar:

extends Node2D

func _ready():
	# Invalid call to function 'get_name' in base 'GDScript'. Expected 0 arguments.
	var i = Foobar.get_name(42)

	# Parser Error: Too few arguments for "get_name()" call. Expected at least 1 but received 0.
	var j = Foobar.get_name()

If I try to call Foobar's static get_name with one parameter (as it is implemented), I get an error message saying that 0 arguments are expected. But when I remove the argument, now the error message says that 1 argument is expected.

I'm guessing that get_name is a name that just cannot be used as a static function name. As a member function name it is usable.

The problem here is that the current error messages do not help to understand what is going on. If a static get_name is not allowed at all, I would expect an error message saying just that at foobar.gd where I try to implement that function.

Steps to reproduce

As above.

Minimal reproduction project

N/A

@AThousandShips
Copy link
Member

That's because get_name is a method in GDScript, you can't name a static method the same as an existing one AFAIK

@miv391
Copy link
Contributor Author

miv391 commented Nov 1, 2023

get_name still seems to be different than for example sqrt. This works as expected and can be used without error:

foobar.gd:

static func sqrt(f: float) -> float:
	return 0.0

node_2d.gd:

print(Foobar.sqrt(1.0))

Also, the documentation doesn't seem to include that GDScript level get_name function which makes it a bit difficult to find why your code doesn't work.

@AThousandShips
Copy link
Member

No, get_name is a method of Resource which GDScript inherits

@miv391
Copy link
Contributor Author

miv391 commented Nov 1, 2023

Oh yes, Resource seems to have a get_name getter. A specific error message for these situations would be nice.

@AThousandShips
Copy link
Member

There should be one already but might be mistaken, will investigate when I have time

@dalexeev
Copy link
Member

dalexeev commented Nov 2, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants