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

Single nested enum fails due to no support in fleece #131

Closed
7sharp9 opened this issue Feb 4, 2019 · 11 comments · Fixed by #169
Closed

Single nested enum fails due to no support in fleece #131

7sharp9 opened this issue Feb 4, 2019 · 11 comments · Fixed by #169
Labels
enhancement New feature or request help wanted Extra attention is needed json

Comments

@7sharp9
Copy link
Contributor

7sharp9 commented Feb 4, 2019

  enum NestedEnum {
    NESTED_ENUM_UNSPECIFIED = 0;
    FOO = 1;
    BAR = 2;
    BAZ = 3;
    NEG = -1;  // Intentionally negative.
  }

Results in:

    type NestedEnum =
        | NestedEnumUnspecified = 0
        | Foo = 1
        | Bar = 2
        | Baz = 3
        | Neg = -1

...
type TestAllTypes =
    { mutable singleInt32 : int option
      mutable singleInt64 : int64 option
      mutable singleUint32 : UInt32 option
      mutable singleUint64 : UInt64 option
      mutable singleSint32 : int option
      mutable singleSint64 : int64 option
      mutable singleFixed32 : UInt32 option
      mutable singleFixed64 : UInt64 option
      mutable singleSfixed32 : int option
      mutable singleSfixed64 : int64 option
      mutable singleFloat : float32 option
      mutable singleDouble : float option
      mutable singleBool : bool option
      mutable singleString : string option
      mutable singleBytes : ArraySegment<Byte> option
      mutable singleNestedMessage : TestAllTypes.NestedMessage option
...
            Fleece.Newtonsoft.jfieldOpt<TestAllTypes, TestAllTypes.NestedEnum, option<List<Int32>> -> option<List<Int64>> -> option<List<UInt32>> -> option<List<UInt64>> -> option<List<Int32>> -> option<List<Int64>> -> option<List<UInt32>> -> option<List<UInt64>> -> option<List<Int32>> -> option<List<Int64>> -> option<List<Single>> -> option<List<Double>> -> option<List<Boolean>> -> option<List<String>> -> TestAllTypes>
                ("singleNestedEnum") (fun x -> x.singleNestedEnum) (decode, encode)
0>/Users/dave.thomas/Documents/GitHub/falanx/test/Falanx.Tests/schemas/falanx_test.proto.fs(319,13): Error FS0001 : No overloads match for method 'ToJson'. The available overloads are shown below.
0>Possible overload: 'static member ToJson.ToJson : x:bool * ToJson -> JToken'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'bool'    �.
0>Possible overload: 'static member ToJson.ToJson : x:string * ToJson -> JToken'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'string'    �.
0>Possible overload: 'static member ToJson.ToJson : x:DateTime * ToJson -> JToken'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'DateTime'    �.
0>Possible overload: 'static member ToJson.ToJson : x:DateTimeOffset * ToJson -> JToken'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'DateTimeOffset'    �.
0>Possible overload: 'static member ToJson.ToJson : x:decimal * ToJson -> JToken'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'decimal'    �.
0>Possible overload: 'static member ToJson.ToJson : x:Double * ToJson -> JToken'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'Double'    �.
0>Possible overload: 'static member ToJson.ToJson : x:Single * ToJson -> JToken'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'Single'    �.
0>Possible overload: 'static member ToJson.ToJson : x:int * ToJson -> JToken'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'int'    �.
0>Possible overload: 'static member ToJson.ToJson : x:uint32 * ToJson -> JToken'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'uint32'    �.
0>Possible overload: 'static member ToJson.ToJson : x:int64 * ToJson -> JToken'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'int64'    �.
0>Possible overload: 'static member ToJson.ToJson : x:uint64 * ToJson -> JToken'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'uint64'    �.
0>Possible overload: 'static member ToJson.ToJson : x:int16 * ToJson -> JToken'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'int16'    �.
0>Possible overload: 'static member ToJson.ToJson : x:uint16 * ToJson -> JToken'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'uint16'    �.
0>Possible overload: 'static member ToJson.ToJson : x:byte * ToJson -> JToken'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'byte'    �.
0>Possible overload: 'static member ToJson.ToJson : x:sbyte * ToJson -> JToken'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'sbyte'    �.
0>Possible overload: 'static member ToJson.ToJson : x:char * ToJson -> JToken'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'char'    �.
0>Possible overload: 'static member ToJson.ToJson : x:Guid * ToJson -> JToken'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'Guid'    �.
0>Possible overload: 'static member ToJson.ToJson : unit * ToJson -> JToken'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'unit'    �.
0>Possible overload: 'static member ToJson.ToJson : x:Choice< ^a, ^b> * ToJson -> JToken when (ToJson or  ^a) : (static member ToJson :  ^a * ToJson -> JsonValue) and (ToJson or  ^b) : (static member ToJson :  ^b * ToJson -> JsonValue)'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'Choice<'a,'b>'    �.
0>Possible overload: 'static member ToJson.ToJson : x:Choice< ^a, ^b, ^c> * ToJson -> JToken when (ToJson or  ^a) : (static member ToJson :  ^a * ToJson -> JsonValue) and (ToJson or  ^b) : (static member ToJson :  ^b * ToJson -> JsonValue) and (ToJson or  ^c) : (static member ToJson :  ^c * ToJson -> JsonValue)'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'Choice<'a,'b,'c>'    �.
0>Possible overload: 'static member ToJson.ToJson : x: ^a option * ToJson -> JToken when (ToJson or  ^a) : (static member ToJson :  ^a * ToJson -> JsonValue)'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    ''a option'    �.
0>Possible overload: 'static member ToJson.ToJson : x:Nullable< ^a> * ToJson -> JsonValue when  ^a : (new : unit ->  ^a) and  ^a : struct and  ^a :> ValueType and (ToJson or  ^a) : (static member ToJson :  ^a * ToJson -> JsonValue)'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'Nullable<'a>'    �.
0>Possible overload: 'static member ToJson.ToJson : x: ^a list * ToJson -> JToken when (ToJson or  ^a) : (static member ToJson :  ^a * ToJson -> JsonValue)'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    ''a list'    �.
0>Possible overload: 'static member ToJson.ToJson : x:Set< ^a> * ToJson -> JToken when  ^a : comparison and (ToJson or  ^a) : (static member ToJson :  ^a * ToJson -> JsonValue)'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'Set<'a>'    �.
0>Possible overload: 'static member ToJson.ToJson : x: ^a array * ToJson -> JToken when (ToJson or  ^a) : (static member ToJson :  ^a * ToJson -> JsonValue)'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    ''a array'    �.
0>Possible overload: 'static member ToJson.ToJson : x:ArraySegment< ^a> * ToJson -> JToken when (ToJson or  ^a) : (static member ToJson :  ^a * ToJson -> JsonValue)'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'ArraySegment<'a>'    �.
0>Possible overload: 'static member ToJson.ToJson : x:Map<string, ^a> * ToJson -> JToken when (ToJson or  ^a) : (static member ToJson :  ^a * ToJson -> JsonValue)'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'Map<string,'a>'    �.
0>Possible overload: 'static member ToJson.ToJson : x:Dictionary<string, ^a> * ToJson -> JToken when (ToJson or  ^a) : (static member ToJson :  ^a * ToJson -> JsonValue)'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'Dictionary<string,'a>'    �.
0>Possible overload: 'static member ToJson.ToJson : x:ResizeArray< ^a> * ToJson -> JToken when (ToJson or  ^a) : (static member ToJson :  ^a * ToJson -> JsonValue)'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    'ResizeArray<'a>'    �.
0>Possible overload: 'static member ToJson.ToJson : x:( ^a0 *  ^a1) * ToJson -> JToken when (ToJson or  ^a0) : (static member ToJson :  ^a0 * ToJson -> JsonValue) and (ToJson or  ^a1) : (static member ToJson :  ^a1 * ToJson -> JsonValue)'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    ''a * 'b'    �.
0>Possible overload: 'static member ToJson.ToJson : x:( ^a0 *  ^a1 *  ^a2) * ToJson -> JToken when (ToJson or  ^a0) : (static member ToJson :  ^a0 * ToJson -> JsonValue) and (ToJson or  ^a1) : (static member ToJson :  ^a1 * ToJson -> JsonValue) and (ToJson or  ^a2) : (static member ToJson :  ^a2 * ToJson -> JsonValue)'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    ''a * 'b * 'c'    �.
0>Possible overload: 'static member ToJson.ToJson : x:( ^a0 *  ^a1 *  ^a2 *  ^a3) * ToJson -> JToken when (ToJson or  ^a0) : (static member ToJson :  ^a0 * ToJson -> JsonValue) and (ToJson or  ^a1) : (static member ToJson :  ^a1 * ToJson -> JsonValue) and (ToJson or  ^a2) : (static member ToJson :  ^a2 * ToJson -> JsonValue) and (ToJson or  ^a3) : (static member ToJson :  ^a3 * ToJson -> JsonValue)'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    ''a * 'b * 'c * 'd'    �.
0>Possible overload: 'static member ToJson.ToJson : x:( ^a0 *  ^a1 *  ^a2 *  ^a3 *  ^a4) * ToJson -> JToken when (ToJson or  ^a0) : (static member ToJson :  ^a0 * ToJson -> JsonValue) and (ToJson or  ^a1) : (static member ToJson :  ^a1 * ToJson -> JsonValue) and (ToJson or  ^a2) : (static member ToJson :  ^a2 * ToJson -> JsonValue) and (ToJson or  ^a3) : (static member ToJson :  ^a3 * ToJson -> JsonValue) and (ToJson or  ^a4) : (static member ToJson :  ^a4 * ToJson -> JsonValue)'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    ''a * 'b * 'c * 'd * 'e'    �.
0>Possible overload: 'static member ToJson.ToJson : x:( ^a0 *  ^a1 *  ^a2 *  ^a3 *  ^a4 *  ^a5) * ToJson -> JToken when (ToJson or  ^a0) : (static member ToJson :  ^a0 * ToJson -> JsonValue) and (ToJson or  ^a1) : (static member ToJson :  ^a1 * ToJson -> JsonValue) and (ToJson or  ^a2) : (static member ToJson :  ^a2 * ToJson -> JsonValue) and (ToJson or  ^a3) : (static member ToJson :  ^a3 * ToJson -> JsonValue) and (ToJson or  ^a4) : (static member ToJson :  ^a4 * ToJson -> JsonValue) and (ToJson or  ^a5) : (static member ToJson :  ^a5 * ToJson -> JsonValue)'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    ''a * 'b * 'c * 'd * 'e * 'f'    �.
0>Possible overload: 'static member ToJson.ToJson : x:( ^a0 *  ^a1 *  ^a2 *  ^a3 *  ^a4 *  ^a5 *  ^a6) * ToJson -> JToken when (ToJson or  ^a0) : (static member ToJson :  ^a0 * ToJson -> JsonValue) and (ToJson or  ^a1) : (static member ToJson :  ^a1 * ToJson -> JsonValue) and (ToJson or  ^a2) : (static member ToJson :  ^a2 * ToJson -> JsonValue) and (ToJson or  ^a3) : (static member ToJson :  ^a3 * ToJson -> JsonValue) and (ToJson or  ^a4) : (static member ToJson :  ^a4 * ToJson -> JsonValue) and (ToJson or  ^a5) : (static member ToJson :  ^a5 * ToJson -> JsonValue) and (ToJson or  ^a6) : (static member ToJson :  ^a6 * ToJson -> JsonValue)'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    ''a * 'b * 'c * 'd * 'e * 'f * 'g'    �.
0>Possible overload: 'static member ToJson.ToJson : t: ^T * Fleece.Default5 -> JToken when  ^T : (static member get_JsonObjCodec : -> Codec<IReadOnlyDictionary<string,JsonValue>, ^T>)'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    ''a'    �.
0>Possible overload: 'static member ToJson.ToJson : t: ^T * Fleece.Default4 -> JToken when  ^T : (static member get_JsonObjCodec : -> ConcreteCodec<KeyValuePair<string,JToken> list,KeyValuePair<string,JToken> list,'a1, ^T>)'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    ''a'    �.
0>Possible overload: 'static member ToJson.ToJson : t: ^T * Fleece.Default3 -> JsonValue when  ^T : (static member ToJSON :  ^T -> JsonValue)'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    ''a'    �.
0>Possible overload: 'static member ToJson.ToJson : t: ^T * Fleece.Default2 -> JsonValue when  ^T : (static member ToJson :  ^T -> JsonValue)'. Type constraint mismatch. The type �    'TestAllTypes.NestedEnum'    �is not compatible with type�    ''a'    �.
@7sharp9
Copy link
Contributor Author

7sharp9 commented Feb 5, 2019

Discussed this here: fsprojects/Fleece#65
Requires substantial effort so marking as nice addition for now.

@7sharp9 7sharp9 added enhancement New feature or request help wanted Extra attention is needed labels Feb 5, 2019
@7sharp9
Copy link
Contributor Author

7sharp9 commented Feb 6, 2019

After discussion with @gusty we think this is best done in Fleece.

@7sharp9 7sharp9 added the json label Feb 15, 2019
@7sharp9
Copy link
Contributor Author

7sharp9 commented Feb 28, 2019

@gusty Can you remember what needs to be done for this?

@gusty
Copy link
Contributor

gusty commented Feb 28, 2019

Yes, there's no built-in support in Fleece for enums.

We can add a default codec there, based either on numbers or names. We need to decide which, it sounds to me that names are best suited for human-readable json.

Otherwise, since enums can't contain static members, the only way to encode them externally is by using explicit combinators.

Let me know which way you would prefer to move forward, for Falanx.

@7sharp9
Copy link
Contributor Author

7sharp9 commented Mar 19, 2019

@gusty I think the reasoning around json encoding is to be more human readable so lets just go for names for now although the proto definition of json encoding is this:

enum | string | "FOO_BAR" |
The name of the enum value as specified in proto is used. Parsers accept both enum names and integer values.

@gusty
Copy link
Contributor

gusty commented Mar 19, 2019

OK, let's add an overload for this.

@gusty
Copy link
Contributor

gusty commented Jul 21, 2019

This is done in Fleece. Once a new nuget is created we should be able to reference it and fix this.

@gusty
Copy link
Contributor

gusty commented Jul 22, 2019

BTW: I think this

Parsers accept both enum names and integer values.

is also doable in Fleece, the question is whether it makes sense, as it would work one way only.

@gusty
Copy link
Contributor

gusty commented Oct 7, 2020

Why closing this without merging #169 ?

@gusty
Copy link
Contributor

gusty commented Oct 8, 2020

Just for the sake of closing it? But the issue is real and the PR that would solve it is not merged.

@gusty
Copy link
Contributor

gusty commented Oct 8, 2020

I know, but in the OSS world you never know who's using what.

If you're not the maintainer and can't merge the PR that will effectively close this issue, you should leave it open.

By closing it this way you are giving the false information that the issue is resolved, when is not.

@7sharp9 7sharp9 reopened this Oct 8, 2020
deviousasti pushed a commit that referenced this issue Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed json
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants