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

Problem when the name of a 'oneof' field matches the name of the message. #4

Open
blue-hope opened this issue Apr 27, 2023 · 1 comment
Labels
bug Something isn't working discussion open for discussion

Comments

@blue-hope
Copy link

Simple Example:

message Content {
  oneof Content {
    string text = 1;
  }
}

is converted into

@KrotoDC(forProto = a.b.c.Content::class)
public data class Content(
    public val Content: Content? = null,
) {
    public sealed interface Content {
        public data class Text(
            public val text: String = "",
        ) : Content
    }
}

occurs kotlin compile error.

This could be a minor issue because typically, the name of the 'oneof' field is not the same as the message's field.
However, it may not be a forbidden action, so it requires support.

@mscheong01 mscheong01 added bug Something isn't working discussion open for discussion labels Apr 28, 2023
@mscheong01
Copy link
Owner

mscheong01 commented Apr 28, 2023

This wasn't considered during the initial development 😓 It seems that it will also occur when any two of message name/ oneof name/ oneof included field name has the same value. One solution would be to add suffixes to the oneof sealed interface / data class names like:

@KrotoDC(forProto = a.b.c.Content::class)
public data class Content(
    public val Content: ContentOneof? = null,
) {
    public sealed interface ContentOneof {
        public data class TextField(
            public val text: String = "",
        ) : Content
    }
}

( example with ~Oneof, ~Field suffexes added )
Although this is breaking change. Since naming messages and oneofs (or containing fields) identically seems like an unpopular choice and avoidable, let's try keeping this issue open for a while and see if we could get other opinions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working discussion open for discussion
Projects
None yet
Development

No branches or pull requests

2 participants