Skip to content

Commit

Permalink
Fix #512: argument-less NamedUnionCases + regression test
Browse files Browse the repository at this point in the history
  • Loading branch information
Tarmil committed Dec 16, 2015
1 parent d517363 commit 48276f5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/compiler/WebSharper.Core/Json.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -744,7 +744,7 @@ let inferredCasesTable t =
buildTable
<| (name, tag) :: acc
<| Map.remove tag cases
buildTable [] cases
buildTable [] allCases

module Internal =

Expand Down
17 changes: 17 additions & 0 deletions tests/WebSharper.Tests/Regression.fs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ module Bug446 =
// new v = { inherit BaseClass(v + 1); x = v }
// member this.OriginalValue = this.x

[<JavaScript>]
module Bug512 =
[<NamedUnionCases>]
type TestType =
| Float of Float:float
| Prod of Prod1:TestType * TestType
| Sum of Sum1:TestType * TestType

// for bug #328
type System.Object with
[<Inline "$0.test">]
Expand Down Expand Up @@ -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<Bug512.TestType> str
let str2 = WebSharper.Json.Serialize data2
equal v data2
equal str str2
}

}
5 changes: 5 additions & 0 deletions tests/WebSharper.Tests/WebSharper.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
<Project>{52741881-8d64-4639-8b5c-19c060958c35}</Project>
<Private>True</Private>
</ProjectReference>
<ProjectReference Include="..\..\src\sitelets\WebSharper.Web\WebSharper.Web.fsproj">
<Name>WebSharper.Web</Name>
<Project>{fe6ba781-fdc9-4bb5-b38a-3bb9841ea836}</Project>
<Private>True</Private>
</ProjectReference>
<ProjectReference Include="..\..\src\stdlib\WebSharper.Collections\WebSharper.Collections.fsproj">
<Name>WebSharper.Collections</Name>
<Project>{4ef94364-b50f-4906-ab91-77bca8413d60}</Project>
Expand Down

0 comments on commit 48276f5

Please sign in to comment.