Преглед на файлове

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 <josh11b@users.noreply.github.com>
josh11b преди 1 година
родител
ревизия
0b209c3fbc
променени са 1 файла, в които са добавени 8 реда и са изтрити 6 реда
  1. 8 6
      toolchain/check/deduce.cpp

+ 8 - 6
toolchain/check/deduce.cpp

@@ -122,15 +122,17 @@ class DeductionWorklist {
     const auto& param_impls =
     const auto& param_impls =
         context_.facet_types().Get(params).impls_constraints;
         context_.facet_types().Get(params).impls_constraints;
     const auto& arg_impls = context_.facet_types().Get(args).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;
       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.
   // Adds a (param, arg) pair for an instruction argument, given its kind.