diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index 8c3b36972848a66314c30f688e57cd46b27c4434..80cf2c2384e5bf2f619e58947a66d22db4d73ef3 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -96,27 +96,30 @@ impl ProtocolDescription { } let definition_id = definition_id.unwrap(); - let definition = &self.heap[definition_id]; - if !definition.is_component() { + let ast_definition = &self.heap[definition_id]; + if !ast_definition.is_component() { return Err(ComponentCreationError::DefinitionNotComponent); } // Make sure that the types of the provided value group matches that of // the expected types. - let definition = definition.as_component(); - if !definition.poly_vars.is_empty() { + let ast_definition = ast_definition.as_component(); + if !ast_definition.poly_vars.is_empty() { return Err(ComponentCreationError::DefinitionNotComponent); } - // - check number of arguments - let expr_data = self.types.get_procedure_expression_data(&definition_id, 0); - if expr_data.arg_types.len() != arguments.values.len() { + // - check number of arguments by retrieving the one instantiated + // monomorph + let concrete_type = ConcreteType{ parts: vec![ConcreteTypePart::Component(definition_id, 0)] }; + let mono_index = self.types.get_procedure_monomorph_index(&definition_id, &concrete_type.parts).unwrap(); + let mono_type = self.types.get_procedure_monomorph(mono_index); + if mono_type.arg_types.len() != arguments.values.len() { return Err(ComponentCreationError::InvalidNumArguments); } // - for each argument try to make sure the types match for arg_idx in 0..arguments.values.len() { - let expected_type = &expr_data.arg_types[arg_idx]; + let expected_type = &mono_type.arg_types[arg_idx]; let provided_value = &arguments.values[arg_idx]; if !self.verify_same_type(expected_type, 0, &arguments, provided_value) { return Err(ComponentCreationError::InvalidArgumentType(arg_idx));