ocaml-protoc
ocaml-protoc copied to clipboard
Wrong number of constructor arguments for empty message inside oneof
For the below protobuf snippet:
syntax = "proto2";
message Null {}
message A {
optional bool ignored = 1072;
oneof foo {
Null foo_not_set = 99999;
bool bar = 1;
}
}
The generated json encoder function contains an error:
let rec encode_json_a_foo (v:a_foo) =
begin match v with
| Foo_not_set -> `Assoc [("fooNotSet", `Null)]
| Bar v -> `Assoc [("bar", Pbrt_yojson.make_bool v)]
end
and encode_json_a (v:a) =
let assoc = [] in
let assoc = match v.ignored with
| None -> assoc
| Some v -> ("ignored", Pbrt_yojson.make_bool v) :: assoc
in
let assoc = match v.foo with
| Foo_not_set v -> (* Error: The constructor Foo_not_set expects 0 argument(s), but is applied here to 1 argument(s) *)
("fooNotSet", `Null) :: assoc
| Bar v ->
("bar", Pbrt_yojson.make_bool v) :: assoc
in (* match v.foo *)
`Assoc assoc
If I remove optional bool ignored from the message A, the code is generated differently and actually compiles:
let rec encode_json_a (v:a) =
begin match v with
| Foo_not_set -> `Assoc [("fooNotSet", `Null)]
| Bar v -> `Assoc [("bar", Pbrt_yojson.make_bool v)]
end