Skip to content

Commit

Permalink
Merge pull request #3712 from chkn/fix-deref-byref-type
Browse files Browse the repository at this point in the history
Fix type of dereferenced byref
  • Loading branch information
ncave authored Jan 24, 2024
2 parents ca97ed0 + b371b08 commit 3a51f87
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Fable.Transforms/FSharp2Fable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,12 @@ let private transformExpr
&& com.Options.Language <> Rust
then
// Getting byref value is compiled as FSharpRef op_Dereference
return Replacements.Api.getRefCell com r v.Type v
return
Replacements.Api.getRefCell
com
r
(List.head v.Type.Generics)
v
else
return v

Expand Down
11 changes: 11 additions & 0 deletions tests/Js/Main/TypeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,12 @@ let inline callWithByrefCreatedFromByrefInlined(n: byref<int>) =
let f = &n
byrefFunc &f

let inline inlinedFunc(n: 't[]) =
n.Length

let genericByrefFunc(n: byref<'t[]>) =
inlinedFunc n

let tests =
testList "Types" [
// TODO: This test produces different results in Fable and .NET
Expand Down Expand Up @@ -1100,4 +1106,9 @@ let tests =
ignore intRef
callWithByrefCreatedFromByrefInlined &intRef
an_int |> equal 66

testCase "inline with generic byref works" <| fun () ->
let mutable arr = [| 1; 2; 3 |]
let result = genericByrefFunc &arr
result |> equal 3
]

0 comments on commit 3a51f87

Please sign in to comment.