{"record":{"id":"c027945e9d90da05","repo":"stride3d/stride","slug":"unsupported-type-for-getelementtype-symbol","errorCode":null,"errorMessage":"Unsupported type for GetElementType: {symbol}","messagePattern":"Unsupported type for GetElementType: (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Builder.Expressions.cs","lineNumber":735,"sourceCode":"        };\n    }\n\n    public static SymbolType GetVectorOrScalar(this ScalarType scalar, int size)\n        => size == 1 ? scalar : new VectorType(scalar, size);\n\n    public static int GetElementCount(this SymbolType symbol) => symbol switch\n    {\n        ScalarType s => 1,\n        VectorType v => v.Size,\n        MatrixType m => m.Rows * m.Columns,\n        _ => throw new NotSupportedException($\"Unsupported type for GetElementCount: {symbol}\"),\n    };\n    public static ScalarType GetElementType(this SymbolType symbol) => symbol switch\n    {\n        ScalarType s => s,\n        VectorType v => v.BaseType,\n        MatrixType m => m.BaseType,\n        _ => throw new NotSupportedException($\"Unsupported type for GetElementType: {symbol}\"),\n    };\n    public static SymbolType WithElementType(this SymbolType symbol, ScalarType elementType) => symbol switch\n    {\n        ScalarType s => elementType,\n        VectorType v => v.BaseType == elementType ? v : v with { BaseType = elementType },\n        MatrixType m => m.BaseType == elementType ? m : m with { BaseType = elementType },\n        _ => throw new NotSupportedException($\"Unsupported type for WithElementType: {symbol}\"),\n    };\n    public static bool IsSignedInteger(this SymbolType symbol) => symbol is ScalarType { Type: Scalar.Int or Scalar.Int64 };\n    public static bool IsUnsignedInteger(this SymbolType symbol) => symbol is ScalarType { Type: Scalar.UInt or Scalar.UInt64 };\n    public static bool IsFloating(this SymbolType symbol) => symbol is ScalarType { Type: Scalar.Half or Scalar.Float or Scalar.Double };\n    public static bool IsInteger(this SymbolType symbol) => symbol.IsSignedInteger() || symbol.IsUnsignedInteger();\n    public static bool IsNumber(this SymbolType symbol) => symbol.IsInteger() || symbol.IsFloating();\n    public static bool IsSigned(this SymbolType symbol) => symbol.IsSignedInteger() || symbol.IsFloating();\n    public static bool IsUnsigned(this SymbolType symbol) => symbol.IsUnsignedInteger();\n    public static bool IsSignedIntegerVector(this SymbolType symbol)\n        => symbol.IsSignedInteger() || symbol is VectorType v && v.BaseType.IsSignedInteger();\n    public static bool IsUnsignedIntegerVector(this SymbolType symbol)","sourceCodeStart":717,"sourceCodeEnd":753,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Builder.Expressions.cs#L717-L753","documentation":"GetElementType returns the underlying ScalarType of a SymbolType (scalar itself, vector's base, matrix's base). It throws NotSupportedException when the SymbolType has no single element type — e.g. arrays, structs, images, samplers, or pointers.","triggerScenarios":"Calling GetElementType() on a non-numeric SymbolType (ArrayType, StructType, PointerType, ImageType, SamplerType) during SPIR-V type manipulation or instruction emission.","commonSituations":"Working with shader code that uses arrays or user-defined structs passed into helpers written for scalars/vectors/matrices, e.g. when rewriting load/store or cast instructions in the Stride shader parser.","solutions":["Check the type is numeric (Scalar/Vector/Matrix) before calling GetElementType.","For arrays, recurse: the element type of an array is the element type of its base type.","For structs, iterate members instead of asking for a single element type.","Add explicit handling for the failing SymbolType in the calling code path."],"exampleFix":"// before\nvar scalar = symbolType.GetElementType();\n// after\nvar scalar = symbolType switch\n{\n    ScalarType s => s,\n    VectorType v => v.BaseType,\n    MatrixType m => m.BaseType,\n    ArrayType a => a.BaseType.GetElementType(),\n    _ => throw new NotSupportedException($\"No element type for {symbolType}\")\n};","handlingStrategy":"type-guard","validationCode":"bool hasElementType = t is ScalarType or VectorType or MatrixType;","typeGuard":"static bool HasScalarElementType(SymbolType t) => t is ScalarType or VectorType or MatrixType;","tryCatchPattern":"try { var elem = symbol.GetElementType(); } catch (NotSupportedException) { /* route composite types to member-wise handling */ }","preventionTips":["Type-check before requesting an element type","Recurse into arrays explicitly when needed","Treat structs as aggregates, never single-element types","Extend the switch when new SymbolType kinds are introduced"],"tags":["spirv","shader-compiler","unsupported-type"],"backgroundTag":"unsupported-operation","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"}