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

use fully qualified name when generating messages #104

Merged
merged 19 commits into from
Dec 28, 2020

Conversation

nbaztec
Copy link
Contributor

@nbaztec nbaztec commented Nov 21, 2020

Fixes #47

For the following protobuf where the oneof field had the same name as message, the companion object definition would shadow the oneof class instead of the message class. This patch fixes it by fully qualifying the message class name.

Input:

syntax = "proto3";
package foobar;

message Value {
    oneof value {
        int32 int_val = 1;
        string str_val = 2;
    }
}

Before:

package foobar

data class Value(
        val value: Value<*>? = null,
        override val unknownFields: Map<Int, pbandk.UnknownField> = emptyMap()
) : pbandk.Message {
       sealed class Value<V>(value: V) : pbandk.Message.OneOf<V>(value) {
              ...
       }
       ...
       companion object : pbandk.Message.Companion<Value> {
              ...
       }
       ...
}

After:

package foobar

data class Value(
        val value: Value<*>? = null,
        override val unknownFields: Map<Int, pbandk.UnknownField> = emptyMap()
) : pbandk.Message {
       sealed class Value<V>(value: V) : pbandk.Message.OneOf<V>(value) {
              ...
       }
       ...
       companion object : pbandk.Message.Companion<foobar.Value> {
              ...
       }
       ...
}

Copy link
Collaborator

@garyp garyp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing this! Sorry for the delay in reviewing your change.

@garyp garyp added the bug Something isn't working label Dec 16, 2020
@garyp garyp added this to the 0.9.1 milestone Dec 16, 2020
@garyp garyp changed the base branch from master to v0.9.x December 26, 2020 01:50
Copy link
Collaborator

@garyp garyp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@garyp garyp merged commit ed017e6 into streem:v0.9.x Dec 28, 2020
garyp added a commit that referenced this pull request Dec 28, 2020
garyp pushed a commit that referenced this pull request Dec 28, 2020
Fixes #47

For the following protobuf where the `oneof` field had the same name as message, the companion object definition would shadow the `oneof` class instead of the `message` class. This patch fixes it by fully qualifying the `message` class name.

**Input:**

```protobuf
syntax = "proto3";
package foobar;

message Value {
    oneof value {
        int32 int_val = 1;
        string str_val = 2;
    }
}
```

**Before:**

```kotlin
package foobar

data class Value(
        val value: Value<*>? = null,
        override val unknownFields: Map<Int, pbandk.UnknownField> = emptyMap()
) : pbandk.Message {
       sealed class Value<V>(value: V) : pbandk.Message.OneOf<V>(value) {
              ...
       }
       ...
       companion object : pbandk.Message.Companion<Value> {
              ...
       }
       ...
}
```

**After:**

```kotlin
package foobar

data class Value(
        val value: Value<*>? = null,
        override val unknownFields: Map<Int, pbandk.UnknownField> = emptyMap()
) : pbandk.Message {
       sealed class Value<V>(value: V) : pbandk.Message.OneOf<V>(value) {
              ...
       }
       ...
       companion object : pbandk.Message.Companion<foobar.Value> {
              ...
       }
       ...
}
```
garyp added a commit that referenced this pull request Dec 28, 2020
@nbaztec nbaztec mentioned this pull request Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compile error when proto contains a oneof field with same name as the enclosing message
2 participants