Skip to content

Code generation for GRPC for the name "result" is incorrect #633

@epicarchitect

Description

@epicarchitect

To Reproduce
Steps to reproduce the behavior:

  1. Kotlin version: 2.3.20
  2. Gradle version: 9.4.0
  3. kotlinx-rpc version: 0.11.0-grpc-185
  4. OS (Or at least KMP platform): KMP
  5. Minimal reproducer in code:
    Connect org.jetbrains.kotlinx.rpc.plugin and add minimal configuration:
rpc {
    protoc()
}

Add a proto file with the following contents in commonMain/proto:

syntax = "proto3";

message SubmitAuthResponse {
  string submit_result = 1;

  oneof result {
    string finished = 101;
    int64 next_challenge = 102;
  }
}
  1. Error description after compilation:
    Unresolved reference. None of the following candidates is applicable because of a receiver type mismatch:
    fun SubmitAuthResponse.Result.oneOfHashCode(): Int

  2. Generated code:

class SubmitAuthResponseInternal: SubmitAuthResponse.Builder, InternalMessage(fieldsWithPresence = 0) {
 ...
    override var submitResult: String by MsgFieldDelegate { "" }
    override var result: SubmitAuthResponse.Result? = null

    override fun hashCode(): Int {
        checkRequiredFields()
        var result = submitResult.hashCode()
        result = 31 * result + (result?.oneOfHashCode() ?: 0) // error here
        return result
    }
  1. Expected generated code:
class SubmitAuthResponseInternal: SubmitAuthResponse.Builder, InternalMessage(fieldsWithPresence = 0) {
 ...
    override var submitResult: String by MsgFieldDelegate { "" }
    override var result: SubmitAuthResponse.Result? = null

    override fun hashCode(): Int {
        checkRequiredFields()
        var result = submitResult.hashCode()
        result = 31 * result + (this.result?.oneOfHashCode() ?: 0) // used this.result
        return result
    }

In other words, the problem is that the generated code needs to refer to objects more precisely. I think it's worth using this throughout the generated code to avoid such cases.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions