-
-
Notifications
You must be signed in to change notification settings - Fork 21.2k
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
get_script_method_list is missing defaults in some cases #66218
Comments
This bug is still valid! func test_parameterized_int_values(a: int, b :int, c :int, expected :int = 1, test_parameters := [
[1, 2, 3, 6],
[3, 4, 5, 12],
[6, 7, 8, 21] ]) -> void: The "default_args": [
1,
null
], "default_args": [
1,
[[1, 2, 3, 6], [3, 4, 5, 12], [6, 7, 8, 21] ]
], results in {
"args": [
{
"class_name": "",
"hint": 0,
"hint_string": "",
"name": "a",
"type": 2,
"usage": 0
},
{
"class_name": "",
"hint": 0,
"hint_string": "",
"name": "b",
"type": 2,
"usage": 0
},
{
"class_name": "",
"hint": 0,
"hint_string": "",
"name": "c",
"type": 2,
"usage": 0
},
{
"class_name": "",
"hint": 0,
"hint_string": "",
"name": "expected",
"type": 2,
"usage": 0
},
{
"class_name": "",
"hint": 0,
"hint_string": "",
"name": "test_parameters",
"type": 28,
"usage": 0
}
],
"default_args": [
1,
null
],
"flags": 1,
"id": 0,
"name": "test_parameterized_int_values",
"return": {
"class_name": "",
"hint": 0,
"hint_string": "",
"name": "",
"type": 0,
"usage": 6
}
}
|
This is not exactly a bug. Arrays and dictionaries are passed by reference, and two equal arrays are not the same. So by default (as in the case of function parameters) they are not constant expressions. To be treated as a constant expression, an array must be in constant context, in which case the array will be made read-only. In the following case it is impossible to get the full "default" value: func f(x, y = [1, x, 3]): pass
# Value unknown. ^ In the following case, this is potentially possible, but we would need to reduce the expression twice, in the normal context and in the constant context (without generating errors if the expression is not constant): func f(x, y = [1, 2, 3]): pass For this reason, in many languages, initializers for global variables, class fields, and function parameters are required to be constant expressions. This also solves the problem with the initialization order at runtime. |
Ok ... ;), what this mean at the end? Is there another way to grab the default arguments without writing your own parsers? |
I think this can be implemented without significant refactoring. Perhaps we could reuse the function |
Ok thanks, unfortunately that would only partially help me, but better than nothing ;) |
Bump on this issue. Are there any updates? Right now I'm implementing some custom mocking tools, and need to be able to get an accurate description of a function's signature, default args and all. At least as of
More full context: Unfortunately, to do that, I need to know if there's a signature mismatch, and I can only do that if I can dynamically determine what the default args of the real class constructor are. In the case above, I'd end up passing in |
Godot version
4.0.alpha17
System information
macOS 10.15.7
Issue description
Some default values do not appear in the script method metadata
default_args
. When they are missing, there is no way to know which parameters have defaults. For example, the defaults listed in the metadata forContains two entries
From this information, you cannot determine how many parameters have been defaulted and which get the default values that are provided.
In order to reliably find defaulted parameters and associate values with them, you need to know
default_args
Something like this would work
or
For my purposes, simply knowing how many parameters are defaulted is extremely useful. I use this information to generate doubles of objects in the GUT testing framework addon.
Steps to reproduce
Given this script at
res://demo_missing_defaults.gd
You get the following output:
Minimal reproduction project
See Steps to reproduce.
The text was updated successfully, but these errors were encountered: