{"record":{"id":"ce2f26863dfb3371","repo":"stride3d/stride","slug":"unsupported-context-dependent-number-with-type-typeinst-op","errorCode":null,"errorMessage":"Unsupported context dependent number with type {typeInst.Op}","messagePattern":"Unsupported context dependent number with type (.+?)","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Context.Constants.cs","lineNumber":240,"sourceCode":"                    { Width: 64, Signedness: 1 } => operand.ToLiteral<long>(),\n                    _ => throw new NotImplementedException($\"Unsupported int width {type.Width}\"),\n                };\n                return true;\n            }\n            else if (typeInst.Op == Specification.Op.OpTypeFloat)\n            {\n                var type = new OpTypeFloat(typeInst);\n                value = type switch\n                {\n                    { Width: 16 } => operand.ToLiteral<Half>(),\n                    { Width: 32 } => operand.ToLiteral<float>(),\n                    { Width: 64 } => operand.ToLiteral<double>(),\n                    _ => throw new NotImplementedException($\"Unsupported float width {type.Width}\"),\n                };\n                return true;\n            }\n            else\n                throw new NotImplementedException($\"Unsupported context dependent number with type {typeInst.Op}\");\n        }\n\n        throw new Exception(\"Cannot find type instruction for id \" + typeId);\n    }\n\n    public SpirvValue CreateDefaultConstantComposite(SymbolType type)\n    {\n        // TODO: cache results (either here or even more generally for any composite constant even if non-zero)\n        return new(Buffer.AddData(new OpConstantNull(GetOrRegister(type), Bound++)));\n    }\n\n    public SpirvValue CreateConstantCompositeVectorRepeat(Literal literal, int size)\n    {\n        var value = CompileConstantLiteral(literal);\n        if (size == 1)\n            return value;\n\n        var type = new VectorType((ScalarType)ReverseTypes[value.TypeId], size);","sourceCodeStart":222,"sourceCodeEnd":258,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Context.Constants.cs#L222-L258","documentation":"When resolving an OpConstant/OpSpecConstant, the type instruction found for the constant's type id must be OpTypeInt or OpTypeFloat for the value to be extracted as a number. Any other type opcode (OpTypeBool, OpTypeVector, OpTypePointer, etc.) throws NotImplementedException naming the type opcode. Composites are handled earlier in the method, so reaching here means an unexpected scalar-ish type.","triggerScenarios":"A constant instruction whose Result Type is not an int/float/composite/bool type — e.g. an OpConstant typed as OpTypePointer, OpTypeStruct, or a mis-registered type id pointing to a non-number type instruction.","commonSituations":"Malformed or hand-written SPIR-V where constants are typed incorrectly; parser state where a type id resolves to the wrong instruction; modules with constants of types the evaluator never expected to see here.","solutions":["Validate the SPIR-V module so constants of non-numerical types are not emitted as OpConstant (e.g. pointers use OpConstantNull/OpUndef paths)","Add a case in TryGetConstantValue for the unexpected type opcode (e.g. route OpTypeBool to true/false handling)","Check for parser bugs causing type-id lookup to resolve to the wrong instruction (dump typeInst.Op at the throw site)"],"exampleFix":"// before\nelse\n    throw new NotImplementedException($\"Unsupported context dependent number with type {typeInst.Op}\");\n// after\nelse if (typeInst.Op == Specification.Op.OpTypeBool)\n{ value = operand.ToLiteral<byte>() != 0; return true; }\nelse\n    throw new NotImplementedException($\"Unsupported context dependent number with type {typeInst.Op}\");","handlingStrategy":"validation","validationCode":"// confirm a constant's result type is a numeric type before evaluation\nbool IsNumericConstant(SpirvBuffer buffer, Instruction constant)\n{\n    var typeId = constant.Data.Memory.Span[1];\n    return buffer.TryGetInstructionById(typeId, out var t) &&\n           t.Op is Specification.Op.OpTypeInt or Specification.Op.OpTypeFloat;\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    context.TryGetConstantValue(id, out var value, out var typeId);\n}\ncatch (NotImplementedException ex) when (ex.Message.Contains(\"Unsupported context dependent number\"))\n{\n    // handle composite/null constants through the dedicated paths instead\n}","preventionTips":["Never emit OpConstant for pointer/struct/vector types — use OpConstantNull/OpConstantComposite","Validate the module so type ids referenced by constants resolve to int/float/composite/bool types","Check parser ordering so composite constants are matched before falling into the numeric path"],"tags":["spirv","type-system","not-implemented","shader-compilation"],"backgroundTag":"type-mismatch","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"}