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

Overload Constructor with Array type parameter #409

Open
kwek20 opened this issue Jan 19, 2022 · 1 comment
Open

Overload Constructor with Array type parameter #409

kwek20 opened this issue Jan 19, 2022 · 1 comment
Labels
bug Java/JNI Case specific only for Java/JNI interface generation

Comments

@kwek20
Copy link

kwek20 commented Jan 19, 2022

Hey!

Im trying to have 2 constructors in a class;

constructor TransferBuilder::with_outputs(outputs: Vec<TransferOutput>) -> TransferBuilder;
constructor TransferBuilder::new(address: Address, amount: u64) -> TransferBuilder;

Both of these constructors compile and work when I only enable one of the 2. But as soon as I enable both; I get the following error:

error: Can not generate JNI function name for overload method 'init',unknown java type 'TransferOutput[]'
      class TransferBuilder {

I looked at the error origin here:

let type_name = java_type_to_jni_signature(ctx, type_name).ok_or_else(|| {

I tried to take a stab at the code; but couldnt find out how it would handle arrays (Adding escape_underscore around type_name didnt work)

It may be relevant that i use the following typemap to receive a vec on the rust side.

foreign_typemap!(
    ($p:r_type) Vec<TransferOutput> <= internal_aliases::JForeignObjectsArray<TransferOutput> {
        $out = jobject_array_to_vec_of_objects(env, $p);
    };
    ($p:f_type, option = "NoNullAnnotations") <= "TransferOutput[]";
    ($p:f_type, option = "NullAnnotations") <= "@NonNull TransferOutput[]";
);

Could you give me any pointers on how to fix this?

@kwek20 kwek20 changed the title Overload Constructor with Array type Overload Constructor with Array type parameter Jan 19, 2022
@Dushistov Dushistov added bug Java/JNI Case specific only for Java/JNI interface generation enhancement and removed bug labels Jan 20, 2022
@Dushistov
Copy link
Owner

Yes, JNI requires special names for overloading functions.
But this case should be handled properly. See this.
During parsing TransferOutput as foreign_class should be registered signature L[ + class name.
So you need add debugging output around this and failed lines and find out why it can not find L[Class signature.

@Dushistov Dushistov added bug and removed enhancement labels Jan 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Java/JNI Case specific only for Java/JNI interface generation
Projects
None yet
Development

No branches or pull requests

2 participants