diff --git a/symbol-table/src/types/functions/function.rs b/symbol-table/src/types/functions/function.rs index ffc35fde98..3c84176fdc 100644 --- a/symbol-table/src/types/functions/function.rs +++ b/symbol-table/src/types/functions/function.rs @@ -127,7 +127,9 @@ impl FunctionType { pub fn num_inputs(&self) -> usize { self.inputs .iter() - .fold(0, |acc, function_input| acc + function_input.count()) + .filter(|function_input| !function_input.is_self()) + .count() + // .fold(0, |acc, function_input| acc + function_input.arguments()) } /// @@ -139,13 +141,10 @@ impl FunctionType { } /// - /// Returns a vector of [&FunctionInputType] removing `self` and `mut self` inputs. + /// Returns an iterator of [&FunctionInputType] removing `self` and `mut self` inputs. /// - pub fn filter_self_inputs(&self) -> Vec<&FunctionInputType> { - self.inputs - .iter() - .filter(|input| !input.is_self()) - .collect::>() + pub fn filter_self_inputs(&self) -> impl Iterator { + self.inputs.iter().filter(|input| !input.is_self()) } } diff --git a/symbol-table/src/types/functions/function_input.rs b/symbol-table/src/types/functions/function_input.rs index 66a8180f98..cee5ed1df5 100644 --- a/symbol-table/src/types/functions/function_input.rs +++ b/symbol-table/src/types/functions/function_input.rs @@ -77,15 +77,6 @@ impl FunctionInputType { } } - /// - /// Returns `0` if the function input is a `self` or `mut self` keyword which does not have to - /// provided in a call to the function. - /// Returns `1` if a variable must be provided in a call to the function. - /// - pub fn count(&self) -> usize { - if self.is_self() { 0 } else { 1 } - } - /// /// Return a new `FunctionInputType` from a given `FunctionInput`. /// diff --git a/type-inference/src/objects/frame.rs b/type-inference/src/objects/frame.rs index e725bff39b..20b1c44612 100644 --- a/type-inference/src/objects/frame.rs +++ b/type-inference/src/objects/frame.rs @@ -1120,10 +1120,8 @@ impl Frame { } // Filter out `self` and `mut self` keywords. - let expected_inputs = function_type.filter_self_inputs(); - // Assert function inputs are correct types. - for (expected_input, actual_input) in expected_inputs.iter().zip(inputs) { + for (expected_input, actual_input) in function_type.filter_self_inputs().zip(inputs) { // Parse expected input type. let expected_type = expected_input.type_();