{"record":{"id":"5f9d5a4a19ed7d39","repo":"stride3d/stride","slug":"unexpected-type-inputtype-for-asdouble","errorCode":null,"errorMessage":"Unexpected type {inputType} for asdouble","messagePattern":"Unexpected type (.+?) for asdouble","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/Parsing/SDSL/AST/IntrinsicImplementations.cs","lineNumber":55,"sourceCode":"            var packed = builder.Insert(new OpCompositeConstruct(uint2Type, context.Bound++, [x.Id, y.Id]));\n            var result = builder.Insert(new OpBitcast(doubleType, context.Bound++, packed.ResultId));\n            return new(result.ResultId, result.ResultType);\n        }\n        else if (inputType is VectorType v)\n        {\n            var uintType = context.GetOrRegister(ScalarType.UInt);\n            var components = new int[v.Size];\n            for (int i = 0; i < v.Size; i++)\n            {\n                var xi = builder.Insert(new OpCompositeExtract(uintType, context.Bound++, x.Id, [i]));\n                var yi = builder.Insert(new OpCompositeExtract(uintType, context.Bound++, y.Id, [i]));\n                var packed = builder.Insert(new OpCompositeConstruct(uint2Type, context.Bound++, [xi.ResultId, yi.ResultId]));\n                components[i] = builder.Insert(new OpBitcast(doubleType, context.Bound++, packed.ResultId)).ResultId;\n            }\n            var result = new SpirvValue(builder.InsertData(new OpCompositeConstruct(context.GetOrRegister(functionType.ReturnType), context.Bound++, [.. components])));\n            return result;\n        }\n        throw new InvalidOperationException($\"Unexpected type {inputType} for asdouble\");\n    }\n    public override SpirvValue CompileAsfloat16(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue x, TextLocation location = default) => CompileBitcastCall(table, context, builder, functionType.ReturnType, x);\n    public override SpirvValue CompileAsint16(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue x, TextLocation location = default) => CompileBitcastCall(table, context, builder, functionType.ReturnType, x);\n    public override SpirvValue CompileAsuint16(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue x, TextLocation location = default) => CompileBitcastCall(table, context, builder, functionType.ReturnType, x);\n\n    // Trigo\n    public override SpirvValue CompileSin(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue x, TextLocation location = default) => CompileGLSLFloatUnaryCall(table, context, builder, functionType.ReturnType, Specification.GLSLOp.GLSLSin, x);\n    public override SpirvValue CompileSinh(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue x, TextLocation location = default) => CompileGLSLFloatUnaryCall(table, context, builder, functionType.ReturnType, Specification.GLSLOp.GLSLSinh, x);\n    public override SpirvValue CompileAsin(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue x, TextLocation location = default) => CompileGLSLFloatUnaryCall(table, context, builder, functionType.ReturnType, Specification.GLSLOp.GLSLAsin, x);\n    public override SpirvValue CompileCos(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue x, TextLocation location = default) => CompileGLSLFloatUnaryCall(table, context, builder, functionType.ReturnType, Specification.GLSLOp.GLSLCos, x);\n    public override SpirvValue CompileCosh(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue x, TextLocation location = default) => CompileGLSLFloatUnaryCall(table, context, builder, functionType.ReturnType, Specification.GLSLOp.GLSLCosh, x);\n    public override SpirvValue CompileAcos(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue x, TextLocation location = default) => CompileGLSLFloatUnaryCall(table, context, builder, functionType.ReturnType, Specification.GLSLOp.GLSLAcos, x);\n    public override SpirvValue CompileTan(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue x, TextLocation location = default) => CompileGLSLFloatUnaryCall(table, context, builder, functionType.ReturnType, Specification.GLSLOp.GLSLTan, x);\n    public override SpirvValue CompileTanh(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue x, TextLocation location = default) => CompileGLSLFloatUnaryCall(table, context, builder, functionType.ReturnType, Specification.GLSLOp.GLSLTanh, x);\n    public override SpirvValue CompileAtan(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue x, TextLocation location = default) => CompileGLSLFloatUnaryCall(table, context, builder, functionType.ReturnType, Specification.GLSLOp.GLSLAtan, x);\n    public override SpirvValue CompileAtan2(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue x, SpirvValue y, TextLocation location = default) => CompileGLSLFloatBinaryCall(table, context, builder, functionType.ReturnType, Specification.GLSLOp.GLSLAtan2, x, y);\n    public override SpirvValue CompileSincos(SymbolTable table, SpirvContext context, SpirvBuilder builder, FunctionType functionType, SpirvValue x, SpirvValue s, SpirvValue c, TextLocation location = default)\n    {","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/Parsing/SDSL/AST/IntrinsicImplementations.cs#L37-L73","documentation":"CompileAsdouble implements the asdouble intrinsic by packing two 32-bit integers into a uint2 and bitcasting to double. If the input value's type is not one of the supported integer forms (uint/uint2 from asuint pairs), the method exhausts its branches and throws InvalidOperationException at IntrinsicImplementations.cs:55.","triggerScenarios":"Calling asdouble(x) with a float, double, int, vector-of-float, or any type other than the expected uint / uint2 low-high pair.","commonSituations":"Calling asdouble on a float variable, passing a scalar when a two-component pair is required, or on int inputs instead of the uint pair produced by asuint.","solutions":["Pass the two 32-bit halves as uints: `asdouble(asuint(low), asuint(high))` or a uint2 pair.","Do not pass float/double inputs to asdouble; convert to uint first with asuint.","If other input types should be supported, add a branch in CompileAsdouble before the final throw."],"exampleFix":"// before\ndouble d = asdouble(myFloat);\n// after\nuint2 packed = asuint(doubleValue); double d = asdouble(packed.x, packed.y);","handlingStrategy":"type-guard","validationCode":"// asdouble requires uint (or uint2) input produced by asuint\nif (input is not (ScalarType { Type: Scalar.UInt } or VectorType { BaseType: ScalarType { Type: Scalar.UInt } }))\n    throw new ShaderCompileHint(\"asdouble expects uint low/high pair\");","typeGuard":"static bool IsUintValue(BaseType t) => t.GetElementType() is ScalarType { Type: Scalar.UInt };","tryCatchPattern":"try { result = CompileIntrinsic(\"asdouble\", args, table, context, builder); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"for asdouble\"))\n{ diagnostics.Report(location, ex.Message); }","preventionTips":["Always derive asdouble inputs via asuint().","Never pass float/double/int directly to asdouble.","Document supported intrinsic signatures alongside the implementation."],"tags":["shader","intrinsics","spirv","bitcast"],"backgroundTag":"unsupported-dtype","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"}