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

Wrong number of constructor arguments for empty message inside oneof #228

Open
Lupus opened this issue Jan 12, 2024 · 0 comments
Open

Wrong number of constructor arguments for empty message inside oneof #228

Lupus opened this issue Jan 12, 2024 · 0 comments
Labels

Comments

@Lupus
Copy link
Contributor

Lupus commented Jan 12, 2024

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
@c-cube c-cube added the bug label Feb 6, 2024
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