{"record":{"id":"e3962b3f91bd6237","repo":"stride3d/stride","slug":"unsupported-constant-vector-element-type-values-0-gettype","errorCode":null,"errorMessage":"Unsupported constant vector element type: {Values[0].GetType()}","messagePattern":"Unsupported constant vector element type: (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Builder.Class.cs","lineNumber":126,"sourceCode":"                    hashCode = (hashCode * 397) ^ (current.GetHashCode());\n            }\n\n            return hashCode;\n        }\n    }\n}\n\n// Constant vector (generated by TryGetConstantValue)\npublic class ConstantVector\n{\n    public required object[] Values;\n\n    public override string ToString()\n    {\n        var type = Values[0] switch\n        {\n            float => \"float\",\n            _ => throw new NotSupportedException($\"Unsupported constant vector element type: {Values[0].GetType()}\"),\n        };\n\n        return $\"{type}{Values.Length}({string.Join(\",\", Values)})\";\n    }\n}\n\n\npublic partial class SpirvBuilder\n{\n    public static void BuildInheritanceListWithoutSelf(IExternalShaderLoader shaderLoader, SpirvContext topLevelContext, ShaderClassInstantiation classSource, ReadOnlySpan<ShaderMacro> macros, SpirvContext declaringContext, List<ShaderClassInstantiation> inheritanceList, ResolveStep resolveStep)\n    {\n        // Build shader name mapping and collect generic parameter expressions\n        var shaderMapping = new Dictionary<int, ShaderClassInstantiation>();\n        // Map generic parameter index → resolved expression from classSource\n        ConstantExpression[]? resolvedGenericArgs = null;\n        string? declaringClassName = null;\n        // Also build import-level resolution: map shader name → its import's generic args (as expressions)\n        // Used to resolve GenericParamExpr that reference parent shaders' generics","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Builder.Class.cs#L108-L144","documentation":"ConstantVector.ToString() renders a SPIR-V constant vector back into SDSL source text. It only knows how to type float element values; any other element type (int, bool, double) hit the throw-all switch arm. The library throws NotSupportedException because printing a vector of that element type as SDSL is not implemented.","triggerScenarios":"Calling ToString() (directly or via ShaderClassInstantiation.ToClassNameWithGenerics / error messages / cache keys) on a ConstantVector whose Values[0] is not a float, e.g. an int or bool constant vector produced by TryGetConstantValue.","commonSituations":"A shader uses integer or boolean constant vectors (e.g. int2 coordinates, bool4 masks) as generic arguments; SDSL grammar/analysis produces a non-float constant vector which later gets stringified when building shader names or diagnostics.","solutions":["Use float-valued constant vectors (e.g. cast literals to float) when passing vectors as generic arguments.","Extend the switch in ConstantVector.ToString() to map int => \"int\", uint => \"uint\", bool => \"bool\" etc., mirroring SDSL vector type names.","If you own the input shader, replace the non-float vector generic with a float vector or a scalar constant."],"exampleFix":"// before\nvar type = Values[0] switch\n{\n    float => \"float\",\n    _ => throw new NotSupportedException(...),\n};\n// after\nvar type = Values[0] switch\n{\n    float => \"float\",\n    int => \"int\",\n    uint => \"uint\",\n    bool => \"bool\",\n    _ => throw new NotSupportedException($\"Unsupported constant vector element type: {Values[0].GetType()}\"),\n};","handlingStrategy":"validation","validationCode":"if (vector.Values.Length == 0 || vector.Values[0] is not float)\n    throw new ArgumentException($\"ConstantVector must be float-typed to stringify, got {vector.Values.FirstOrDefault()?.GetType()}\");","typeGuard":"bool IsStringifiable(ConstantVector v) => v.Values is { Length: > 0 } && v.Values[0] is float;","tryCatchPattern":"try { text = vector.ToString(); }\ncatch (NotSupportedException ex) { text = $\"<{ex.Message}>\"; /* fall back to non-string form */ }","preventionTips":["Only pass float constant vectors as SDSL generic arguments","Add unit tests covering ToString for each element type you use","Extend the switch when adding new supported vector element types"],"tags":["spirv","sdsl","unsupported-type","generic-arguments"],"backgroundTag":"unsupported-dtype","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"}