{"record":{"id":"a03f3c7dc394b235","repo":"louthy/language-ext","slug":"must-be-of-type-accel","errorCode":null,"errorMessage":"must be of type Accel","messagePattern":"must be of type Accel","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"LanguageExt.Core/Units of Measure/Accel.cs","lineNumber":44,"sourceCode":"\n    public bool Equals(Accel other) =>\n        Value.Equals(other.Value);\n\n    public bool Equals(Accel other, double epsilon) =>\n        Math.Abs(other.Value - Value) < epsilon;\n\n    public override bool Equals(object? obj) =>\n        obj is Accel accel && Equals(accel);\n\n    public override int GetHashCode() =>\n        Value.GetHashCode();\n\n    public int CompareTo(object? obj) =>\n        obj switch\n        {\n            null        => 1,\n            Accel other => CompareTo(other),\n            _           => throw new ArgumentException($\"must be of type {nameof(Accel)}\")\n        };\n\n    public int CompareTo(Accel other) =>\n        Value.CompareTo(other.Value);\n\n    public Accel Add(Accel rhs) =>\n        new (Value + rhs.Value);\n\n    public Accel Subtract(Accel rhs) =>\n        new (Value - rhs.Value);\n\n    public Accel Multiply(double rhs) =>\n        new (Value * rhs);\n\n    public Accel Divide(double rhs) =>\n        new (Value / rhs);\n\n    public static Accel operator *(Accel lhs, double rhs) =>","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/louthy/language-ext/blob/2f0e3628242889774d4141960a35671a0280051f/LanguageExt.Core/Units of Measure/Accel.cs#L26-L62","documentation":"Accel.CompareTo(object? obj) throws ArgumentException('must be of type Accel') when the boxed object passed is neither null nor an Accel. This is the standard IComparable contract: null is ordered before the current value, same-type values are compared by Value, and any other type is rejected.","triggerScenarios":"Passing a non-Accel object (e.g. a double, another unit-of-measure type like Vel or Length, or a boxed int) to the non-generic IComparable.CompareTo — typically via Array.Sort, List.Sort, Comparer.Default, or any API taking object.","commonSituations":"Sorting a mixed object[] containing several LanguageExt unit-of-measure types; comparing Accel against raw numeric values assuming implicit conversion; reflection-based comparisons that erase the static type.","solutions":["Compare against another Accel: wrap or convert the other operand to Accel before calling CompareTo.","Use the generic CompareTo(Accel other) overload, which is type-safe and never throws this error.","Filter or type-check heterogeneous collections before sorting them with Comparer<Accel>.Default.","If you intended to compare magnitudes, extract the underlying Value (double) from both operands and compare those."],"exampleFix":"// before\nobject x = 9.8; // boxed double\naccel.CompareTo(x); // ArgumentException: must be of type Accel\n// after\nif (x is Accel other)\n    accel.CompareTo(other);\nelse\n    accel.CompareTo(new Accel(Convert.ToDouble(x)));","handlingStrategy":"type-guard","validationCode":"// before calling the non-generic CompareTo\nif (obj is not null && obj is not Accel)\n    throw new ArgumentException($\"Expected Accel, got {obj.GetType().Name}\");","typeGuard":"static bool IsAccel(object? obj) => obj is Accel;","tryCatchPattern":"try\n{\n    result = accel.CompareTo((object)maybeAccel);\n}\ncatch (ArgumentException)\n{\n    result = -1; // or handle non-Accel operand explicitly\n}","preventionTips":["Prefer the generic CompareTo(Accel other) overload which is compile-time type-safe","Unbox heterogeneous collections before sorting with unit-of-measure types","Never compare Accel against raw numerics — construct an Accel first","Pattern-match with 'is Accel other' instead of casting blindly"],"tags":["icomparable","argument-type","units-of-measure","languageext"],"backgroundTag":"invalid-argument-value","analyzedSha":"2f0e3628242889774d4141960a35671a0280051f","analyzedAt":"2026-09-15T03:31:55.716Z","contentChangedAt":"2026-09-15T03:31:55.716Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}