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

Generated code contains arity mark when implementing interface in reference assembly #1133

Open
jingliancui opened this issue Jul 22, 2023 · 3 comments
Labels
bug Component does not function as intended generator Issues binding a Java library (generator, class-parse, etc.)

Comments

@jingliancui
Copy link

Android application type

.NET Android (net7.0-android, etc.)

Affected platform version

VSMac 17.6.1 (build 452)

Description

error CS1056: Unexpected character '`'

If click the error to redirect to the generated cs code.
We can find that code is generated:

(global::System.Collections.Generic.IList`1?)

log is here
buildlog.txt

Steps to Reproduce

1.download the aar file from here
2.add aar to this project,ReactAndroidBinding.zip
3.open the sln file using vs Mac
4.build the project
5.error occur

Did you find any workaround?

No

Relevant log output

No response

@jpobst
Copy link
Contributor

jpobst commented Jul 24, 2023

Because this is in the generated invoker type, we can't use any of our usual metadata tricks to fix this. 😞

I think the only thing that can be done to get this to bind will be to remove the ICookieJarContainer type:

<remove-node path="/api/package[@name='com.facebook.react.modules.network']/interface[@name='CookieJarContainer']" />

It might also work to just remove the implemented interface from CookieJarContainer:

<remove-node path="/api/package[@name='com.facebook.react.modules.network']/interface[@name='CookieJarContainer']/implements" />

@jpobst jpobst transferred this issue from xamarin/xamarin-android Jul 24, 2023
@jpobst jpobst added bug Component does not function as intended generator Issues binding a Java library (generator, class-parse, etc.) labels Jul 24, 2023
@jpobst
Copy link
Contributor

jpobst commented Jul 24, 2023

Notes for future me:

Method:

// okhttp3.CookieJar (okhttp3 binding)
[Register("saveFromResponse", "(Lokhttp3/HttpUrl;Ljava/util/List;)V", "GetSaveFromResponse_Lokhttp3_HttpUrl_Ljava_util_List_Handler:Square.OkHttp3.ICookieJarInvoker, Square.OkHttp3")]
void SaveFromResponse(HttpUrl url, IList<Cookie> cookies);

// User library
public interface CookieJarContainer extends CookieJar { ... }

The method is correctly imported with parameter IList<Cookie> by CecilApiImporter.

However, later the Parameter.Validate method sets the sym to a GenericInstance. The type is correct, however when we output it using Parameter.Type it returns global::System.Collections.Generic.IList'1 instead of the correct global::System.Collections.Generic.IList<global::Square.OkHttp3.Cookie>.

The correct fix is probably to override GenericSymbol.FullName to output GenericType.StripArity (), however this a broad fix in code that isn't very well understood. Thus it may have unintended consequences.

It may be worth trying to find a more targeted "hack" fix instead.

@jpobst jpobst changed the title Compiler generates a type with error character that binding project could not be compiled Generated code contains arity mark when implementing interface in reference assembly Jul 24, 2023
@jingliancui
Copy link
Author

Because this is in the generated invoker type, we can't use any of our usual metadata tricks to fix this. 😞

I think the only thing that can be done to get this to bind will be to remove the ICookieJarContainer type:

<remove-node path="/api/package[@name='com.facebook.react.modules.network']/interface[@name='CookieJarContainer']" />

It might also work to just remove the implemented interface from CookieJarContainer:

<remove-node path="/api/package[@name='com.facebook.react.modules.network']/interface[@name='CookieJarContainer']/implements" />

Thanks, let me check later. I just worried about there are some people will need to invoke the methods which are removed in binding phase.

@jpobst jpobst removed their assignment Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Component does not function as intended generator Issues binding a Java library (generator, class-parse, etc.)
Projects
None yet
Development

No branches or pull requests

2 participants