From 0b209c3fbc949a861f85c79ced81b509fcedeccc Mon Sep 17 00:00:00 2001 From: josh11b <15258583+josh11b@users.noreply.github.com> Date: Mon, 25 Nov 2024 15:50:56 -0800 Subject: [PATCH] Make facet type deduction more restrictive and correct (#4589) Previously it would allow interface mismatches. We only need to support the case where there is a single interface, though, which makes checking much more straightforward. Co-authored-by: Josh L --- toolchain/check/deduce.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/toolchain/check/deduce.cpp b/toolchain/check/deduce.cpp index 463160b90aa1..55d66d8edc94 100644 --- a/toolchain/check/deduce.cpp +++ b/toolchain/check/deduce.cpp @@ -122,15 +122,17 @@ class DeductionWorklist { const auto& param_impls = context_.facet_types().Get(params).impls_constraints; const auto& arg_impls = context_.facet_types().Get(args).impls_constraints; - if (param_impls.size() != arg_impls.size()) { - // TODO: Decide whether to error on this or just treat the parameter list - // as non-deduced. For now we treat it as non-deduced. + // TODO: Decide whether to error on these or just treat the parameter list + // as non-deduced. For now we treat it as non-deduced. + if (param_impls.size() != 1 || arg_impls.size() != 1) { return; } - for (auto [param, arg] : - llvm::reverse(llvm::zip_equal(param_impls, arg_impls))) { - Add(param.specific_id, arg.specific_id, needs_substitution); + auto param = param_impls.front(); + auto arg = arg_impls.front(); + if (param.interface_id != arg.interface_id) { + return; } + Add(param.specific_id, arg.specific_id, needs_substitution); } // Adds a (param, arg) pair for an instruction argument, given its kind.