diff --git a/src/Fable.Transforms/FSharp2Fable.fs b/src/Fable.Transforms/FSharp2Fable.fs index 6f9faa9b13..24584c77f7 100644 --- a/src/Fable.Transforms/FSharp2Fable.fs +++ b/src/Fable.Transforms/FSharp2Fable.fs @@ -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 diff --git a/tests/Js/Main/TypeTests.fs b/tests/Js/Main/TypeTests.fs index 678b877285..5e314bdfa9 100644 --- a/tests/Js/Main/TypeTests.fs +++ b/tests/Js/Main/TypeTests.fs @@ -503,6 +503,12 @@ let inline callWithByrefCreatedFromByrefInlined(n: byref) = 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 @@ -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 ]