Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type of dereferenced byref #3712

Merged
merged 1 commit into from
Jan 24, 2024
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
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
]
Loading