{"record":{"id":"dca34eab6269429b","repo":"stride3d/stride","slug":"argument-must-be-at-least-2","errorCode":null,"errorMessage":"Argument must be at least 2.","messagePattern":"Argument must be at least 2\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Core/SymbolTypes.cs","lineNumber":222,"sourceCode":"    public static ScalarType Double { get; } = new(Scalar.Double);\n\n    public override string ToString() => Type switch\n    {\n        Scalar.Void => \"void\",\n        Scalar.Boolean => \"bool\",\n        Scalar.Int => \"int\",\n        Scalar.UInt => \"uint\",\n        Scalar.Int64 => \"long\",\n        Scalar.UInt64 => \"ulong\",\n        Scalar.Half => \"half\",\n        Scalar.Float => \"float\",\n        Scalar.Double => \"double\",\n        _ => throw new ArgumentOutOfRangeException()\n    };\n}\npublic sealed partial record VectorType(ScalarType BaseType, int Size) : SymbolType()\n{\n    public int Size { get; } = Size >= 2 ? Size : throw new ArgumentException(\"Argument must be at least 2.\", nameof(Size));\n\n    public override string ToString() => $\"{BaseType}{Size}\";\n}\npublic sealed partial record MatrixType(ScalarType BaseType, int Rows, int Columns) : SymbolType()\n{\n    public int Rows { get; } = Rows >= 2 ? Rows : throw new ArgumentException(\"Argument must be at least 2.\", nameof(Rows));\n    public int Columns { get; } = Columns >= 2 ? Columns : throw new ArgumentException(\"Argument must be at least 2.\", nameof(Columns));\n\n    // Note: this is HLSL-style so Rows/Columns meaning is swapped\n    // float2x3 = OpTypeMatrix vec3 2 = MatrixType(Rows: 3, Columns: 2)\n    public override string ToString() => $\"{BaseType}{Columns}x{Rows}\";\n}\n/// <summary>\n/// Array type.\n/// </summary>\n/// <param name=\"BaseType\">The base type for the array.</param>\n/// <param name=\"Size\">The size of the array. If -1, it means size is not defined, such as using [].</param>\npublic sealed partial record ArrayType(SymbolType BaseType, int Size, ConstantExpression? SizeExpression = null) : SymbolType()","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Core/SymbolTypes.cs#L204-L240","documentation":"VectorType enforces that a vector has at least 2 components (HLSL has float2..float4; there is no 0- or 1-component vector type). The record's Size property initializer throws ArgumentException when Size < 2, i.e. at construction time.","triggerScenarios":"new VectorType(scalarType, 0), new VectorType(scalarType, 1), or any negative size — including indirect paths like VectorType.From with a malformed string or SPIR-V parsing code passing a raw component count of 0/1.","commonSituations":"Parsing a malformed shader constant/vector declaration; SPIR-V or parser code computing vector size from data that reports 1 component (e.g. treating a scalar as a vector); hand-writing a vector type with an off-by-one size.","solutions":["Ensure Size is between 2 and 4 before constructing; for a single component use the ScalarType itself instead of VectorType.","Clamp or map size 1 (and 0) to the equivalent ScalarType in the caller.","If the size comes from parsed data, validate/reject the input before constructing the record.","Catch ArgumentException at the construction boundary if input sizes are user-supplied and report a diagnostic."],"exampleFix":"// before\nvar v = new VectorType(ScalarType.Float, 1); // ArgumentException\n// after\nSymbolType t = size >= 2 ? new VectorType(ScalarType.Float, size) : ScalarType.Float;","handlingStrategy":"validation","validationCode":"if (size is < 2 or > 4)\n    throw new ArgumentOutOfRangeException(nameof(size), size, \"Vector size must be 2..4\");\nvar v = new VectorType(baseType, size);","typeGuard":null,"tryCatchPattern":"try { var v = new VectorType(baseType, size); }\ncatch (ArgumentException ex)\n{\n    // ex.ParamName == \"Size\": report invalid vector dimension from parsed data\n}","preventionTips":["Validate vector component counts (2..4) at parse time before building types.","Represent single-component values as ScalarType, not VectorType.","Clamp/map sizes read from external data (SPIR-V, declarations) before constructing."],"tags":["csharp","shaders","argument-validation"],"backgroundTag":"argument-out-of-range","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}