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

range() return value should be typed as Array[int] instead of Array #99648

Closed
gitsomebit opened this issue Nov 24, 2024 · 3 comments
Closed

range() return value should be typed as Array[int] instead of Array #99648

gitsomebit opened this issue Nov 24, 2024 · 3 comments

Comments

@gitsomebit
Copy link

gitsomebit commented Nov 24, 2024

Tested versions

4.3 stable

System information

Godot v4.3.stable - Windows 10 - GLES3 (Compatibility)

Issue description

I am always using typed variables as a best practice. In my code I wanted to use the following code:

var display_monitors: Array[int] = range(DisplayServer.get_screen_count())

This throws an error on assignment, because range() always returns and untyped Array even though its always an Array[int]. The docs even indirectly mention that only ints are returned:

range() converts all arguments to int before processing

To iterate over float, convert them in the loop.

Steps to reproduce

just assign range to an typed array and it fails:

var var_name: Array[int] = range(3)

Minimal reproduction project (MRP)

@gitsomebit
Copy link
Author

thanks for the fast reply.
I will leave this issue open for now as it seems there are more people that get hung up on it. Since this would break compatibility for cases such the following example it might be interesting for 5.x

Example
func _ready() -> void:
	var some_array: Array = new_range()
	some_array[0] = "asdf" # error
	some_array.append("asd") # error
	print(some_array)

func new_range() -> Array[int]:
	return [1,2,3]

@dalexeev
Copy link
Member

@dalexeev dalexeev closed this as not planned Won't fix, can't repro, duplicate, stale Nov 25, 2024
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