{"record":{"id":"1b4a0df4b5bd4d40","repo":"stride3d/stride","slug":"unsupported-type-vectororscalartype-for-swizzle-coalescing","errorCode":null,"errorMessage":"Unsupported type {vectorOrScalarType} for swizzle coalescing","messagePattern":"Unsupported type (.+?) for swizzle coalescing","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Parsing/SDSL/AST/Expression.cs","lineNumber":909,"sourceCode":"\n            accessChainIdCount = 0;\n        }\n\n        // If current and next accessors are swizzle, combine them\n        void CoalesceSwizzles(int i, SymbolType currentValueType, ref Expression accessor)\n        {\n            if (i + 1 < Accessors.Count\n                && currentValueType is PointerType { BaseType: VectorType or ScalarType } or VectorType or ScalarType\n                && Accessors[i] is Identifier { Name: var swizzle1 } id1 && id1.IsVectorSwizzle()\n                && Accessors[i + 1] is Identifier { Name: var swizzle2 } id2 && id2.IsVectorSwizzle())\n            {\n                var vectorOrScalarType = currentValueType is PointerType p ? p.BaseType : currentValueType;\n\n                (var size, ScalarType baseType) = vectorOrScalarType switch\n                {\n                    ScalarType s => (1, s),\n                    VectorType v => (v.Size, v.BaseType),\n                    _ => throw new NotSupportedException($\"Unsupported type {vectorOrScalarType} for swizzle coalescing\"),\n                };\n\n                var swizzleIndices = new int[swizzle1.Length];\n                for (int j = 0; j < swizzle1.Length; ++j)\n                {\n                    swizzleIndices[j] = ConvertSwizzle(swizzle1[j]);\n                    if (swizzleIndices[j] >= size)\n                        throw new InvalidOperationException($\"Swizzle {Accessors[i]} is out of bound for expression {ToString(i)} of type {vectorOrScalarType}\");\n                }\n\n                // Combine swizzles with previous ones\n                var newSwizzleIndices = new int[swizzle2.Length];\n                for (int j = 0; j < swizzle2.Length; ++j)\n                {\n                    newSwizzleIndices[j] = swizzleIndices[ConvertSwizzle(swizzle2[j])];\n                    if (newSwizzleIndices[j] >= size)\n                        throw new InvalidOperationException($\"Swizzle {Accessors[i + 1]} is out of bound for expression {ToString(i)} of type {currentValueType}\");\n                }","sourceCodeStart":891,"sourceCodeEnd":927,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Parsing/SDSL/AST/Expression.cs#L891-L927","documentation":"While coalescing consecutive swizzles (e.g. v.xy.zzz) the compiler extracts the underlying scalar/vector type to size the combined swizzle. If the operand's type is neither ScalarType nor VectorType (e.g. a matrix or other type), the switch's _ arm throws NotSupportedException.","triggerScenarios":"Chained swizzle access where the intermediate expression's resolved type is not scalar/vector — e.g. swizzling a matrix-typed or pointer-typed expression that isn't handled upstream.","commonSituations":"Shader code that double-swizzles after a matrix swizzle; type-inference producing an unexpected type; shader variants compiled with different resource types.","solutions":["Restructure the shader so the swizzled expression is a vector or scalar","Avoid chained swizzles on non-vector types; break into intermediate variables","Check the declared type of the expression being swizzled","Extend the type switch in Expression.cs if you own the compiler"],"exampleFix":"// before\nfloat x = m.xy.x; // m is a matrix\n// after\nfloat4 r = m[0];\nfloat x = r.x;","handlingStrategy":"type-guard","validationCode":"if (t is not (ScalarType or VectorType)) throw new InvalidOperationException($\"Swizzling requires scalar/vector, got {t}\");","typeGuard":"bool IsSwizzlable(Type t) => (t is PointerType p ? p.BaseType : t) is ScalarType or VectorType;","tryCatchPattern":"try { CoalesceSwizzles(expr); } catch (NotSupportedException e) when (e.Message.Contains(\"swizzle coalescing\")) { FallBackToSequentialAccess(expr); }","preventionTips":["Only apply chained swizzles to vector/scalar expressions","Check inferred types of intermediate expressions before swizzling"],"tags":["sdsl","shader","swizzle","unsupported-type"],"backgroundTag":"unsupported-dtype","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}