From c24c173101c2c124401af77d8c513a23efac3b7e Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Mon, 30 Oct 2017 11:17:20 -0700 Subject: Fix output for type cast when checking fails (#238) There were some cases where we would try to emit an `ErrorType` to the output HLSL, which obviously isn't allowed. This change tries to avoid emitting error types, and instead use the original expression when it is available. I tried adding a test case for the change, but I can't convince Slang to output matching line numbers for the error message; it seems like more work is needed on that front. --- source/slang/emit.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'source/slang/emit.cpp') diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 6b411a25d..d433d5e2f 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -1563,6 +1563,20 @@ struct EmitVisitor Emit(")"); } + void emitTypeOrExpr( + Type* type, + Expr* expr) + { + if (type && !type->As()) + { + EmitType(type); + } + else + { + emitTypeBasedOnExpr(expr, nullptr); + } + } + void emitSimpleConstructorCallExpr( RefPtr callExpr, EOpInfo outerPrec) @@ -1576,7 +1590,7 @@ struct EmitVisitor bool needClose = MaybeEmitParens(outerPrec, prec); Emit("("); - EmitType(callExpr->type); + emitTypeOrExpr(callExpr->type.type, callExpr->FunctionExpr); Emit(") "); EmitExprWithPrecedence(callExpr->Arguments[0], rightSide(outerPrec, prec)); @@ -1592,7 +1606,7 @@ struct EmitVisitor auto prec = kEOp_Postfix; bool needClose = MaybeEmitParens(outerPrec, prec); - EmitType(callExpr->type); + emitTypeOrExpr(callExpr->type.type, callExpr->FunctionExpr); emitSimpleCallArgs(callExpr); -- cgit v1.2.3