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

JavaScript name hashCode is generated for different inherited members [Kotlin Multiplatform] [JS] #2948

Open
xit0c opened this issue May 17, 2024 · 2 comments

Comments

@xit0c
Copy link

xit0c commented May 17, 2024

In a Kotlin Multiplatform project that targets JS, a Wire generated class shows this error in its constructor: JavaScript name hashCode is generated for different inherited members: var hashCode: Int and fun hashCode(): Int.

image

Setting buildersOnly = true in the plugin configuration (as shown in Wire's js sample) still gives the same error.

Fortunately, the build is not broken by that error and the class can still be used without problems, but since I noticed it I thought it was worth reporting it.

Maybe this is a duplicate of #1424, but that issue doesn't have any progress and it is inactive since 2020.

Reproduction Steps

  • Create a new Kotlin Multiplatform project with the Android Studio "New project..." wizard
  • Add js as one of the targets
  • Add wire gradle plugin and wire-runtime dependency and add the wire configuration block in the build.gradle.kts file
  • Create a simple .proto file in commonMain/proto, mine is:
    syntax = "proto2";
    
    message Position {
      required float x = 1;
      required float y = 2;
    }
  • Run the build and check the generated class
  • NOTE: if the error doesn't show up, go to "File -> Invalidate Caches...", check all the checkboxes and press "Invalidate and Restart", then resync and rebuild the project

Environment

IDE: Android Studio Jellyfish | 2023.3.1
Kotlin Version: 1.9.24
Wire Version: both 4.9.9 and 5.0.0-alpha01 (I didn't test older versions)

@oldergod
Copy link
Member

What's your idea for a fix?

@xit0c
Copy link
Author

xit0c commented May 17, 2024

I don't know wire's internals but it seems it's happening because of a conflict with Message's hashcode property.

I see that in the js implementation @JsName is used to override its name, so maybe it's the annotation that is not working. Any thoughts on that?

A possible solution could be to rename that property to something like internalHashcode (or cachedHashCode as in the annotation) and at that point the error should be gone and the annotation won't even be needed anymore. But again, since I don't know wire's internals and therefore the implications this little refactor could have, maybe this solution isn't feasible.

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

No branches or pull requests

2 participants