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

Array functions do not return typed Arrays. #82538

Closed
produno opened this issue Sep 29, 2023 · 2 comments
Closed

Array functions do not return typed Arrays. #82538

produno opened this issue Sep 29, 2023 · 2 comments

Comments

@produno
Copy link

produno commented Sep 29, 2023

Godot version

v4.2.dev5.official [e3e2528]

System information

Godot v4.2.dev5 - Windows 10.0.22621 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4090 (NVIDIA; 31.0.15.3742) - 13th Gen Intel(R) Core(TM) i7-13700K (24 Threads)

Issue description

I am not entirely sure if this can be classed as a bug or requires a feature proposal but anyhow, i will post here first.

If we try and return a function from an Array, ie map, filter etc into a typed array we get an error.

Doing something like this:

var schedule_types: Array[int] :
    get: return ref.schedule_types.map(func(schedule: String) -> int: return Schedule.SCHEDULE_TYPE[schedule])

Shows this error upon execution.

Trying to return an array of type "Array" where expected return type is "Array[int]".

This is because the map function only returns an Array with no types. I think if the function in map returns a type then it should convert the return type of the Array to match that type.

For example, the above map func returns an int, so the Array it returns should be of type Array[int]

Steps to reproduce

Try to return the Array from the map (or other Array function) into a typed Array.

Minimal reproduction project

N/A

@dalexeev
Copy link
Member

Thanks for reporting the bug nonetheless!


This is because the map function only returns an Array with no types. I think if the function in map returns a type then it should convert the return type of the Array to match that type.

The current type system doesn't allow type to be inferred statically, we don't have something like:

class Array[T]:
    func map[TNew](callable: Callable[TNew, T]) -> Array[TNew]

And even dynamically Callable does not store such information. This is in GDScriptFunction, but Array.map() is a core method that does not depend on GDScript.

@dalexeev dalexeev closed this as not planned Won't fix, can't repro, duplicate, stale Sep 29, 2023
@produno
Copy link
Author

produno commented Sep 29, 2023

Ah ok, looks like this has already been doing the rounds. Sorry, i guess my search skills leave a little to be desired.

Thanks for the explanation.

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

2 participants