You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 3, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Jan 3, 2023. It is now read-only.
Initialization of mutually recursive values can sometimes leave fields uninitialized #847
When initializing mutually recursive values, some fields may end up null (i.e. uninitialized). This does not depend on whether the values are not actually recursive or only declared as such.
No warnings are issued by the compiler, and no runtime errors are raised.
Repro steps
Here is a minimal repro:
type A = A of B
and B = B of A | C
// Case 1: non-recursive
let rec a1 = B (A b1)
and b1 = B (A c1)
and c1 = C
// Case 2: true recursive
let rec a2 = A b2
and b2 = B a2
Case 1: the values are not actually recursive, but are declared as such. The value a1 ends up under-initialized: a1 = B (A null). However, value b1 initializes correctly: b1 = B (A C).
Case 2: the values are actually recursive, and both end up invalid: a2 = A null, b2 = B (A null). Also, b2 itself seems to get initialized correctly as far as its own fields, that is: obj.ReferenceEquals( (fun (B a) -> a) b2, a2 ) = true
Expected behavior
a1 = B (A (B (A C)))
b1 = B (A C)
c1 = C
a2 = A (B a2)
b2 = B (A b2)
Activity
71 commentedon Oct 27, 2018
Looks like this problem only appears in modules, that is...
does result in
However, this non-recursive behavior can be avoided by using an inner expression:
results in
fsoikin commentedon Apr 29, 2019
Another occurrence of this caught in the wild: https://stackoverflow.com/questions/55907218/why-is-the-recursive-value-null/55909017
dsyme commentedon May 16, 2019
Moved to dotnet/fsharp#6750