Skip to content

[module rec] does not initialize let bindings #16009

@xperiandri

Description

@xperiandri

Repro steps

Run reproduction sample
ModuleRecIssueRepro.zip

Notice that in the file AssessmentDataValidated.fs at line 61 Codec value is null!

[<AutoOpen>]
module CodecsExtensions =

    module AsseseeCodecs =

        open System.Net.Mail

        let Codec: Codec<Encoding, Assessee> = // <<----------------- null is here!
            ofObjCodec
            <| codec {
                let! lastName = jreq "lastName" (fun a -> a.LastName |> Some)
                and! firstName = jreq "firstName" (fun a -> a.FirstName |> Some)

                and! middleName =
                    jopt "middleName" (fun a -> a.MiddleName |> ValueOption.toOption)

                and! dateOfBirth = jopt "dateOfBirth" (fun a -> a.DateOfBirth |> ValueOption.toOption)
                and! phone = jopt "phone" (fun a -> a.Phone |> ValueOption.toOption)
                and! email = jopt "email" (fun a -> a.Email |> ValueOption.map (fun mail -> mail.Address) |> ValueOption.toOption)

                return {
                    LastName = lastName
                    MiddleName = middleName |> Option.toVOption
                    FirstName = firstName
                    DateOfBirth = dateOfBirth |> Option.toVOption
                    Phone = phone |> Option.toVOption
                    Email = email |> Option.toVOption |> ValueOption.map MailAddress
                }
            }

    type Assessee with

        static member Codec = AsseseeCodecs.Codec

[<RequireQualifiedAccess>]
module Codecs =

    let V1: Codec<Encoding, EventData> =
        let assesseeCodec = Assessee.Codec
        ofObjCodec
        <| codec {
            let! assessee = jreqWith Assessee.Codec "assessee" (fun di -> di.Assessee |> Some)
            let x = { Assessee = assessee(*; DrivingLicense = drivingLicense; Address = address*) }
            return x
        }

Expected behavior

Codec value is codec

Actual behavior

Codec value is null

Known workarounds

Do not use module rec

Related information

  • .NET 7
  • Visual Studio 17.8 Preview 2.0

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions