diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc index 7eb4d28fad..da6cfe29fa 100644 --- a/src/tint/resolver/resolver.cc +++ b/src/tint/resolver/resolver.cc @@ -1592,7 +1592,17 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) { return builder_->create(arr, std::move(params), args_stage); }); - return arr_or_str_ctor(arr, call_target); + + auto* call = arr_or_str_ctor(arr, call_target); + if (!call) { + return nullptr; + } + + // Validation must occur after argument materialization in arr_or_str_ctor(). + if (!validator_.ArrayConstructor(expr, arr)) { + return nullptr; + } + return call; }, [&](const sem::Struct* str) -> sem::Call* { auto* call_target = utils::GetOrCreate( @@ -1611,7 +1621,17 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) { return builder_->create(str, std::move(params), args_stage); }); - return arr_or_str_ctor(str, call_target); + + auto* call = arr_or_str_ctor(str, call_target); + if (!call) { + return nullptr; + } + + // Validation must occur after argument materialization in arr_or_str_ctor(). + if (!validator_.StructureConstructor(expr, str)) { + return nullptr; + } + return call; }, [&](Default) { AddError("type is not constructible", expr->source); diff --git a/src/tint/resolver/validator.cc b/src/tint/resolver/validator.cc index d854447f0f..c7df529ad1 100644 --- a/src/tint/resolver/validator.cc +++ b/src/tint/resolver/validator.cc @@ -1495,28 +1495,21 @@ bool Validator::Call(const sem::Call* call, sem::Statement* current_statement) c bool is_call_stmt = current_statement && Is(current_statement->Declaration(), [&](auto* stmt) { return stmt->expr == expr; }); - - return Switch( - call->Target(), // - [&](const sem::TypeConversion*) { - if (is_call_stmt) { + if (is_call_stmt) { + return Switch( + call->Target(), // + [&](const sem::TypeConversion*) { AddError("type conversion evaluated but not used", call->Declaration()->source); return false; - } - return true; - }, - [&](const sem::TypeConstructor* ctor) { - if (is_call_stmt) { + }, + [&](const sem::TypeConstructor*) { AddError("type constructor evaluated but not used", call->Declaration()->source); return false; - } - return Switch( - ctor->ReturnType(), // - [&](const sem::Array* arr) { return ArrayConstructor(expr, arr); }, - [&](const sem::Struct* str) { return StructureConstructor(expr, str); }, - [&](Default) { return true; }); - }, - [&](Default) { return true; }); + }, + [&](Default) { return true; }); + } + + return true; } bool Validator::DiscardStatement(const sem::Statement* stmt,