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

double() fails if script director uses method with user-defined default arguments #308

Closed
RailKill opened this issue Oct 27, 2021 · 6 comments
Assignees
Labels
bug Something isn't working priority requires urgent attention resolved For features and refactors that got added

Comments

@RailKill
Copy link
Contributor

Issue description

WAT Version: 6.0.0
Godot Version: 3.3.4
OS: Windows 10

Steps to reproduce the issue

  1. Edit examples/doubles/calculator.gd and put a default value in one of the arguments of the add() method as such:
func add(a, b = 5) -> int:
  return a + b
  1. Run the method director tests.

What's the expected result?
Tests should pass.

What's the actual result?

 built-in:7 - Parse Error: The function signature doesn't match the parent. Parent signature is: "int add(Variant, Variant=default)".
 modules/gdscript/gdscript.cpp:585 - Method failed. Returning: ERR_PARSE_ERROR
 Error calling method from 'callv': 'GDScript::new': Method not found..
 res://addons/WAT/double/script_director.gd:138 - Invalid get index 'WATRegistry' (on base: 'Nil').
@RailKill
Copy link
Contributor Author

Seems like Godot's get_script_method_list() isn't returning the default arguments correctly, which is probably the root cause of this issue. Bug report here: godotengine/godot#33624

Haha, just saw that GUT also opened an issue on this: bitwes/Gut#263. They have a stub that can specify default arguments, but I don't like that idea of letting the user modify the method signature here because it weakens the purpose of a double. Might as well write a short and simple mock class at that point, which is always a valid workaround. I suggest we keep this issue open until the PR is merged into Godot 4.0 and its release, and then we can make sure it works there. Alternatively, we can write our own script reader - or some kind of intermediary parser for method declarations only so that the default arguments can be added in, but that's overkill in my opinion.

@AlexDarigan AlexDarigan self-assigned this Nov 20, 2021
@AlexDarigan AlexDarigan added the bug Something isn't working label Nov 20, 2021
@AlexDarigan AlexDarigan added the benched for abandoned features that may be worth revisiting label Dec 18, 2021
@AlexDarigan
Copy link
Collaborator

I have a lot of plans for 4.0 but want to focus issues on 3.X.X for now so I'm going to close this and marked it as a benched so we know to come back to it.

@AlexDarigan AlexDarigan removed the benched for abandoned features that may be worth revisiting label Dec 26, 2022
@AlexDarigan
Copy link
Collaborator

Reopening unresolved issue.

A note: Considering writing test doubles as separate plugin that can be used in conjunction with WAT rather than a core feature of WAT which should hypothetically allow for a more robust Test Double system.

@AlexDarigan
Copy link
Collaborator

I've been thinking about this. A large problem was that previously it would have been hard to find which script this method existed in, which means the script we would be parsing for the defaults might not have the function at all. However thanks to the event of get_script_method_list(), it seems we'll be able to loop to the correct script to double the method. then do a source.split("\n") or some form of regex(func name(*)) and then parse the paranthesis. We'd likely focus on doubling primitive defaults for now though.

@AlexDarigan AlexDarigan added priority requires urgent attention and removed Waiting for Godot We can't do this by ourselves labels May 1, 2023
@AlexDarigan
Copy link
Collaborator

In ScriptDirector, we have the set methods function which is already handling the built in defaults (since these ones actually work correctly)
image

My idea here is, if it isn't nested or built-in, we use a different default args by looping through the source code until we find the function in quest. Split the source code, and then attempt our best to extract the args, and types.

@AlexDarigan AlexDarigan changed the title double() fails if script director uses method with default arguments double() fails if script director uses method with user-defined default arguments May 1, 2023
@AlexDarigan
Copy link
Collaborator

Finally resolved by #373

Inner Classes are still limited but that cost-value ratio just isn't worth it for now, so optional keywords and retvals are kept in.

@AlexDarigan AlexDarigan added the resolved For features and refactors that got added label May 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority requires urgent attention resolved For features and refactors that got added
Projects
None yet
Development

No branches or pull requests

2 participants