{"record":{"id":"3c857eec1795a2c8","repo":"stride3d/stride","slug":"unsupported-composite-type-type","errorCode":null,"errorMessage":"Unsupported composite type {Type}","messagePattern":"Unsupported composite type (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Parsing/SDSL/AST/Literals.cs","lineNumber":185,"sourceCode":"\n    public bool IsConstant()\n    {\n        foreach (var v in Values)\n            if (v is not (NumberLiteral or BoolLiteral))\n                return false;\n        return true;\n    }\n\n    public override SpirvValue CompileImpl(SymbolTable table, CompilerUnit compiler)\n    {\n        var (builder, context) = compiler;\n\n        (var compositeCount, var totalCount, var expectedElementType) = Type switch\n        {\n            VectorType v => (v.Size, v.Size, v.BaseType),\n            MatrixType m => (m.Columns, m.Columns * m.Rows, m.BaseType),\n            ArrayType t => (t.Size, t.Size, t.BaseType),\n            _ => throw new NotSupportedException($\"Unsupported composite type {Type}\"),\n        };\n\n        Span<int> values = stackalloc int[totalCount];\n        Span<int> compositeValues = stackalloc int[compositeCount];\n\n        // Note: There are a lot of opportunity to optimize by working with vector-to-vector copy (if they align correctly) and/or OpVectorShuffle, but it can get quite complex to handle all cases\n        //       However, it is probably optimized by SPIRV-Cross or the compiler/driver, so maybe not worth optimzing (due to increased code cases/complexity)\n        var elementIndex = 0;\n        for (int i = 0; i < Values.Count; i++)\n        {\n            // Note: we can compute expected element type only if there are as many source values as expected elements\n            // i.e. float3(float, float, float) is OK but float3(float, float2) is not as we don't know which element will be which before compiling them (we would need 2-pass compilation for that)\n            var value = Values[i].CompileAsValue(table, compiler, expectedElementType);\n            var valueType = Values[i].ValueType;\n\n            // We expand elements, because float4 can be created from (float, float2, float), or (float2x2)\n            if (Type is ScalarType or VectorType or MatrixType)\n            {","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Parsing/SDSL/AST/Literals.cs#L167-L203","documentation":"VectorLiteral.CompileImpl flattens a composite literal into scalars for SPIR-V emission. Only VectorType, MatrixType, and ArrayType have defined composite layouts; any other literal Type cannot be decomposed and throws this NotSupportedException.","triggerScenarios":"A literal expression whose Type is a scalar or custom composite (not vector/matrix/array) enters the composite compilation path — typically a malformed or wrongly-typed literal in parsed SDSL code.","commonSituations":"Parser/AST bugs where a literal's Type was not narrowed to a composite; user code attempting an aggregate initializer on a non-aggregate type that survived type checking.","solutions":["Check the literal's declared type — it must be a vector, matrix, or array to use aggregate initializer syntax","Fix the expression so scalars are assigned directly rather than via composite literals","Report a parser bug if a valid composite literal reaches this path"],"exampleFix":"// before\nfloat x = { 1.0, 2.0 }; // scalar with composite literal\n// after\nfloat2 x = { 1.0, 2.0 };","handlingStrategy":"type-guard","validationCode":"// Ensure literal Type is a supported composite before compiling\nif (literal.Type is not (VectorType or MatrixType or ArrayType))\n    throw new NotSupportedException($\"Literal type {literal.Type} is not a composite\");","typeGuard":"bool IsCompositeLiteral(TypeBase t) => t is VectorType or MatrixType or ArrayType;","tryCatchPattern":"try { literal.Compile(context, builder); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"Unsupported composite type\")) { /* report invalid literal type */ }","preventionTips":["Only use aggregate initializer syntax on vector/matrix/array types","Assign scalars directly, not via brace-initializer lists","Guard parser paths so scalar literals never enter composite compilation"],"tags":["sdsl","literals","composite","spirv"],"backgroundTag":"type-mismatch","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}