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: Subclass member with type of another script's subclass does not get assigned correctly #61268

Closed
estroBiologist opened this issue May 22, 2022 · 1 comment · Fixed by #68374

Comments

@estroBiologist
Copy link

Godot version

v4.0.alpha8.official [cc3ed63]

System information

Windows 10

Issue description

(I tried my best with the title, I swear.)

In GDScript 2.0, attempting to assign to a subclass member variable with a type of another script's subclass quietly fails, resulting in a null value instead.

Steps to reproduce

A minimal example project is provided. In addition, here are the steps used to manually reproduce the issue:

  • Create a project in the latest alpha build of Godot 4.0.
  • Create two scripts, AScript.gd and BScript.gd, with these contents, respectively:
# AScript.gd

class_name AScript

class ASubClass:
	var data := 4.0
# BScript.gd

extends Node # Assign this script to the main scene to reproduce

class BSubClass:
	# The type annotation here is what triggers the bug - without it, no problem
	var a := AScript.ASubClass.new()
	
func _ready():
	# Lone ASubClass, works as expected.
	
	var lone_a := AScript.ASubClass.new()
	print(lone_a.data)
	
	# BSubClass.new() initializes correctly, `a` is valid, as is `data`
	
	var b := BSubClass.new()
	print(b.a.data)
	
	# Here's where it gets weird - despite being functionally identical 
	# to line 10, `a` is `null` after this statement
	
	b.a = AScript.ASubClass.new()
	print(b.a)
	# print(b.a.data) 	Error, `a` is null

The console output of this project is:

4
4
null

(Given that removing the type annotation from BSubClass resolves this, it seems like a type checking issue. I've used this to work around the bug in my own project.)

Minimal reproduction project

GDScriptBugTest.zip

@Calinou Calinou added this to the 4.0 milestone May 22, 2022
@rune-scape
Copy link
Contributor

just checked that #68374 fixes this

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.

3 participants