Skip to content

Commit

Permalink
Fix #644 remoting with unions with Constant null case
Browse files Browse the repository at this point in the history
  • Loading branch information
Jand42 committed Feb 17, 2017
1 parent 15da7d9 commit 651918d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/compiler/WebSharper.Compiler/QuotationReader.fs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ let rec transformExpression (env: Environment) (expr: Expr) =
| _ -> expr :: acc
getSeq [] expr |> List.rev |> List.map tr |> Sequential
| Patterns.Value (value, _) ->
if obj.ReferenceEquals(value, null) then Value Null else
if isNull value then Value Null else
try
let value =
let t = value.GetType()
Expand Down
10 changes: 7 additions & 3 deletions src/compiler/WebSharper.Core/Json.fs
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,7 @@ let rec Write (writer: System.IO.TextWriter) (value: Value) =
else
raise WriteException
let wS (x: string) =
if x = null then
raise WriteException
if x = null then s "null" else
c '"'
for i in 0 .. x.Length - 1 do
match x.[i] with
Expand Down Expand Up @@ -586,6 +585,7 @@ let serializers =
| x -> raise (DecoderException(x, typeof<char>))
add encChar decChar d
let decString = function
| Null -> null
| String x -> x
| x -> raise (DecoderException(x, typeof<string>))
add EncodedString decString d
Expand Down Expand Up @@ -1004,6 +1004,10 @@ let unionDecoder dD (i: FormatSettings) (ta: TAttrs) =
for k, v in c do consts.Add(k, v)
consts
let getTag = i.GetUnionTag t
let nullConstant =
match consts.TryGetValue (String null) with
| true, x -> x
| false, _ -> null
fun (x: Value) ->
match x with
| Object fields ->
Expand All @@ -1016,7 +1020,7 @@ let unionDecoder dD (i: FormatSettings) (ta: TAttrs) =
fs
|> Array.map (fun (f, e) -> e (get f))
|> mk
| Null -> null
| Null -> nullConstant
| v ->
match consts.TryGetValue v with
| true, x -> x
Expand Down

0 comments on commit 651918d

Please sign in to comment.