Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/Fable.Transforms/Python/Replacements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4004,7 +4004,16 @@ let fsharpType com methName (r: SourceLocation option) t (i: CallInfo) (args: Ex
| "IsRecord"
| "IsTuple"
| "IsFunction" ->
Helper.LibCall(com, "Reflection", Naming.lowerFirst methName, t, args, i.SignatureArgTypes, ?loc = r)
// Drop the trailing `allowAccessToPrivateRepresentation` flag (no meaning in Python)
Helper.LibCall(
com,
"Reflection",
Naming.lowerFirst methName,
t,
List.truncate 1 args,
i.SignatureArgTypes,
?loc = r
)
|> Some
| "IsExceptionRepresentation"
| "GetExceptionFields" -> None // TODO!!!
Expand Down
4 changes: 3 additions & 1 deletion tests/Python/TestReflection.fs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ let ``test reflection functions accept allowAccessToPrivateRepresentation`` () =
let recordType = typeof<MyRecord>
let record = { String = "a"; Int = 1 }

FSharpType.IsRecord(recordType, allowAccessToPrivateRepresentation = true) |> equal true
FSharpType.GetRecordFields(recordType, allowAccessToPrivateRepresentation = true).Length |> equal 2

let values = FSharpValue.GetRecordFields(record, allowAccessToPrivateRepresentation = true)
Expand All @@ -231,7 +232,8 @@ let ``test reflection functions accept allowAccessToPrivateRepresentation`` () =
rebuilt |> equal record

let unionType = typeof<MyUnion>
let intCase = FSharpType.GetUnionCases(unionType).[1]
FSharpType.IsUnion(unionType, allowAccessToPrivateRepresentation = true) |> equal true
let intCase = FSharpType.GetUnionCases(unionType, allowAccessToPrivateRepresentation = true).[1]
let u = FSharpValue.MakeUnion(intCase, [| box 5 |], allowAccessToPrivateRepresentation = true) :?> MyUnion
let info, fields = FSharpValue.GetUnionFields(u, unionType, allowAccessToPrivateRepresentation = true)
info.Name |> equal "IntCase"
Expand Down
Loading