From 0c819b87835e2714c6a8f8a05aa596d88a05e30e Mon Sep 17 00:00:00 2001 From: David Mak Date: Wed, 10 Jul 2024 10:29:05 +0800 Subject: [PATCH] core/typecheck/typedef: Handle vararg parameters in unify_call --- nac3core/src/typecheck/typedef/mod.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/nac3core/src/typecheck/typedef/mod.rs b/nac3core/src/typecheck/typedef/mod.rs index cd1d89d2..9e829b59 100644 --- a/nac3core/src/typecheck/typedef/mod.rs +++ b/nac3core/src/typecheck/typedef/mod.rs @@ -3,7 +3,7 @@ use itertools::Itertools; use std::cell::RefCell; use std::collections::HashMap; use std::fmt::{self, Display}; -use std::iter::zip; +use std::iter::{repeat_with, zip}; use std::rc::Rc; use std::sync::{Arc, Mutex}; use std::{borrow::Cow, collections::HashSet}; @@ -650,6 +650,7 @@ impl Unifier { // Get details about the function signature/parameters. let num_params = signature.args.len(); + let is_vararg = signature.args.iter().any(|arg| arg.is_vararg); // Force the type vars in `b` and `signature' to be up-to-date. let b = self.instantiate_fun(b, signature); @@ -738,7 +739,7 @@ impl Unifier { }; // Check for "too many arguments" - if num_params < posargs.len() { + if !is_vararg && num_params < posargs.len() { let expected_min_count = signature.args.iter().filter(|param| param.is_required()).count(); let expected_max_count = num_params; @@ -762,7 +763,7 @@ impl Unifier { .collect(); // Now consume all positional arguments and typecheck them. - for (&arg_ty, param) in zip(posargs, signature.args.iter()) { + for (param, &arg_ty) in zip(signature.args.iter().chain(repeat_with(|| signature.args.iter().last().unwrap())), posargs) { // We will also use this opportunity to mark the corresponding `param_info` as having been supplied. let param_info = param_info_by_name.get_mut(¶m.name).unwrap(); param_info.has_been_supplied = true;