{"record":{"id":"969c1c9737047ff5","repo":"stride3d/stride","slug":"unsupported-element-type-valuetype-in-composite-extraction","errorCode":null,"errorMessage":"Unsupported element type {valueType} in composite extraction","messagePattern":"Unsupported element type (.+?) in composite extraction","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Parsing/SDSL/AST/Literals.cs","lineNumber":212,"sourceCode":"        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            {\n                var sourceElementType = valueType!.GetElementType();\n                for (int j = 0; j < valueType!.GetElementCount(); ++j)\n                {\n                    SpirvValue extractedValue = valueType switch\n                    {\n                        MatrixType m => new(builder.InsertData(new OpCompositeExtract(context.GetOrRegister(sourceElementType), context.Bound++, value.Id, [j / m.Columns, j % m.Rows]))),\n                        VectorType v => new(builder.InsertData(new OpCompositeExtract(context.GetOrRegister(sourceElementType), context.Bound++, value.Id, [j]))),\n                        ScalarType s => value,\n                        _ => throw new NotSupportedException($\"Unsupported element type {valueType} in composite extraction\"),\n                    };\n                    // If too many elments, keep counting so that exception is still thrown a bit later, with total count\n                    var currentElementIndex = elementIndex++;\n                    if (currentElementIndex >= values.Length)\n                        continue;\n                    values[currentElementIndex] = builder.Convert(context, extractedValue, expectedElementType).Id;\n                }\n            }\n            else if (Type is ArrayType arrayType)\n            {\n                values[elementIndex++] = builder.Convert(context, value, expectedElementType).Id;\n            }\n        }\n\n        // Scalar splat: float3(x) means float3(x, x, x)\n        if (elementIndex == 1 && totalCount > 1 && Type is VectorType or MatrixType)\n        {\n            for (int j = 1; j < totalCount; ++j)","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Parsing/SDSL/AST/Literals.cs#L194-L230","documentation":"While extracting the j-th element of a composite value during literal compilation, the element's type must be a MatrixType, VectorType, or ScalarType to be lowered via OpCompositeExtract/convert. Other element types are rejected, so nested composites of unexpected kinds cannot be flattened.","triggerScenarios":"A composite literal contains elements whose resolved Spirv type is neither scalar, vector, nor matrix — e.g. arrays of arrays or struct-typed elements inside a vector/matrix/array literal.","commonSituations":"Nested aggregate initializers beyond the supported one-level flatten; array literals whose element type itself is an unsupported composite.","solutions":["Flatten nested aggregate literals manually into scalar expressions","Restrict literal element types to scalars (or vectors/matrices where supported)","Check that the literal's declared element type matches the actual sub-expression types"],"exampleFix":"// before\nfloat2x2 m = { float2[]{1,2}, float2[]{3,4} }; // nested array element\n// after\nfloat2x2 m = { 1, 2, 3, 4 }; // scalar elements","handlingStrategy":"type-guard","validationCode":"// Ensure every element expression compiles to a scalar/vector/matrix value\nbool AllSupportedElements(IEnumerable<TypeBase> elemTypes) =>\n    elemTypes.All(t => t is ScalarType or VectorType or MatrixType);","typeGuard":"bool IsExtractable(TypeBase t) => t is ScalarType or VectorType or MatrixType;","tryCatchPattern":"try { literal.Compile(context, builder); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"Unsupported element type\")) { /* flatten the initializer manually */ }","preventionTips":["Avoid deeply nested aggregate initializers; write scalar element lists","Match literal element expressions to the declared element type","Keep one-level flattening assumptions when writing initializers"],"tags":["sdsl","literals","composite","spirv"],"backgroundTag":"unsupported-dtype","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"}