Header menu logo ionide-analyzers

CopyAndUpdateRecordChangesAllFieldsAnalyzer

Problem

See fsharp/fslang-suggestions#603, when you have a record update expression that overrides all fields, it is advised to construct a new instance instead.

type Point = 
    {
        X: int
        Y: int
    }

let zero = { X = 0; Y = 0 }
// Triggers analyzer
let moved = { zero with X = 1; Y = 2 }

Fix

Remove the expr with part:

let moved = { X = 1; Y = 2 }

If you use the Ionide integration, there's a quick fix available:

RecordUpdateAnalyzerFix

type Point = { X: int Y: int }
Point.X: int
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

--------------------
type int = int32

--------------------
type int<'Measure> = int
Point.Y: int
val zero: Point
val moved: Point

Type something to start searching.