Skip to content

Commit

Permalink
Fix output for type cast when checking fails (#238)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Tim Foley authored Oct 30, 2017
1 parent 4ab545b commit c24c173
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions source/slang/emit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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));
Expand All @@ -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);

Expand Down

0 comments on commit c24c173

Please sign in to comment.