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

[c#] Generated code for non-alphanumeric enum names is invalid #19134

Open
saquibmian opened this issue Nov 5, 2024 · 1 comment
Open

[c#] Generated code for non-alphanumeric enum names is invalid #19134

saquibmian opened this issue Nov 5, 2024 · 1 comment
Labels

Comments

@saquibmian
Copy link

What version of protobuf and what language are you using?
Version: v28.3
Language: C#

What operating system (Linux, Windows, ...) and version?
macOS

What runtime / compiler are you using (e.g., python version or gcc version)
protoc

What did you do?
Steps to reproduce the behavior:

  1. Write foo.proto with the following content.
    syntax = "proto3";
    
    package foo.v1;
    
    enum Foo {
      _ = 0;
    }
  2. Run protoc -I . --csharp_out=. foo.proto

What did you expect to see
Foo.cs should contain the following definition:

public enum Foo {
  [pbr::OriginalName("_")]  _ = 0,
}

What did you see instead?
Foo.cs contains the following definition, which does not compile (missing enum name):

public enum Foo {
  [pbr::OriginalName("_")]  = 0,
}

Anything else we should know about your project / environment
Nothing else.

@saquibmian saquibmian added the untriaged auto added to all issues by default when created. label Nov 5, 2024
@jskeet jskeet added c# and removed untriaged auto added to all issues by default when created. labels Nov 5, 2024
@jskeet
Copy link
Contributor

jskeet commented Nov 5, 2024

I agree we shouldn't generate invalid code. Whether just _ is the right name to generate is up for discussion, given that _ has a "somewhat" special meaning in C#. (For an enum value that make be okay - for a field it could be pretty confusing. It's worth thinking about how it might be used in all contexts rather than just enums.)

I think it's unlikely that we're going to get to this corner case any time soon - but if you have the time to create a PR to change the C# generator code to fix this, I'd happily review it.

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

No branches or pull requests

2 participants