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

Calling super() when base implementation does not exist doesn't give any error until runtime #81804

Closed
KoBeWi opened this issue Sep 17, 2023 · 3 comments · Fixed by #81808
Closed

Comments

@KoBeWi
Copy link
Member

KoBeWi commented Sep 17, 2023

Godot version

4.2 dev4

System information

Windows 10.0.19045 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1060 (NVIDIA; 30.0.15.1403) - Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz (8 Threads)

Issue description

When you override a native virtual function and call super(), you won't see any error until you run the project. This is most prominent when using _ready(). If you have a script that extends another script and use super(), you need to open the base script to know whether the base class already implements _ready() or not. If it doesn't, you'll get runtime error.

Custom script methods properly report if the base doesn't exist, e.g.

func anything():
	super()

Steps to reproduce

  1. Create script extending Node
  2. Create another script extending node
  3. Add _ready() method to the second script only and use super()
  4. No parse error
  5. Run the project
  6. Invalid call. Nonexistent function '_ready'.

Minimal reproduction project

@tool
extends EditorScript

class Class1 extends Node:
	pass

class Class2 extends Class1:
	func _ready() -> void:
		super()

func _run() -> void:
	get_editor_interface().get_edited_scene_root().add_child(Class2.new())
@anvilfolk
Copy link
Contributor

I think I tried to do this with #77324 but it ended up being reverted in #78533 because you simply can't check at compile-time whether an object is going to have a script that implements the function :(

@KoBeWi
Copy link
Member Author

KoBeWi commented Sep 17, 2023

But the base script is known, so not sure what's the problem 🤔
Could it be a warning at least?

@anvilfolk
Copy link
Contributor

Yeah, I think you're right, I think the other PR was doing it in the general case of virtual functions. If we restrict the checking to just super() calls, then we should be able to figure it out I think!

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