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

static type arrya cannot understand extends(subclass) #93063

Closed
AkiYama-Ryou opened this issue Jun 11, 2024 · 2 comments
Closed

static type arrya cannot understand extends(subclass) #93063

AkiYama-Ryou opened this issue Jun 11, 2024 · 2 comments

Comments

@AkiYama-Ryou
Copy link

Tested versions

godot 4.2.2 statble

System information

windows 10

Issue description

godot support OOP, so we can extend class :But it seem like gotdot cannot understand class in container

Im not sure is this a feature?

Steps to reproduce

I have class A and B. Class B extend from A.
var a:A
var b:B
a=b
but this cannot pass:
var a:Array[A]
var b:Array[B]
a=b
error:Value of type "Array[B]" cannot be assigned to a variable of type "Array[A]"

Minimal reproduction project (MRP)

N/A

@dalexeev
Copy link
Member

See:

This is not a bug. Arrays are passed by reference; they do not copy the entire content. Otherwise you would get:

var a: Array[Node2D]
var b: Array[Node]
b = a # Now `b` refers to the same array as `a`.
b.append(Label.new()) # Valid, `Label` is a subtype of `Node`.
print(a[0]) # Invalid, `Label` is **not** a subtype of `Node2D`.

Probably the only way this would work is if the GDScript supported read/write qualifiers. But it's too difficult.

Thanks for the contribution nonetheless!

@dalexeev dalexeev closed this as not planned Won't fix, can't repro, duplicate, stale Jun 12, 2024
@github-project-automation github-project-automation bot moved this from For team assessment to Done in GDScript Issue Triage Jun 12, 2024
@AkiYama-Ryou
Copy link
Author

Thank you for explaining.

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

No branches or pull requests

2 participants