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

Method name clashes #50

Open
Simn opened this issue Apr 15, 2019 · 2 comments
Open

Method name clashes #50

Simn opened this issue Apr 15, 2019 · 2 comments

Comments

@Simn
Copy link
Owner

Simn commented Apr 15, 2019

Since all classes implicitly inherit from java.lang.Object at run-time, we have to deal with name clashes. The following methods are final and have to be escaped:

  • Class<?> getClass()
  • void notify()
  • void notifyAll()
  • void wait(long timeout)
  • void wait(long timeout, int nanos)
  • void wait()

Note that the signature is relevant and we only have to escape if a method matches in both name and signature.

The following methods are not final and might be overridden:

  • int hashCode()
  • boolean equals(Object obj)
  • Object clone()
  • String toString()
  • void finalize()

The question here is what we want to do with those. We can treat toString as a separate case because it's defined in Haxe with the same semantics, so we always want to allow overriding it in classes. For the others, there are two options:

  1. Escape by default, allow to not-escape (and thus override) with metadata.
  2. Don't escape (and thus override) by default, allow to to escape with metadata.

Not sure which option is better. From a pragmatic point of view I'm leaning towards 2.


As for how to handle the escaping, I propose that we prefix with _hx_ and make sure reflection respects that. This should be a matter of stripping a leading _hx_ in some places, and adding it in some others. That's pretty annoying, but I don't think we can avoid it.

@Simn Simn mentioned this issue Apr 15, 2019
@Simn
Copy link
Owner Author

Simn commented Apr 15, 2019

We also have to escape some enum parameter fields in addition to the java.lang.Object ones:

  • String name()
  • int ordinal()
  • String toString()
  • int compareTo(E o)
  • Class<E> getDeclaringClass()

This should not require any reflection adjustments because there is no API to interact with enum parameters by-name.

@Simn
Copy link
Owner Author

Simn commented Mar 7, 2020

I've learned that it's ok to have a field and method with the same name, so there's no problem with enums.

The original problem remains and is very easy to reproduce:

class Main {
	static function main() {
		new Main().wait();
	}

	function new() {}

	function wait() {}
}
Error: LinkageError occurred while loading main class haxe.root.Main
        java.lang.VerifyError: class haxe.root.Main overrides final method java.lang.Object.wait()V
Error: Command failed with error 1

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

No branches or pull requests

1 participant