-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
set() or object assignment looks for more specific type than returned by typeof() #93067
Comments
This tracker is intended for engine or documentation bugs. If you want to propose a new feature or change to functionality that works as designed, please use godot-proposals instead. You raised several questions at once:
However, I think all these questions are already known, documented or being discussed:
|
That is fair, we can close this if it doesn't feel "bug-like" enough.
I'm not sure I'm knowledgeable enough to make a proposal for a change myself. That might have to wait a year. (For example, I wasn't even aware of the If there was a place to add use-cases in the context of discussion I would do that, but there's not. I do think there are some minor additions here. This is the first request I've noticed for "convert to the same as" or of wanting a function to return the GDScript type of an array. Most of the other requests are using hardcoded types. Other than that, I would agree that the individual components have been discussed. I don't feel I'm educated enough to request a specific right solution to this problem, and I agree this isn't a pressing specific bug, so I'll close it. |
Tested versions
Found in Godot 4.2.2.
System information
Godot v4.2.2.stable unknown - Arch Linux #1 SMP PREEMPT_DYNAMIC Fri, 31 May 2024 15:14:45 +0000 - Tty - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4060 Ti (nvidia; 550.78) - Intel(R) Xeon(R) CPU E5-2690 v3 @ 2.60GHz (24 Threads)
Issue description
I'm filing a usability bug. I think everything below is working as designed, I'm just running into some problems with parts of the design being inconsistent, and it making Godot less usable in practice.
When using:
self[k] = v
, it appears the type has to match exactly. Not justArray
, butArray[int]
. That's fine.However, there doesn't seem to be an easy way to actually do the conversion, because
typeof()
returns only the Variant.TypeArray
, andtype_convert()
also looks only at Variant.Type. So if you start with untyped data, which you perhaps know the type of, I'm not sure of a way to add typing information. This is a usability bug.Below is a short reproduction case of the issue. (For this sample code, it's also relevant that you can't annotate the types of individual dictionary values.)
Note that for the related built-in function
set()
, the same failure happens. Instead of a user-visible error, typed Array values are silently skipped (when assigned value is of typeArray
), which is the original bug I dug into.Ideally, I would like the final reproduction code to work, whether because the []= operator becomes more permissive about typed arrays, or the convert() operator starts accepting more specific types.
Also relevant:
typeof()
does not return it.)Steps to reproduce
Minimal reproduction project (MRP)
bug-repro.zip same code as above
The text was updated successfully, but these errors were encountered: