-
-
Notifications
You must be signed in to change notification settings - Fork 21k
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
Impossible to call overloaded methods between languages #90946
Comments
CC @vnen @raulsntos |
Overloaded methods are not really supported but I feel like you should be able to workaround this:
Following all these steps, you should be able to fix this by adding a method like this (make sure it's the first one in the public void SayHello(Variant name = default)
{
GD.Print($"Hello {name}!");
} This would work if we supported default parameter values, but it looks we don't: godot/modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/ScriptMethodsGenerator.cs Line 321 in 4a01602
Also, keep in mind that this may add ambiguity in C# which may break compat for your C# users so it's not a perfect solution. |
Well, I'm not arguing if that was supported voluntarily or not. But the fact remains that this behaviour changes between 4.2.1 and 4.2.2, so it is a regression / a breaking change. I (and thus, maybe other users) am/was relying on it, as a side note: to work around the lack of default parameters. If we consider the new behaviour is the intended one, and this won't be fixed, we should communicate on it explicitly in the release notes.
For my personal use case, those methods are all EB never in C#, they are only there because of the lack of default params. |
Did it work reliably before though? Did it work for all methods of calling things etc.? |
As far as I know. I won't say I'll assure you I tested everything, but I've never witnessed any issue in my own testing. Nor have I had feedback from my user base (a majority of which makes calls to my API from GDScript) before this was reported on the 18th (I think 4.2.2 was released on the 17th). |
What happens if you create a callable from a method like this? Did it work reliably previously? And calling with Also did it work with an overload of a parent class method (unfamiliar with C# and the permissiveness there but it works in c++ so assuming) |
That is fair, I agree. I will test more cases, and report back. Whatever the results, I still believe this would have its place in the release notes. |
I agree |
Here are a few test cases you highlighted. The results correlate to what I'd expect. The C# code
public partial class Bar : Node
{
public void SayHello(string name)
{
GD.Print($"Hello {name}!");
}
public void SayHello()
{
GD.Print("Hello World!");
}
}
public partial class ExtendedBar : Bar
{
public void SayHello(string name, int n)
{
for (var i = 0; i < n; ++i)
{
GD.Print($"Hello {name}! ({i})");
}
}
} The calls in GDScript
print("--- Direct calls")
bar.SayHello()
bar.SayHello("paulloz")
print("--- Calls by name")
bar.call("SayHello")
bar.call("SayHello", "paulloz")
print("--- Calls through callable")
var callable = Callable(bar, "SayHello")
callable.call()
callable.call("paulloz")
callable.bind("bounded paulloz").call()
print("--- Calls to the one in ExtendedBar")
bar.SayHello("paulloz", 2)
bar.call("SayHello", "paulloz", 2)
callable.call("paulloz", 2)
print("--- Everything deferred")
bar.call_deferred("SayHello")
bar.call_deferred("SayHello", "paulloz")
bar.call_deferred("SayHello", "paulloz", 2)
callable.call_deferred()
callable.call_deferred("paulloz")
callable.call_deferred("paulloz", 2) Output
|
I think #90968 should fix this. When trying to get the method info for a method that has overloads, instead of returning the first method info we find, we now return an empty one. This means overloaded methods lose typing information for the GDScript analyzer but that's probably fine. |
Oh I missed that issue, it sounds like this is a duplicate then. |
Tested versions
name
field in MethodInfo operator == #86259System information
Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4060 (NVIDIA; 31.0.15.5222) - Intel(R) Core(TM) i5-10400F CPU @ 2.90GHz (12 Threads)
Issue description
Calling overloaded methods across language boundaries is not possible any more. Given the
Bar.cs
script provided below, trying to callBar.SayHello()
from GDScript is raising the following error:Such a call was possible without any issue in earlier versions (up to, including, 4.2.1).
Steps to reproduce
Foo.gd
.Bar.cs
.Minimal reproduction project (MRP)
MRP.zip
The text was updated successfully, but these errors were encountered: