Skip to content

Commit 1669c13

Browse files
Fix reflection for int64 with
1 parent be5961b commit 1669c13

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/Fable.Transforms/FSharp2Fable.Util.fs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -773,11 +773,17 @@ module TypeHelpers =
773773
dict ["bool`1", Choice1Of2 Fable.Boolean
774774
"byte`1", Choice1Of2 (Fable.Number UInt8)
775775
"string`1", Choice1Of2 Fable.String
776-
"uint64`1", Choice2Of2("System.Runtime", Types.uint64)
777-
"Guid`1", Choice2Of2("System.Runtime", Types.guid)
778-
"TimeSpan`1", Choice2Of2("System.Runtime", Types.timespan)
779-
"DateTime`1", Choice2Of2("System.Runtime", Types.datetime)
780-
"DateTimeOffset`1", Choice2Of2("System.Runtime", Types.datetimeOffset)]
776+
"uint64`1", Choice2Of2 Types.uint64
777+
"Guid`1", Choice2Of2 Types.guid
778+
"TimeSpan`1", Choice2Of2 Types.timespan
779+
"DateTime`1", Choice2Of2 Types.datetime
780+
"DateTimeOffset`1", Choice2Of2 Types.datetimeOffset]
781+
782+
let private makeSystemRuntimeType fullName =
783+
let r: Fable.EntityRef =
784+
{ FullName = fullName
785+
Path = Fable.CoreAssemblyName "System.Runtime" }
786+
Fable.DeclaredType(r, [])
781787

782788
let makeTypeFromDef ctxTypeArgs (genArgs: IList<FSharpType>) (tdef: FSharpEntity) =
783789
if tdef.IsArrayType then
@@ -801,16 +807,14 @@ module TypeHelpers =
801807
| Types.resizeArray -> makeGenArgs ctxTypeArgs genArgs |> List.head |> Fable.Array
802808
| Types.list -> makeGenArgs ctxTypeArgs genArgs |> List.head |> Fable.List
803809
| DicContains numberTypes kind -> Fable.Number kind
810+
| "Microsoft.FSharp.Core.int64`1" -> makeSystemRuntimeType Types.int64
811+
| "Microsoft.FSharp.Core.decimal`1" -> makeSystemRuntimeType Types.decimal
804812
// TODO: FCS doesn't expose the abbreviated type of a MeasureAnnotatedAbbreviation,
805813
// so we need to hard-cde FSharp.UMX types
806814
| Naming.StartsWith "FSharp.UMX." (DicContains fsharpUMX choice) ->
807815
match choice with
808816
| Choice1Of2 t -> t
809-
| Choice2Of2(dllName, fullName) ->
810-
let r: Fable.EntityRef =
811-
{ FullName = fullName
812-
Path = Fable.CoreAssemblyName dllName }
813-
Fable.DeclaredType(r, [])
817+
| Choice2Of2 fullName -> makeSystemRuntimeType fullName
814818
| _ ->
815819
// Special attributes
816820
tdef.Attributes |> tryPickAttribute [

tests/Main/ReflectionTests.fs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Fable.Tests.Reflection
22

33
open Util.Testing
4+
open FSharp.Data.UnitSystems.SI.UnitSymbols
45

56
#if !OPTIMIZE_FCS
67

@@ -470,6 +471,11 @@ let reflectionTests = [
470471
let value = 0.7833263478179128134089M
471472
value.GetType().FullName |> equal "System.Decimal"
472473

474+
// See https://github.com/thoth-org/Thoth.Json/issues/74
475+
testCase "Reflection info of int64/decimal with units of measure works" <| fun () ->
476+
typeof< int64 > = typeof< int64<m> > |> equal true
477+
typeof< decimal > = typeof< decimal<m> > |> equal true
478+
473479
testCase "Reflection works with enums" <| fun () ->
474480
typeof<MyEnum>.IsEnum |> equal true
475481
typeof<int>.IsEnum |> equal false

0 commit comments

Comments
 (0)