Skip to content

Mutually recursive non-function values with intermediate module definition not initialized incorrectly #12384

@brianberns

Description

@brianberns

Repro steps

Consider the following code:

type Node =
    {
        Next: Node
        Prev: Node
        Value: int
    }

let rec one =
    {
        Next = two
        Prev = two
        Value = 1
    }

and two =
    {
        Next = one
        Prev = one
        Value = 2
    }
printfn "%A" one
printfn "%A" two

Expected behavior

Either:

  • Correctly initialize the mutually recursive values.
  • Reject the code as being invalid.

Actual behavior

The code compiles with no warnings/errors. two is initialized correctly, but one.Next and one.Prev are both null:

{ Next = null
  Prev = null
  Value = 1 }
{ Next = { Next = null
           Prev = null
           Value = 1 }
  Prev = { Next = null
           Prev = null
           Value = 1 }
  Value = 2 }

Known workarounds

None

Related information

Decompiled C# code with incorrect initialization.

Note that a single self-referencing value is actually initialized correctly:

let rec zero =
    {
        Next = zero
        Prev = zero
        Value = 0
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-CodeGenIlxGen, ilwrite and things at the backendBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.Ready

    Type

    Projects

    Status

    New

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions