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

Using 'as' keyword does nothing when attempting to cast typed arrays #75004

Closed
moil23 opened this issue Mar 16, 2023 · 2 comments
Closed

Using 'as' keyword does nothing when attempting to cast typed arrays #75004

moil23 opened this issue Mar 16, 2023 · 2 comments

Comments

@moil23
Copy link

moil23 commented Mar 16, 2023

Godot version

Godot 4

System information

Windows 10

Issue description

Don't think this is a duplicate - sorry if it's already been discussed.

Cannot cast from one typed array to another using the as keyword (this used to work in older G4 betas)

As it stands there is no way of converting typed arrays to another.

This is particularly relevant when attempting to use functional tools such as map, filter etc. on typed arrays and retain strong typing.

Several workarounds exists e.g. for loops and appending where conditions are met, but it would be nice to be able to cast arrays in some way, though maybe the as keyword is not the best way as it would not be clear what happens to elements that are not of the arrays type.

Steps to reproduce

extends Node

@onready var sprites := get_children().filter(func(node): return node is Sprite2D) as Array[Sprite2D]

Attach this script and running a scene with it will get the error "Trying to assign an array of type "Array[Node]" to a variable of type "Array[Sprite2D]"."

Minimal reproduction project

N/A

@AThousandShips
Copy link
Member

AThousandShips commented Mar 16, 2023

Duplicate of #72627, please search for relevant words

@Calinou
Copy link
Member

Calinou commented Mar 16, 2023

@Calinou Calinou closed this as not planned Won't fix, can't repro, duplicate, stale Mar 16, 2023
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

3 participants