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: no parser error when super() doesn't called in derived class #40861

Open
ThakeeNathees opened this issue Jul 30, 2020 · 3 comments · May be fixed by #85481
Open

GDScript: no parser error when super() doesn't called in derived class #40861

ThakeeNathees opened this issue Jul 30, 2020 · 3 comments · May be fixed by #85481

Comments

@ThakeeNathees
Copy link
Member

ThakeeNathees commented Jul 30, 2020

Godot version: v4.0.dev.custom_build 5ba46dd

OS/device including version: windows 10

Issue description:
it should remind to call super() if base class doesn't have any default constructor

class A:
	func _init(p):
		pass

class B extends A:
	func _init():  <-- no parser error here
		pass
		
@lyuma
Copy link
Contributor

lyuma commented Aug 6, 2021

See also issue #50590

What is supposed to happen if super() is called implicitly, but your superclass (A) takes an argument?
Should this case produce an error?

@dalexeev
Copy link
Member

dalexeev commented Feb 9, 2023

In 4.x, multilevel calls are removed and and constructor syntax is no different from other methods now, so requiring a call to super() looks wrong to me.

As for the exception for constructor, this behavior exists in some other languages as well. For example PHP:

Unlike other methods, __construct() is exempt from the usual signature compatibility rules when being extended.

I'm not sure what the behavior in GDScript should be here. Perhaps this should be a warning, not an error.

For other custom methods, the signature is checked:

class A:
    func test(p):
        pass

class B extends A:
    # Error: The function signature doesn't match the parent. Parent signature is "test(Variant) -> Variant".
    func test():
        pass

@vnen
Copy link
Member

vnen commented Feb 24, 2023

It is indeed a bug, it should raise an error if the super class constructor requires an argument that is not being provided. This can be checked at compile time and should show an error in the editor. I'll try to keep in my shortlist for 4.0 but it's so close I won't really promise it.

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.

8 participants