tint: improve compile error when calling builder::Val with the wrong

type

Now that Val() creates a Vecor of Scalar, we get horrible template spew
if the input value is of the wrong type.

Bug: tint:1581
Change-Id: I464d369e25f6374d3ffce0ee4dc21723b7e533a9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/112323
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Antonio Maiorano
2022-11-30 16:02:45 +00:00
committed by Dawn LUCI CQ
parent 6e306d34b5
commit 171c542bf7
2 changed files with 18 additions and 0 deletions

View File

@@ -31,6 +31,7 @@
#include "src/tint/sem/expression.h"
#include "src/tint/sem/statement.h"
#include "src/tint/sem/variable.h"
#include "src/tint/traits.h"
#include "src/tint/utils/vector.h"
namespace tint::resolver {
@@ -793,6 +794,7 @@ constexpr bool IsValue = std::is_same_v<T, Value>;
/// Creates a Value of DataType<T> from a scalar `v`
template <typename T>
Value Val(T v) {
static_assert(traits::IsTypeIn<T, Scalar>, "v must be a Number of bool");
return Value::Create<T>(utils::Vector<Scalar, 1>{v});
}