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

Cannot override functions with narrowing return type. #69075

Closed
RoniPerson opened this issue Nov 23, 2022 · 3 comments
Closed

Cannot override functions with narrowing return type. #69075

RoniPerson opened this issue Nov 23, 2022 · 3 comments

Comments

@RoniPerson
Copy link
Contributor

Godot version

4.0.beta6

System information

Windows 10

Issue description

When overriding a method of a class it is not possible to change the return type even if the new return type is a valid subtype of the original.

Steps to reproduce

a.gd

extends Object

func foo() -> Node:
    return Node.new()

b.gd

extends "a.gd"

func foo() -> Node2D: # The function signature doesn't match the parent. Parent signature is "Node foo()".
    return Node2D.new()

Minimal reproduction project

override_bug.zip

@Mickeon
Copy link
Contributor

Mickeon commented Nov 24, 2022

I wonder, how does this work in other languages?

@RoniPerson
Copy link
Contributor Author

It works in Dart.

I also tested it in Python and TypeScript and it works in both but they would also allow me to return a not compatible type (e.g. String) from the overriden method which seems questionable to me.

@RoniPerson
Copy link
Contributor Author

Completed per #82477

@AThousandShips AThousandShips added this to the 4.2 milestone Nov 30, 2023
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

4 participants