Skip to content

Code generation for GRPC is incorrect with any google protobuf import for iOS #634

@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): iOS
  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:

syntax = "proto3";

import "google/protobuf/timestamp.proto"; // just add any import from google/protobuf

message SimpleResponse {
  string result = 1;
}
  1. Error description after compilation:
    error: 'equals' overrides nothing. Potential signatures for overriding: fun equals(other: Any?): Boolean

  2. Generated code:

import com.google.protobuf.kotlin.* // problem here
import ...

class SimpleResponseInternal: SimpleResponse.Builder, InternalMessage(fieldsWithPresence = 0) {
   ...
    // here we got com.google.protobuf.kotlin.Any
    override fun equals(other: Any?): Boolean {
        checkRequiredFields()
        if (this === other) return true
        if (other == null || this::class != other::class) return false
        other as SimpleResponseInternal
        other.checkRequiredFields()
        if (this.result != other.result) return false
        return true
    }
  1. Expected generated code:
import com.google.protobuf.kotlin.Timestamp // precision import, not *
...

class SimpleResponseInternal: SimpleResponse.Builder, InternalMessage(fieldsWithPresence = 0) {
    // And now, as expected, we have 'kotlin.Any' here.
    override fun equals(other: Any?): Boolean {
        checkRequiredFields()
        if (this === other) return true
        if (other == null || this::class != other::class) return false
        other as SimpleResponseInternal
        other.checkRequiredFields()
        if (this.result != other.result) return false
        return true
    }

Because we imported 'com.google.protobuf.kotlin.*' in the generated code, we also imported 'com.google.protobuf.kotlin.Any', and this causes a problem: now 'Any' in equals is not 'kotlin.Any', but 'com.google.protobuf.kotlin.Any', and this breaks the override of the equals method.

An interesting observation: the build succeeds on Android, but fails on iOS. I wonder why this is. I would expect the compiler to throw an error on Android as well, which is very strange.

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