stride3d/stride · error · NotSupportedException
Unsupported literal type
Error message
Unsupported literal type: {literal.GetType()} What it means
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.
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
Example fix
// before Literal lit = new HalfLiteral(2.0f); // custom subtype ComputeLiteralType(lit); // throws // after Literal lit = new FloatLiteral(new(32, true, true), 2.0f, default); ComputeLiteralType(lit); // ScalarType.Float
Defensive patterns
Strategy: type-guard
Validate before calling
bool HasComputableScalarType(Literal lit) =>
lit is BoolLiteral or IntegerLiteral or FloatLiteral; Type guard
static bool IsScalarLiteral(Literal l) => l is BoolLiteral or IntegerLiteral or FloatLiteral;
Try / catch
try
{
var scalarType = SpirvContext.ComputeLiteralType(literal);
}
catch (NotSupportedException ex) when (ex.Message.Contains("Unsupported literal type"))
{
// convert to a built-in scalar literal and retry
var scalarType = SpirvContext.ComputeLiteralType(ToBuiltInLiteral(literal));
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Custom Literal implementations added by extension code; internal refactors adding a Literal kind without updating ComputeLiteralType; test harnesses constructing placeholder literals.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Unsupported literal type
- Second parameter of geometry shader must be a…
- Semantic requested with type but last time with
- Unsupported float
- Unsupported integer suffix
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/8790b1385020ac23.
Report an issue: GitHub.
Appendix: source
Thrown at sources/shaders/Stride.Shaders.Parsers/Spirv/Building/Context.Constants.cs:380
{
//{ Signed: true, Size: 8 } => ScalarType.SByte,
//{ Signed: true, Size: 16 } => ScalarType.Short,
{ Signed: true, Size: 32 } => ScalarType.Int,
{ Signed: true, Size: 64 } => ScalarType.Int64,
//{ Signed: false, Size: 8 } => ScalarType.UByte,
//{ Signed: false, Size: 16 } => ScalarType.UShort,
{ Signed: false, Size: 32 } => ScalarType.UInt,
{ Signed: false, Size: 64 } => ScalarType.UInt64,
_ => throw new NotImplementedException("Unsupported integer suffix")
},
FloatLiteral lit => lit.Suffix.Size switch
{
//16 => ScalarType.Half,
32 => ScalarType.Float,
64 => ScalarType.Double,
_ => throw new NotImplementedException("Unsupported float")
},
_ => throw new NotSupportedException($"Unsupported literal type: {literal.GetType()}"),
};
}
}
View on GitHub (pinned to 96fad776d2)