tint: Fix AInt -> AFloat implicit conversion from construction
Bug: tint:1581
Change-Id: I8c6a1e375130ab38ef52cb0d8dddaca03cc098da
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/100800
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/tint/resolver/const_eval_test.cc b/src/tint/resolver/const_eval_test.cc
index d515ac4..243b3b9 100644
--- a/src/tint/resolver/const_eval_test.cc
+++ b/src/tint/resolver/const_eval_test.cc
@@ -2982,6 +2982,32 @@
EXPECT_EQ(i2->ConstantValue()->As<u32>(), 2_u);
}
+TEST_F(ResolverConstEvalTest, Matrix_AFloat_Construct_From_AInt_Vectors) {
+ auto* c = Const("a", Construct(ty.mat(nullptr, 2, 2), //
+ Construct(ty.vec(nullptr, 2), Expr(1_a), Expr(2_a)),
+ Construct(ty.vec(nullptr, 2), Expr(3_a), Expr(4_a))));
+ WrapInFunction(c);
+
+ EXPECT_TRUE(r()->Resolve()) << r()->error();
+
+ auto* sem = Sem().Get(c);
+ ASSERT_NE(sem, nullptr);
+ EXPECT_TRUE(sem->Type()->Is<sem::Matrix>());
+ auto* cv = sem->ConstantValue();
+ EXPECT_TYPE(cv->Type(), sem->Type());
+ EXPECT_TRUE(cv->Index(0)->Type()->Is<sem::Vector>());
+ EXPECT_TRUE(cv->Index(0)->Index(0)->Type()->Is<sem::AbstractFloat>());
+ EXPECT_FALSE(cv->AllEqual());
+ EXPECT_FALSE(cv->AnyZero());
+ EXPECT_FALSE(cv->AllZero());
+ auto* c0 = cv->Index(0);
+ auto* c1 = cv->Index(1);
+ EXPECT_EQ(std::get<AFloat>(c0->Index(0)->Value()), 1.0);
+ EXPECT_EQ(std::get<AFloat>(c0->Index(1)->Value()), 2.0);
+ EXPECT_EQ(std::get<AFloat>(c1->Index(0)->Value()), 3.0);
+ EXPECT_EQ(std::get<AFloat>(c1->Index(1)->Value()), 4.0);
+}
+
////////////////////////////////////////////////////////////////////////////////////////////////////
// Unary op
////////////////////////////////////////////////////////////////////////////////////////////////////
diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc
index 4bb0634..1599334 100644
--- a/src/tint/resolver/resolver.cc
+++ b/src/tint/resolver/resolver.cc
@@ -1690,10 +1690,12 @@
const sem::Constant* value = nullptr;
auto stage = sem::EarliestStage(ctor_or_conv.target->Stage(), args_stage);
if (stage == sem::EvaluationStage::kConstant) {
- auto const_args =
- utils::Transform(args, [](auto* arg) { return arg->ConstantValue(); });
+ auto const_args = ConvertArguments(args, ctor_or_conv.target);
+ if (!const_args) {
+ return nullptr;
+ }
if (auto r = (const_eval_.*ctor_or_conv.const_eval_fn)(
- ctor_or_conv.target->ReturnType(), const_args, expr->source)) {
+ ctor_or_conv.target->ReturnType(), const_args.Get(), expr->source)) {
value = r.Get();
} else {
return nullptr;