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

Copy and update record expression doesn't compile when the record comes from a function #18062

Open
mlaily opened this issue Nov 26, 2024 · 0 comments

Comments

@mlaily
Copy link

mlaily commented Nov 26, 2024

In some cases, I can't use the with keyword to copy and update a record with the F# 7 nested records shortcut syntax, when the source record comes from a function call (but in some situations it compiles fine).

It seems the compiler gets somehow confused... (?)

Repro steps

The following code doesn't compile:

type MyCustomer =
    { FirstName: string
      LastName: string
      Comment: string option }

type MyBooking =
    { Reference: string
      Customer: MyCustomer }

type MyParentObject = { Booking: MyBooking }

module MyParentObject =
    let Sample =
        { Booking =
            { Reference = "reference"
              Customer =
                { FirstName = "firstname"
                  LastName = "lastname"
                  Comment = Some "comment" } } }

let okTest =
    let value = MyParentObject.Sample

    { value with
        MyParentObject.Booking.Customer.Comment = None }

let failingTest =
    let func () = MyParentObject.Sample

    { func () with
        MyParentObject.Booking.Customer.Comment = None }

More precisely, the okTest compiles ok, but the failingTest does not.

Expected behavior

I would expect the failingTest to work.

Related information

Provide any related information (optional):

I'm using Visual Studio 17.12 on Windows, with .NET 9 installed.

I reproduced the issue when targeting .NET 8 and .NET 6 too, and also from VS Code.


Did I stumble on a real issue, or am I misunderstanding something?

@github-actions github-actions bot added this to the Backlog milestone Nov 26, 2024
@mlaily mlaily changed the title Copy and update record expression doesn't compile when using a function output Copy and update record expression doesn't compile when the record comes from a function Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: New
Development

No branches or pull requests

1 participant