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

silent failure of deserialiser generation #512

Closed
FilippoPolo opened this issue Dec 16, 2015 · 3 comments
Closed

silent failure of deserialiser generation #512

FilippoPolo opened this issue Dec 16, 2015 · 3 comments

Comments

@FilippoPolo
Copy link

(This applies to the current version from source control.) Consider this type:

[< NamedUnionCases>]
type testType =
 | Float of Float:float
 | Prod of Prod1:testType * testType
 | Sum of Sum1:testType * testType

I'm not 100% certain of what is supposed to happen when calling WebSharper.Json.Deserialize on this, according to http://websharper.com/docs/json#heading-3-4-2, because I'm not sure whether a different name is sufficient to satisfy the requirement for a unique field. Still, I would expect it to either succeed and work correctly, or fail with a compiler error.
Instead, compilation is successful but the resulting deserializer fails when invoked. This is the full repro case, where I attempt to do a round trip and test whether it works:

[< NamedUnionCases>]
type testType =
 | Float of Float:float
 | Prod of Prod1:testType * testType
 | Sum of Sum1:testType * testType
let runTest2() =
  let v = Prod(Float(1.0),Float(1.0));
  let str = WebSharper.Json.Serialize v
  let data2:testType = WebSharper.Json.Deserialize str
  let str2 = WebSharper.Json.Serialize data2
  if (str <> str2) then
    failwith "test failed"
  str2

Note that removing the Sum case results in the test succeeding, even though it isn't used anywhere.
Fortunately, there is a simple workaround. If I give a name to the second member of each tuple type, then everything works. So this isn't a major problem.

@Tarmil
Copy link
Member

Tarmil commented Dec 16, 2015

Indeed it seems that the deserialization algorithm to find the unique field to use is faulty. Looking at the compiled code, it deduces that it's a Sum if it has an Item2, which Prod also has, when it should look for Sum1 instead.

@Tarmil Tarmil closed this as completed in 48276f5 Dec 16, 2015
@granicz
Copy link
Member

granicz commented Dec 16, 2015

Just a tiny request: please-please, use proper markdown formatting for code snippets (indent by at least 4 spaces, or wrap in triple-ticks), otherwise the parent issue will end up looking horrible on the WebSharper forums page. Thanks!

@FilippoPolo
Copy link
Author

Will do. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants