{"record":{"id":"8790b1385020ac23","repo":"stride3d/stride","slug":"unsupported-literal-type-literal-gettype","errorCode":null,"errorMessage":"Unsupported literal type: {literal.GetType()}","messagePattern":"Unsupported literal type: (.+?)","errorType":"validation","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Context.Constants.cs","lineNumber":380,"sourceCode":"            {\n                //{ Signed: true, Size: 8 } => ScalarType.SByte,\n                //{ Signed: true, Size: 16 } => ScalarType.Short,\n                { Signed: true, Size: 32 } => ScalarType.Int,\n                { Signed: true, Size: 64 } => ScalarType.Int64,\n                //{ Signed: false, Size: 8 } => ScalarType.UByte,\n                //{ Signed: false, Size: 16 } => ScalarType.UShort,\n                { Signed: false, Size: 32 } => ScalarType.UInt,\n                { Signed: false, Size: 64 } => ScalarType.UInt64,\n                _ => throw new NotImplementedException(\"Unsupported integer suffix\")\n            },\n            FloatLiteral lit => lit.Suffix.Size switch\n            {\n                //16 => ScalarType.Half,\n                32 => ScalarType.Float,\n                64 => ScalarType.Double,\n                _ => throw new NotImplementedException(\"Unsupported float\")\n            },\n            _ => throw new NotSupportedException($\"Unsupported literal type: {literal.GetType()}\"),\n        };\n    }\n}\n","sourceCodeStart":362,"sourceCodeEnd":384,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Context.Constants.cs#L362-L384","documentation":"ComputeLiteralType's outer switch only recognizes BoolLiteral, IntegerLiteral, and FloatLiteral; any other Literal subtype throws NotSupportedException naming the literal's actual type. Unlike the blank NotImplementedException at CompileConstantLiteral line 312, this one includes the type name for diagnosis.","triggerScenarios":"Passing a Literal that is not one of the three built-in kinds into ComputeLiteralType — typically via CompileConstantLiteral with a custom/new Literal subclass whose Type was null.","commonSituations":"Custom Literal implementations added by extension code; internal refactors adding a Literal kind without updating ComputeLiteralType; test harnesses constructing placeholder literals.","solutions":["Use only BoolLiteral/IntegerLiteral/FloatLiteral with this API","Add a switch arm in ComputeLiteralType mapping the new Literal subtype to its ScalarType (and matching arms in CompileConstantLiteral)","Convert the custom literal into a supported built-in literal before compiling"],"exampleFix":"// before\nLiteral lit = new HalfLiteral(2.0f); // custom subtype\nComputeLiteralType(lit); // throws\n// after\nLiteral lit = new FloatLiteral(new(32, true, true), 2.0f, default);\nComputeLiteralType(lit); // ScalarType.Float","handlingStrategy":"type-guard","validationCode":"bool HasComputableScalarType(Literal lit) =>\n    lit is BoolLiteral or IntegerLiteral or FloatLiteral;","typeGuard":"static bool IsScalarLiteral(Literal l) => l is BoolLiteral or IntegerLiteral or FloatLiteral;","tryCatchPattern":"try\n{\n    var scalarType = SpirvContext.ComputeLiteralType(literal);\n}\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"Unsupported literal type\"))\n{\n    // convert to a built-in scalar literal and retry\n    var scalarType = SpirvContext.ComputeLiteralType(ToBuiltInLiteral(literal));\n}","preventionTips":["Pass only BoolLiteral/IntegerLiteral/FloatLiteral to ComputeLiteralType","When adding a Literal subtype, update ComputeLiteralType's switch together with CompileConstantLiteral's switches","Assign literal.Type before compilation to skip type inference for non-scalar literals","Convert composite/custom literals at the API boundary"],"tags":["literal","type-mismatch","not-supported","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"}