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

Overriding static methods has highly inconsistent, context-dependent behavior #77895

Closed
NotDaze opened this issue Jun 6, 2023 · 5 comments
Closed

Comments

@NotDaze
Copy link

NotDaze commented Jun 6, 2023

Godot version

4.1.dev4, 4.0.3, 3.5.2, and everything in between, probably more

System information

Windows 11

Issue description

This is best explained with an example:

class One:
	
	static func a() -> int:
		return 1;
	static func b() -> int:
		return a();
	static func c() -> int:
		return b();
	
class Two extends One:
	
	static func a() -> int:
		return 2;

func _init():
	
	# 2 = override succeeded, 1 = override failed
	print(Two.a()); # 2
	print(Two.b()); # 1
	print(Two.c()); # 1
	
	print(Two.new().a()); # 2
	print(Two.new().b()); # 2
	print(Two.new().c()); # 1 (!!)

This behavior is inconsistent and illogical:

  1. We see different behavior when called from an instance vs the class.
  2. Two.new().b() correctly calls Two.new().a(), but Two.new().c() doesn't correctly call Two.new().b() and somehow ends up circling back to One.a(). Very, very strange.

Closely related to #72973, but builds on it substantially

Steps to reproduce

Use the example code above

Minimal reproduction project

N/A, the script above can be used to easily reproduce the issue

@akien-mga akien-mga changed the title Overriding static methods has highly inconsistent, context-dependent behavior [All Versions] Overriding static methods has highly inconsistent, context-dependent behavior Jun 6, 2023
@AThousandShips
Copy link
Member

The behavior on instances should be corrected, but by "override failed" do you mean that you consider it incorrect? As I see it the first range of results should be matched in the second, as that is in my opinion the correct way to treat static methods

@NotDaze
Copy link
Author

NotDaze commented Jun 8, 2023

Somewhere in between. I was using language borrowed from #72973 rather than trying to express an opinion. On the other hand, that bug report disagreed with you.

My opinion isn't very informed, but personally I would prefer if overriding static methods worked the same way as overriding other methods. That just strikes me as more intuitive. I know other languages work differently, though, and again my opinion isn't worth much.

@AThousandShips
Copy link
Member

AThousandShips commented Jun 8, 2023

Disagrees how?

I'm not sure if this can be called a 100% bug. The expected behavior is not documented anywhere.

And as I said, I was just stating my opinion, and there's currently no officially "right" way, and I just wanted to clarify as your report was unclear

I would argue that the first results follows the principle of least astonishment the most, and matches the immediate assumptions of "static", but it's a matter of interpretation

@NotDaze
Copy link
Author

NotDaze commented Jun 8, 2023

Disagrees how?

I meant that the earlier bug report (not any comments on it) probably used that language because it considered the "override failed" behavior a bug. I didn't intend for this report to have the same connotation (even though it does represent my stance).

@AThousandShips
Copy link
Member

Thank you for reporting, consolidating in:

See there for more details, if you think something was missed about this and it's not the same issue, please comment here and it can be reopened

@AThousandShips AThousandShips closed this as not planned Won't fix, can't repro, duplicate, stale Jun 4, 2024
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

3 participants