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

Alpha 5 regression: Custom class typed array is broken. #59485

Closed
nabfrew opened this issue Mar 24, 2022 · 3 comments · Fixed by #63325
Closed

Alpha 5 regression: Custom class typed array is broken. #59485

nabfrew opened this issue Mar 24, 2022 · 3 comments · Fixed by #63325

Comments

@nabfrew
Copy link
Contributor

nabfrew commented Mar 24, 2022

Godot version

v4.0.alpha5.official [d7d528c]

System information

Windows 10

Issue description

When a function returning Array[CustomClass] to a variable expecting Array[CustomClass], the following error occurs:

'Trying to return a typed array with an array of different type.'

E 0:00:00:0829   _ready: Assignment of arrays of incompatible types.
  <C++ Error>    Method/function failed. Returning: false
  <C++ Source>   core/variant/array.cpp:221 @ _assign()
  <Stack Trace>  Node2D.gd:13 @ func_that_returns_custom_array()
                 Node2D.gd:6 @ _ready()

This worked fine on alpha 4. If you push past the breakpoint at the error, nothing is assigned to the variable.

Steps to reproduce

extends Node2D

func _ready() -> void:
	var int_array : Array[int] = func_that_returns_int_array()
	print(int_array)
	var custom_array : Array[CustomClass] = func_that_returns_custom_array()
	print(custom_array[0].number)
	
func func_that_returns_int_array() -> Array[int]:
	return [0, 1, 2]
	
func func_that_returns_custom_array() -> Array[CustomClass]:
	return [CustomClass.new(3), CustomClass.new(4), CustomClass.new(5)]

with a custom class, e.g.:

extends Node

class_name CustomClass

var number : int

func _init(n : int) -> void:
	number = n

Minimal reproduction project

CustomTypedArrayBug.zip

@Calinou Calinou added this to the 4.0 milestone Mar 24, 2022
@nabfrew
Copy link
Contributor Author

nabfrew commented Apr 6, 2022

Don't know what changed, but this is fixed in Alpha 6.

@nabfrew nabfrew closed this as completed Apr 6, 2022
@nabfrew nabfrew reopened this Apr 6, 2022
@nabfrew
Copy link
Contributor Author

nabfrew commented Apr 6, 2022

Sorry, my mistake, it wasn't fixed, I just opened the wrong version of the reproduction project with bits commented out.

@nabfrew
Copy link
Contributor Author

nabfrew commented Apr 6, 2022

Two findings on further inspecting the bug:

  • The error is caused by the hint in the function return type, has nothing to do with the variable the function's return value is assigned to. i.e. func return_array() -> Array[CustomClass]: causes error, func return_array(): does not.
  • if you create an array of a custom type, custom_array, it's a String array according to typeof(custom_array)...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants