From 48276f53a6413c61ae5205e9f7e8f3f2e6b41621 Mon Sep 17 00:00:00 2001 From: Loic Denuziere Date: Wed, 16 Dec 2015 11:45:55 +0100 Subject: [PATCH] Fix #512: argument-less NamedUnionCases + regression test --- src/compiler/WebSharper.Core/Json.fs | 6 +++--- tests/WebSharper.Tests/Regression.fs | 17 +++++++++++++++++ tests/WebSharper.Tests/WebSharper.Tests.fsproj | 5 +++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/compiler/WebSharper.Core/Json.fs b/src/compiler/WebSharper.Core/Json.fs index dfbb8e164..e7e24322c 100644 --- a/src/compiler/WebSharper.Core/Json.fs +++ b/src/compiler/WebSharper.Core/Json.fs @@ -706,7 +706,7 @@ let getDiscriminatorName (t: System.Type) = else None) let inferredCasesTable t = - let cases = + let allCases = FST.GetUnionCases(t, flags) |> Array.map (fun c -> let fields = c.GetFields() @@ -727,7 +727,7 @@ let inferredCasesTable t = cases |> Map.tryPick (fun t fs -> let allOtherFields = - cases + allCases |> Seq.choose (fun (KeyValue(t', fs)) -> if t = t' then None else Some fs) |> Set.unionMany @@ -744,7 +744,7 @@ let inferredCasesTable t = buildTable <| (name, tag) :: acc <| Map.remove tag cases - buildTable [] cases + buildTable [] allCases module Internal = diff --git a/tests/WebSharper.Tests/Regression.fs b/tests/WebSharper.Tests/Regression.fs index 526af70f4..2cc7ad150 100644 --- a/tests/WebSharper.Tests/Regression.fs +++ b/tests/WebSharper.Tests/Regression.fs @@ -155,6 +155,14 @@ module Bug446 = // new v = { inherit BaseClass(v + 1); x = v } // member this.OriginalValue = this.x +[] +module Bug512 = + [] + type TestType = + | Float of Float:float + | Prod of Prod1:TestType * TestType + | Sum of Sum1:TestType * TestType + // for bug #328 type System.Object with [] @@ -364,4 +372,13 @@ let Tests = equal (test()) (5, 5) } + Test "Bug #512" { + let v = Bug512.Prod(Bug512.Float(1.0),Bug512.Float(1.0)); + let str = WebSharper.Json.Serialize v + let data2 = WebSharper.Json.Deserialize str + let str2 = WebSharper.Json.Serialize data2 + equal v data2 + equal str str2 + } + } diff --git a/tests/WebSharper.Tests/WebSharper.Tests.fsproj b/tests/WebSharper.Tests/WebSharper.Tests.fsproj index b03b44484..743f3bd1e 100644 --- a/tests/WebSharper.Tests/WebSharper.Tests.fsproj +++ b/tests/WebSharper.Tests/WebSharper.Tests.fsproj @@ -55,6 +55,11 @@ {52741881-8d64-4639-8b5c-19c060958c35} True + + WebSharper.Web + {fe6ba781-fdc9-4bb5-b38a-3bb9841ea836} + True + WebSharper.Collections {4ef94364-b50f-4906-ab91-77bca8413d60}