Skip to content

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

@MathewMorreyClark

Description

@MathewMorreyClark

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.

Metadata

Metadata

Assignees

Labels

Area-Compiler-OptimizationThe F# optimizer, release code gen etc.BugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.

Type

No fields configured for Bug.

Projects

Status

New

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions