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

GDScript 2.0: Coroutines cannot return statically typed subclass into a statically typed variable #68561

Closed
atirut-w opened this issue Nov 12, 2022 · 5 comments · Fixed by #68374

Comments

@atirut-w
Copy link
Contributor

atirut-w commented Nov 12, 2022

Godot version

v4.0.beta4.official [e675154]

System information

N/A

Issue description

Conditions for this to happen

  • Static typing is used and
  • The coroutine returns a custom subclass

Custom class for testing:

class_name Foo
extends RefCounted


var bar: String


func _init(str: String):
	bar = str

Testing script:

extends Node


func get_foo() -> Foo:
	await get_tree().process_frame
	return Foo.new("bar")


func _ready():
	var foo := await get_foo() as Foo
	breakpoint

If we try to run the coroutine by doing var foo := await get_foo() as Foo, we get the expected Foo object with the initialized variable:
Screenshot_20221112_204206

However, if we make Foo a subclass of another class...

class FooSub:
	var bar: String
	
	func _init(str: String):
		bar = str

and do this:

extends Node


func get_foo() -> CustomClass.FooSub:
	await get_tree().process_frame
	return CustomClass.FooSub.new("bar")


func _ready():
	var foo := await get_foo() as CustomClass.FooSub
	breakpoint

foo turns into a null, seemingly lost in the process of casting:

Screenshot_20221112_204600

This is a problem for me because I am making a plugin and thus have to avoid making generically named global classes.

Steps to reproduce

See above

Minimal reproduction project

Subclass problems.zip

@adamscott
Copy link
Member

Relates to issue #65953.

@adamscott
Copy link
Member

Though, @atirut-w, as this is a complex example, please add a minimum reproducible project (a MRP) to your issue. This greatly helps the developers to fix the issue, as it creates a testbed.

See https://github.com/godotengine/godot/blob/master/CONTRIBUTING.md#reporting-bugs

@atirut-w
Copy link
Contributor Author

Here's the repro project: Subclass problems.zip

@adamscott
Copy link
Member

Thanks! I suggest to add it to to the issue description, you can edit it.

@adamscott
Copy link
Member

I confirm the issue. Could reproduce on master (c17f17e).
But I'm happy to report that PR #68374 fixes this issue.

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.

4 participants