diff options
| author | Tim Foley <tfoleyNV@users.noreply.github.com> | 2017-10-30 11:17:20 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-10-30 11:17:20 -0700 |
| commit | c24c173101c2c124401af77d8c513a23efac3b7e (patch) | |
| tree | 62878bd6a88f7535667c73beaa514aa69e8df869 | |
| parent | 4ab545bcd0716cc3f2da432a921c1f53fdce7925 (diff) | |
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.
| -rw-r--r-- | source/slang/emit.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
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<ErrorType>()) + { + EmitType(type); + } + else + { + emitTypeBasedOnExpr(expr, nullptr); + } + } + void emitSimpleConstructorCallExpr( RefPtr<InvokeExpr> 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); |
