jet / falanx

Generates F# code from protobuf schema for binary and json format

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A proto file with a normal field follows by a oneOf results in incorrect generated code

7sharp9 opened this issue · comments

Given:

message TestAllTypes {
  // Singular
  int32 single_int32 = 1;

  // For oneof test
   oneof oneof_field {
     uint32 oneof_uint32 = 111;
     //NestedMessage oneof_nested_message = 112;
     string oneof_string = 113;
     //bytes oneof_bytes = 114;
   }
}

This code is generated:

type TestAllTypes =
    { mutable oneofField : TestAllTypes.oneof_field option
      mutable singleInt32 : int option }

    static member JsonObjCodec =
        fun singleInt32 oneofField ->
            { oneofField = singleInt32
              singleInt32 = oneofField } : TestAllTypes
        |> fun f ->
            Fleece.Newtonsoft.withFields<option<Int32> -> option<TestAllTypes.oneof_field> -> TestAllTypes, IReadOnlyDictionary<String, JToken>, Fleece.Newtonsoft.DecodeError, TestAllTypes, String, JToken>
                (f)
        |> fun codec ->
            let decode =
                let _bind_0, _ = codec
                _bind_0

            let encode =
                let _, _bind_1 = codec
                _bind_1

            Fleece.Newtonsoft.jfieldOpt<TestAllTypes, Int32, TestAllTypes> ("singleInt32") (fun x -> x.singleInt32)
                (decode, encode)

Notice the oneofField = singleInt32 in the record creation.

If the oneOf field is first then this does not happen.