Skip to content

Commit

Permalink
fix #911 missing System type handling in Router.Infer
Browse files Browse the repository at this point in the history
  • Loading branch information
Jand42 committed Feb 19, 2018
1 parent 25df835 commit cc3678d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 16 deletions.
5 changes: 5 additions & 0 deletions src/compiler/WebSharper.Core/Macros.fs
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@ type NumericMacro() =
translateCompareTo c.Compilation (ConcreteType c.DefiningType) c.This.Value c.Arguments.Head
| _ -> MacroFallback

override this.TranslateCtor(c) =
match c.Arguments with
| [] -> MacroOk (Value (Int 0))
| _ -> MacroError "numericMacro error: contructor with arguments"

let charTy, charParse =
let t = typeof<System.Char>
Reflection.ReadTypeDefinition t,
Expand Down
24 changes: 24 additions & 0 deletions src/sitelets/WebSharper.Sitelets/RouterInfer.Client.fs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ module private ClientRoutingInternals =
let rIntOp = getMethod <@ RouterOperators.rInt @>
let rDoubleOp = getMethod <@ RouterOperators.rDouble @>
let rDateTimeOp = getMethod <@ RouterOperators.rDateTime @>
let rSByteOp = getMethod <@ RouterOperators.rSByte @>
let rByteOp = getMethod <@ RouterOperators.rByte @>
let rInt16Op = getMethod <@ RouterOperators.rInt16 @>
let rUInt16Op = getMethod <@ RouterOperators.rUInt16 @>
let rUInt32Op = getMethod <@ RouterOperators.rUInt @>
let rInt64Op = getMethod <@ RouterOperators.rInt64 @>
let rUInt64Op = getMethod <@ RouterOperators.rUInt64 @>
let rSingleOp = getMethod <@ RouterOperators.rSingle @>
let TupleOp = getMethod <@ RouterOperators.JSTuple [||] @>
let ArrayOp = getMethod <@ RouterOperators.JSArray RouterOperators.rInt @>
let ListOp = getMethod <@ RouterOperators.JSList RouterOperators.rInt @>
Expand Down Expand Up @@ -228,6 +236,22 @@ type RoutingMacro() =
true, Call(None, NonGeneric routerOpsModule, NonGeneric rDoubleOp, [])
| C (T "System.DateTime", []) ->
true, Call(None, NonGeneric routerOpsModule, NonGeneric rDateTimeOp, [])
| C (T "System.SByte", []) ->
true, Call(None, NonGeneric routerOpsModule, NonGeneric rSByteOp, [])
| C (T "System.Byte", []) ->
true, Call(None, NonGeneric routerOpsModule, NonGeneric rByteOp, [])
| C (T "System.Int16", []) ->
true, Call(None, NonGeneric routerOpsModule, NonGeneric rInt16Op, [])
| C (T "System.UInt16", []) ->
true, Call(None, NonGeneric routerOpsModule, NonGeneric rUInt16Op, [])
| C (T "System.UInt32", []) ->
true, Call(None, NonGeneric routerOpsModule, NonGeneric rUInt32Op, [])
| C (T "System.Int64", []) ->
true, Call(None, NonGeneric routerOpsModule, NonGeneric rInt64Op, [])
| C (T "System.UInt64", []) ->
true, Call(None, NonGeneric routerOpsModule, NonGeneric rUInt64Op, [])
| C (T "System.Single", []) ->
true, Call(None, NonGeneric routerOpsModule, NonGeneric rSingleOp, [])
| TupleType (ts, _) ->
let fields = NewArray (ts |> List.map getRouter)
true, Call(None, NonGeneric routerOpsModule, NonGeneric TupleOp, [ fields ])
Expand Down
32 changes: 16 additions & 16 deletions src/sitelets/WebSharper.Sitelets/RouterInfer.Server.fs
Original file line number Diff line number Diff line change
Expand Up @@ -259,22 +259,22 @@ module internal ServerRouting =
match t.Namespace with
| "System" ->
match t.Name with
| "Object" ->
IEmpty
| "String" ->
iString
| "Char" ->
iChar
| "Guid" ->
iGuid
| "Boolean" ->
iBool
| "Int32" ->
iInt
| "Double" ->
iDouble
| "DateTime" ->
iDateTime None
| "Object" -> IEmpty
| "String" -> iString
| "Char" -> iChar
| "Guid" -> iGuid
| "Boolean" -> iBool
| "Int32" -> iInt
| "Double" -> iDouble
| "DateTime" -> iDateTime None
| "SByte" -> iSByte
| "Byte" -> iByte
| "Int16" -> iInt16
| "UInt16" -> iUInt16
| "UInt32" -> iUInt
| "Int64" -> iInt64
| "UInt64" -> iUInt64
| "Single" -> iSingle
| "Nullable`1" ->
let item = t.GetGenericArguments().[0]
INullable (getRouter item)
Expand Down
4 changes: 4 additions & 0 deletions tests/WebSharper.Web.Tests/Routers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

namespace WebSharper.Sitelets.Tests

open System
open WebSharper
open WebSharper.Sitelets
open WebSharper.CSharp.Sitelets.Tests
Expand Down Expand Up @@ -86,6 +87,8 @@ module PerformanceTests =
| [<EndPoint "/wildcard-list"; Wildcard>] UWildcardList of int list
| [<EndPoint "/two-unions">] UTwoUnions of MultipleTest * MultipleTest
| [<EndPoint "/csharp">] UCSharp of CSharpEndPointRoot
| [<EndPoint "/type-tests">] TypeTests of
Guid * single * double * sbyte * byte * int16 * uint16 * uint32 * int64 * uint64

let TestValues =
[
Expand Down Expand Up @@ -129,6 +132,7 @@ module PerformanceTests =
UTwoUnions (A1 1, A1 1)
UCSharp (new CSharpEndPointRoot())
UCSharp (new CSharpEndPointRoot.Sub1(X = 42))
TypeTests (Guid.NewGuid(), 1.3f, 1.4, 15y, 16uy, 64s, 65us, 66u, 67L, 68UL)
]

let ExtraTestValues =
Expand Down

0 comments on commit cc3678d

Please sign in to comment.