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

Typed array methods return Variant #63892

Closed
KoBeWi opened this issue Aug 4, 2022 · 3 comments
Closed

Typed array methods return Variant #63892

KoBeWi opened this issue Aug 4, 2022 · 3 comments

Comments

@KoBeWi
Copy link
Member

KoBeWi commented Aug 4, 2022

Godot version

ea4b8de

System information

Windows 10 x64

Issue description

var arr: Array[int]
var v := arr[0] # works
var v2 := arr.front() # Could not infer the type of the variable "v2" because the initial value is a variant.

I'd expect the front() to correctly return int.

Steps to reproduce

  1. Add typed array
  2. Try infer return value of any method that returns an element

Minimal reproduction project

No response

@akien-mga akien-mga added this to the 4.0 milestone Aug 4, 2022
@akien-mga
Copy link
Member

Related to #62709 (comment)

I don't know if that's fixable given that TypedArrays are still normal Variant arrays internally. Maybe with more specific handling for their hint in GDScript.

@amoriqbal
Copy link
Contributor

amoriqbal commented Oct 9, 2022

Two possible ideas to fix this:

  1. Treat arrays as objects of classes. Array[int] and Array[float] should then be objects of two different autogenerated classes (say e.g. _GD_TypedArray_1 and _GD_TypedArray_2).
  2. Change Variant::Type from enum to a class. Then we can keep member variables to keep track of other details like type of elements of array. We can also use operator overloading to enable something like arr1.type == arr2.type.

@kleonc
Copy link
Member

kleonc commented Oct 26, 2022

Duplicate of #59721.

@kleonc kleonc closed this as not planned Won't fix, can't repro, duplicate, stale Oct 26, 2022
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

4 participants