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

Compiler throws internal error when using record 'with' construct on type with static let #18165

Open
MathewMorreyClark opened this issue Dec 19, 2024 · 0 comments

Comments

@MathewMorreyClark
Copy link

When using 'with' to construct a record based on another record, in a specific set of circumstances the compiler fails with the following errors:

error FS0073: internal error: TryOptimizeRecordFieldGet: term argument out of range
error FS0193: internal error: Index was outside the bounds of the array.

The following toy application reproduces the error:

type FooBar =
    { xyz : string }
    static let staticLet = 1

let doThing (foo : FooBar) =
    let bar = { foo with xyz = foo.xyz }
    let baz = { bar with xyz = bar.xyz }
    printfn "%O" baz

doThing { xyz = "" }

Note that the following are required:

  • baz must use with based on another record type that also uses with based on another record type: if baz is changed to = { foo with... the code builds correctly.
  • The record type must contain a static let: if staticLet is removed then the code builds correctly.
  • The code must be in a function: if doThing is removed and replaced with let foo = { Field = "" } then the code builds correctly.

This error only happens when building with optimisations switched on.

Tested using the 9.0.101 SDK.

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