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

Fantomas 2.9.1 breaks code generation #84

Closed
vchekan opened this issue Dec 10, 2018 · 3 comments
Closed

Fantomas 2.9.1 breaks code generation #84

vchekan opened this issue Dec 10, 2018 · 3 comments

Comments

@vchekan
Copy link
Contributor

vchekan commented Dec 10, 2018

Describe the bug
cc @7sharp9 I am quite sure Fantomas is the culprit, but would like a confirmation from you to make sure there is no stalled package caching issue on my end.

Fantomas has no version constraint and has been locked in my branch to 2.9.1 instead of 2.9 as in master branch. It seems, such change breaks binary code generation. All alignments are off.

To Reproduce
Update paket.dependencies to nuget Fantomas == 2.9.1, do paket update and make sure that paked.lock has been updated fantomas.
Regenerate simplest schema with both json and binary serializers:

syntax = "proto3";

message ItemLevelOrderHistory {
  string client_id = 1;
  string retail_sku_id = 2;
  double category_id = 3;
  string brand = 4;
  string product = 5;
  float order_tss = 6;
}

Observe misaligned and non-compilable fs code (see at the end of the file):

namespace rec amnesiac

open System
open System.Collections.Generic
open Froto.Serialization
open Falanx.Proto.Codec.Binary
open Falanx.Proto.Codec.Binary.Primitives
open Newtonsoft.Json.Linq
open Fleece.Newtonsoft

[<CLIMutable>]
type ItemLevelOrderHistory =
    { mutable clientId : string option
      mutable retailSkuId : string option
      mutable categoryId : float option
      mutable brand : string option
      mutable product : string option
      mutable orderTss : float32 option }

    static member JsonObjCodec =
        fun clientId retailSkuId categoryId brand product orderTss ->
            { clientId = clientId
              retailSkuId = retailSkuId
              categoryId = categoryId
              brand = brand
              product = product
              orderTss = orderTss } : ItemLevelOrderHistory
        |> fun f ->
            Fleece.Newtonsoft.withFields<Option<String> -> Option<String> -> Option<Double> -> Option<String> -> Option<String> -> Option<Single> -> ItemLevelOrderHistory, IReadOnlyDictionary<String, JToken>, String, ItemLevelOrderHistory, String, JToken>
                (f)
        |> fun codec ->
            let decode =
                let _bind_f51abf1077e6456fb4a02f1268668e44, _ = codec in _bind_f51abf1077e6456fb4a02f1268668e44

            let encode =
                let _, _bind_f2bf7da83028415d8f61ab20ed413d52 = codec in _bind_f2bf7da83028415d8f61ab20ed413d52

            Fleece.Newtonsoft.jfieldOpt<ItemLevelOrderHistory, String, Option<String> -> Option<Double> -> Option<String> -> Option<String> -> Option<Single> -> ItemLevelOrderHistory>
                ("clientId") (fun x -> x.clientId) (decode, encode)
        |> fun codec ->
            let decode =
                let _bind_64c47fa0947d41c69a029cf384b7735d, _ = codec in _bind_64c47fa0947d41c69a029cf384b7735d

            let encode =
                let _, _bind_2e85977edcc6489d865d26ec19597bf5 = codec in _bind_2e85977edcc6489d865d26ec19597bf5

            Fleece.Newtonsoft.jfieldOpt<ItemLevelOrderHistory, String, Option<Double> -> Option<String> -> Option<String> -> Option<Single> -> ItemLevelOrderHistory>
                ("retailSkuId") (fun x -> x.retailSkuId) (decode, encode)
        |> fun codec ->
            let decode =
                let _bind_6894c9159daf4018a31a90c9833a8405, _ = codec in _bind_6894c9159daf4018a31a90c9833a8405

            let encode =
                let _, _bind_238da84697cd48cf86466368de0f4600 = codec in _bind_238da84697cd48cf86466368de0f4600

            Fleece.Newtonsoft.jfieldOpt<ItemLevelOrderHistory, Double, Option<String> -> Option<String> -> Option<Single> -> ItemLevelOrderHistory>
                ("categoryId") (fun x -> x.categoryId) (decode, encode)
        |> fun codec ->
            let decode =
                let _bind_74ddc87304bc4e8489d78066f700a51f, _ = codec in _bind_74ddc87304bc4e8489d78066f700a51f

            let encode =
                let _, _bind_ee3a6a24482d429cb3bf441b6ddc632a = codec in _bind_ee3a6a24482d429cb3bf441b6ddc632a

            Fleece.Newtonsoft.jfieldOpt<ItemLevelOrderHistory, String, Option<String> -> Option<Single> -> ItemLevelOrderHistory>
                ("brand") (fun x -> x.brand) (decode, encode)
        |> fun codec ->
            let decode =
                let _bind_77e6ee5133564ebb8e46ba8b43910660, _ = codec in _bind_77e6ee5133564ebb8e46ba8b43910660

            let encode =
                let _, _bind_dea5f0fa500a4123b7af3af31cf39176 = codec in _bind_dea5f0fa500a4123b7af3af31cf39176

            Fleece.Newtonsoft.jfieldOpt<ItemLevelOrderHistory, String, Option<Single> -> ItemLevelOrderHistory>
                ("product") (fun x -> x.product) (decode, encode)
        |> fun codec ->
            let decode =
                let _bind_4f0417a92ab14c8ca420979d5204e65a, _ = codec in _bind_4f0417a92ab14c8ca420979d5204e65a

            let encode =
                let _, _bind_b5af5897c4004ea780dcea10e1cf8438 = codec in _bind_b5af5897c4004ea780dcea10e1cf8438

            Fleece.Newtonsoft.jfieldOpt<ItemLevelOrderHistory, Single, ItemLevelOrderHistory> ("orderTss")
                (fun x -> x.orderTss) (decode, encode)

    static member Serialize(m : ItemLevelOrderHistory, buffer : ZeroCopyBuffer) =
        Primitives.writeOption<String> (Primitives.writeString) (1) (buffer) (m.clientId)
        Primitives.writeOption<String> (Primitives.writeString) (2) (buffer) (m.retailSkuId)
        Primitives.writeOption<Double> (Primitives.writeDouble) (3) (buffer) (m.categoryId)
        Primitives.writeOption<String> (Primitives.writeString) (4) (buffer) (m.brand)
        Primitives.writeOption<String> (Primitives.writeString) (5) (buffer) (m.product)
        Primitives.writeOption<Single> (Primitives.writeFloat) (6) (buffer) (m.orderTss)

    static member Deserialize(buffer : ZeroCopyBuffer) = Primitives.deserialize<ItemLevelOrderHistory> (buffer)
    interface IMessage with
        member x.Serialize(buffer : ZeroCopyBuffer) = ItemLevelOrderHistory.Serialize(x, buffer)

        member x.ReadFrom(buffer : ZeroCopyBuffer) =
            let enumerator : IEnumerator<Froto.Serialization.Encoding.RawField> =
                ZeroCopyBuffer.allFields(buffer).GetEnumerator() in while enumerator.MoveNext() do
                                                                        let current : Froto.Serialization.Encoding.RawField =
                                                                            enumerator.Current in if current.FieldNum = 6 then
                                                                                                      x.orderTss <- (Some
                                                                                                                         (Primitives.readFloat
                                                                                                                              current) : Option<Single>)
                                                                                                  else if current.FieldNum = 5 then
                                                                                                      x.product <- (Some
                                                                                                                        (Primitives.readString
                                                                                                                             current) : Option<String>)
                                                                                                  else if current.FieldNum = 4 then
                                                                                                      x.brand <- (Some
                                                                                                                      (Primitives.readString
                                                                                                                           current) : Option<String>)
                                                                                                  else if current.FieldNum = 3 then
                                                                                                      x.categoryId <- (Some
                                                                                                                           (Primitives.readDouble
                                                                                                                                current) : Option<Double>)
                                                                                                  else if current.FieldNum = 2 then
                                                                                                      x.retailSkuId <- (Some
                                                                                                                            (Primitives.readString
                                                                                                                                 current) : Option<String>)
                                                                                                  else if current.FieldNum = 1 then
                                                                                                      x.clientId <- (Some
                                                                                                                         (Primitives.readString
                                                                                                                              current) : Option<String>)
                                                                                                  else ()
                                                                    enumerator.Dispose()

        member x.SerializedLength() = Primitives.serializedLength<ItemLevelOrderHistory> (x)
@7sharp9
Copy link
Contributor

7sharp9 commented Jan 2, 2019

Looks dormant in Fantomas, Im guessing this will only be fixed if we do it ourselves.

@7sharp9
Copy link
Contributor

7sharp9 commented Jan 21, 2019

I think I saw this may be fixed now with latest fantomas, just needs testing.

@7sharp9
Copy link
Contributor

7sharp9 commented Feb 4, 2019

2.9.2 fixed this, closing

@7sharp9 7sharp9 closed this as completed Feb 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants