1919#include "IRGEN/ir_gen_type.h"
2020#include "UTIL/ground.h"
2121#include "UTIL/trait.h"
22+ #include "UTIL/util.h"
2223
2324successful_t func_args_match (ast_func_t * func , ast_type_t * type_list , length_t type_list_length ){
2425 ast_type_t * arg_types = func -> arg_types ;
@@ -105,11 +106,13 @@ errorcode_t func_args_polymorphable(ir_builder_t *builder, ast_func_t *poly_temp
105106 length_t required_arity = poly_template -> arity ;
106107
107108 // Ensure argument supplied meet length requirements
108- if (
109- required_arity < type_list_length &&
110- !(poly_template -> traits & AST_FUNC_VARARG ) &&
111- (conform_mode & CONFORM_MODE_VARIADIC ? !(poly_template -> traits & AST_FUNC_VARIADIC ) : true)
112- ) return FAILURE ;
109+ if (required_arity < type_list_length ){
110+ if (!(poly_template -> traits & AST_FUNC_VARARG )){
111+ if (!(conform_mode & CONFORM_MODE_VARIADIC ) || !(poly_template -> traits & AST_FUNC_VARIADIC )){
112+ return FAILURE ;
113+ }
114+ }
115+ }
113116
114117 // Determine whether we are missing arguments
115118 bool requires_use_of_defaults = required_arity > type_list_length ;
@@ -150,7 +153,9 @@ errorcode_t func_args_polymorphable(ir_builder_t *builder, ast_func_t *poly_temp
150153 // Number of polymorphic paramater types that have been processed (used for cleanup)
151154 length_t i ;
152155
153- for (i = 0 ; i != required_arity ; i ++ ){
156+ length_t num_conforms = length_min (type_list_length , required_arity );
157+
158+ for (i = 0 ; i != num_conforms ; i ++ ){
154159 if (ast_type_has_polymorph (& poly_template_arg_types [i ]))
155160 res = ir_gen_polymorphable (builder -> compiler , builder -> object , & poly_template_arg_types [i ], & arg_types [i ], & catalog , true);
156161 else
@@ -176,17 +181,22 @@ errorcode_t func_args_polymorphable(ir_builder_t *builder, ast_func_t *poly_temp
176181 goto polymorphic_failure ;
177182 }
178183
179- bool meets_return_matching_requirement = ast_types_identical (gives , & concrete_return_type );
184+ bool matches_return_type = ast_types_identical (gives , & concrete_return_type );
180185 ast_type_free (& concrete_return_type );
181186
182- if (!meets_return_matching_requirement ){
187+ if (!matches_return_type ){
188+ compiler_panicf (builder -> compiler , gives -> source , "Unable to match requested return type with callee's return type" );
183189 res = FAILURE ;
184190 goto polymorphic_failure ;
185191 }
186192 }
187193
188- if (out_catalog ) * out_catalog = catalog ;
189- else ast_poly_catalog_free (& catalog );
194+ if (out_catalog ){
195+ * out_catalog = catalog ;
196+ } else {
197+ ast_poly_catalog_free (& catalog );
198+ }
199+
190200 free (arg_value_list_unmodified );
191201 return SUCCESS ;
192202
0 commit comments