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

Can not call overloaded array methods #74

Open
marschall opened this issue Oct 17, 2019 · 5 comments
Open

Can not call overloaded array methods #74

marschall opened this issue Oct 17, 2019 · 5 comments
Labels

Comments

@marschall
Copy link

marschall commented Oct 17, 2019

java.util.Arrays#oString is overloaded for every array type, I would like to call java.util.Arrays#oString(byte[]) but this fails with

'com.oracle.truffle.api.interop.UnsupportedTypeException: Multiple applicable overloads found for method name toString (candidates: [Method[public static java.lang.String java.util.Arrays.toString(boolean[])], Method[public static java.lang.String java.util.Arrays.toString(byte[])], Method[public static java.lang.String java.util.Arrays.toString(float[])], Method[public static java.lang.String java.util.Arrays.toString(double[])], Method[public static java.lang.String java.util.Arrays.toString(long[])], Method[public static java.lang.String java.util.Arrays.toString(int[])], Method[public static java.lang.String java.util.Arrays.toString(short[])], Method[public static java.lang.String java.util.Arrays.toString(char[])], Method[public static java.lang.String java.util.Arrays.toString(java.lang.Object[])]], arguments: [byte[4] (NativeObject)])'

reproducer

self assert: ((Java type: 'java.util.Arrays') toString: #[127 0 0 1]) = '[127, 0, 0, 1]'

That is with 1.0.0-rc2, I did not check with 1.0.0-rc3

@fniephaus
Copy link
Member

Same error occurs in Graal.js:

$ polyglot --jvm --shell
GraalVM MultiLanguage Shell 19.2.1
  JavaScript version 19.2.1
js> Java.type('java.util.Arrays').toString([1,2,3,4])
TypeError: invokeMember (toString) on JavaClass[java.util.Arrays] failed due to: Multiple applicable overloads found for method name toString (candidates: [Method[public static java.lang.String java.util.Arrays.toString(boolean[])], Method[public static java.lang.String java.util.Arrays.toString(byte[])], Method[public static java.lang.String java.util.Arrays.toString(float[])], Method[public static java.lang.String java.util.Arrays.toString(double[])], Method[public static java.lang.String java.util.Arrays.toString(long[])], Method[public static java.lang.String java.util.Arrays.toString(int[])], Method[public static java.lang.String java.util.Arrays.toString(short[])], Method[public static java.lang.String java.util.Arrays.toString(char[])], Method[public static java.lang.String java.util.Arrays.toString(java.lang.Object[])]], arguments: [DynamicObject<JSArray>@29215f06 (DynamicObjectBasic)])

Still investigating ...

@marschall
Copy link
Author

Same error occurs in Graal.js:

...

Still investigating ...

I'm not sure that can be compared. JavaScript doesn't really have arrays let alone byte arrays. So I can understand that no method can be selected. Squeak on the other hand has ByteArray, DoubleByteArray, FloatArray, IntegerArray and ShortIntegerArray classes.

@fniephaus
Copy link
Member

Javascript does support typed arrays (e.g. Uint8Array). However, it looks like interop only checks if an array has elements and does not consider it's type at all. I'll file a bug against Truffle.

@fniephaus
Copy link
Member

I've opened oracle/graal#1759.

@fniephaus
Copy link
Member

Maybe this could be helpful:

Added support for explicitly selecting a host method overload using the signature in the form of comma-separated fully qualified parameter type names enclosed by parentheses (e.g. methodName(f.q.TypeName,java.lang.String,int,int[])).

See 21.0.0 release notes.

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

No branches or pull requests

2 participants