Open Simn opened 5 years ago
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.
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
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: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.