cjyyyza / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
0 stars 0 forks source link

Protogen Generates Odd Code With Protobuf Extensions #414

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Please include an e-mail address if this might need a dialogue!
==============

--What steps will reproduce the problem?
1. Compile Failure.proto using protoc (protoc -o Failure.protocomp 
Failure.proto)
2. Generate C# source using protogen.exe (mono protogen.exe 
-i:Failure.protocomp -o:Failure.cs
3. Try to compile Failure.cs with mcs (mcs -r:protobuf-net.dll Failure.cs)

--What is the expected output? What do you see instead?
Failure.proto is a perfectly kosher protobuf definition, so I would expect the 
C# source to compile cleanly. Instead, I get the following error:

Failure.cs(25,25): error CS0102: The type `Failure.Foo' already contains a 
definition for `_message'
Failure.cs(18,25): (Location of the symbol related to previous error)
Failure.cs(27,24): error CS0102: The type `Failure.Foo' already contains a 
definition for `message'
Failure.cs(20,24): (Location of the symbol related to previous error)
Compilation failed: 2 error(s), 0 warnings

As you can see from Failure.cs, it has the following problematic code:

    private Failure.Bar _message;
    [global::ProtoBuf.ProtoMember(100, IsRequired = true, Name=@"message", DataFormat = global::ProtoBuf.DataFormat.Default)]
    public Failure.Bar message
    {
      get { return _message; }
      set { _message = value; }
    }
    private Failure.Baz _message;
    [global::ProtoBuf.ProtoMember(101, IsRequired = true, Name=@"message", DataFormat = global::ProtoBuf.DataFormat.Default)]
    public Failure.Baz message
    {
      get { return _message; }
      set { _message = value; }
    }

Interestingly enough, if you perform the same steps but use Success.proto, the 
output compiles just fine and works as I would expect it. The only difference 
is that the Success.proto definition does not contain a `package` line in it. 
The diff between the resulting C# source is:

10,11c10,11
< // Generated from: Failure.proto
< namespace Failure

---
> // Generated from: Success.proto
> namespace Success
18,31d17
<     private Failure.Bar _message;
<     [global::ProtoBuf.ProtoMember(100, IsRequired = true, Name=@"message", 
DataFormat = global::ProtoBuf.DataFormat.Default)]
<     public Failure.Bar message
<     {
<       get { return _message; }
<       set { _message = value; }
<     }
<     private Failure.Baz _message;
<     [global::ProtoBuf.ProtoMember(101, IsRequired = true, Name=@"message", 
DataFormat = global::ProtoBuf.DataFormat.Default)]
<     public Failure.Baz message
<     {
<       get { return _message; }
<       set { _message = value; }
<     }

--What version of the product are you using? On what operating system?

I am using protobuf-net r668, protoc 2.4.1, Mono 3.0.6 on OS X 10.9.

Original issue reported on code.google.com by turing.e...@gmail.com on 7 Nov 2013 at 6:59

Attachments: