Table of Contents

TUX003 - Invalid const assignment to a refined type

A compile time known constant value that does not pass refinement will fail at runtime. The value should be changed, or the code changed.

using Tuxedo;

public readonly partial struct TrueBool
{
    [Refinement("Must be 'true'", Name = nameof(TrueBool))]
    public static bool Refinement(bool value) => value;
}

public class Test
{
    public void TestMethod()
    {
        // thes are not compliant
        var v1 = TrueBool.Parse(false);
        var v2 = (TrueBool)false;
        var v3 = TrueBool.TryParse(false, out _, out _);
        
        // these are
        var v4 = TrueBool.Parse(true);
        var v5 = (TrueBool)true;
        var v6 = TrueBool.TryParse(true, out _, out _);
    }
}