Skip to content

Commit

Permalink
Coerce 'case' expressions to the same type as 'condition'
Browse files Browse the repository at this point in the history
Some WGSL compilers complain if e.g. case expression is signed while
condition expression is unsigned.
Insert logic to coerce the case expression to be of the same type as the condition
expression.

This addresses issue shader-slang#4921.
  • Loading branch information
aleino-nv committed Sep 5, 2024
1 parent 1673cf9 commit 2e4a59a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions source/slang/slang-check-stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,11 @@ namespace Slang
}
else
{
// TODO: need to do some basic matching to ensure the type
// for the `case` is consistent with the type for the `switch`...
// Try to coerce the case expression to the same type as the condition
Expr* condition = switchStmt->condition;
expr = coerce(CoercionSite::General, condition->type, expr);
// Can't think of any cases where this would fail
SLANG_ASSERT(expr);
}

stmt->expr = expr;
Expand Down

0 comments on commit 2e4a59a

Please sign in to comment.