alexeyxo / protobuf-swift

Google ProtocolBuffers for Apple Swift
http://protobuf.io/#swift
Apache License 2.0
937 stars 138 forks source link

Oneof can't use property with type of another message? #131

Open Tsarfolk opened 8 years ago

Tsarfolk commented 8 years ago

I have such code in my photo file, i can compile it into swift file and everything ok message Subject { oneof subjects { string maths = 1; string physics = 2; Informatics informatics = 3; } }

message Informatics { enum Themes { CPLUSPLUS = 1; JAVA = 2; PASCAL = 3; BASIC = 4; }

optional Themes theme = 1;

}

But when i added compiled swift file i got 3 errors on Informatics (Use of undeclared type "Informatics"). Had I done smth wrong? protobuf version is 2.6.1

alexeyxo commented 8 years ago

For a temporary solution I can offer - rename OneOf field named "informatics":

message Subject {
    oneof subjects {
        string maths = 1;
        string physics = 2;
        Informatics informaticsField = 3;
    }
}

message Informatics {
    enum Themes {
        CPLUSPLUS = 1;
        JAVA = 2;
        PASCAL = 3;
        BASIC = 4;
    }
    optional Themes theme = 1;
}
Tsarfolk commented 8 years ago

It can be fixed by placing it after // oneOf declaration public typealias inf = (Informatics)

and changing type Informatics to inf But it's a bit harder i think then the solution above