@@ -216,29 +216,77 @@ TypeCheckCallExpr::visit (FnPtr &type)
216
216
217
217
// method call checker
218
218
219
- void
220
- TypeCheckMethodCallExpr::visit (FnType &type)
219
+ TypeCheckMethodCallExpr::TypeCheckMethodCallExpr (
220
+ Analysis::NodeMapping call_mappings, std::vector<Argument> &args,
221
+ Location call_locus, Location receiver_locus, TyTy::BaseType *adjusted_self,
222
+ Resolver::TypeCheckContext *context)
223
+ : call_mappings (call_mappings), arguments (args), call_locus (call_locus),
224
+ receiver_locus (receiver_locus), adjusted_self (adjusted_self),
225
+ context (context), mappings (Analysis::Mappings::get ())
226
+ {}
227
+
228
+ BaseType *
229
+ TypeCheckMethodCallExpr::go (FnType *ref, HIR::MethodCallExpr &call,
230
+ TyTy::BaseType *adjusted_self,
231
+ Resolver::TypeCheckContext *context)
232
+ {
233
+ std::vector<Argument> args;
234
+ for (auto &arg : call.get_arguments ())
235
+ {
236
+ BaseType *argument_expr_tyty
237
+ = Resolver::TypeCheckExpr::Resolve (arg.get ());
238
+ if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
239
+ {
240
+ rust_error_at (arg->get_locus (),
241
+ " failed to resolve type for argument" );
242
+ return new ErrorType (ref->get_ref ());
243
+ }
244
+
245
+ Argument a (arg->get_mappings (), argument_expr_tyty, arg->get_locus ());
246
+ args.push_back (std::move (a));
247
+ }
248
+
249
+ TypeCheckMethodCallExpr checker (call.get_mappings (), args,
250
+ call.get_locus (),
251
+ call.get_receiver ()->get_locus (),
252
+ adjusted_self, context);
253
+ return checker.check (*ref);
254
+ }
255
+
256
+ BaseType *
257
+ TypeCheckMethodCallExpr::go (FnType *ref, Analysis::NodeMapping call_mappings,
258
+ std::vector<Argument> &args, Location call_locus,
259
+ Location receiver_locus,
260
+ TyTy::BaseType *adjusted_self,
261
+ Resolver::TypeCheckContext *context)
262
+ {
263
+ TypeCheckMethodCallExpr checker (call_mappings, args, call_locus,
264
+ receiver_locus, adjusted_self, context);
265
+ return checker.check (*ref);
266
+ }
267
+
268
+ BaseType *
269
+ TypeCheckMethodCallExpr::check (FnType &type)
221
270
{
222
271
Resolver::TypeCheckBase::unify_site (
223
- call.get_mappings ().get_hirid (), TyWithLocation (type.get_self_type ()),
224
- TyWithLocation (adjusted_self, call.get_receiver ()->get_locus ()),
225
- call.get_locus ());
272
+ call_mappings.get_hirid (), TyWithLocation (type.get_self_type ()),
273
+ TyWithLocation (adjusted_self, receiver_locus), call_locus);
226
274
227
275
// +1 for the receiver self
228
- size_t num_args_to_call = call. num_params () + 1 ;
276
+ size_t num_args_to_call = arguments. size () + 1 ;
229
277
if (num_args_to_call != type.num_params ())
230
278
{
231
- rust_error_at (call. get_locus () ,
279
+ rust_error_at (call_locus ,
232
280
" unexpected number of arguments %lu expected %lu" ,
233
- (unsigned long ) call. num_params () ,
281
+ (unsigned long ) num_args_to_call ,
234
282
(unsigned long ) type.num_params ());
235
- return ;
283
+ return new ErrorType (type. get_ref ()) ;
236
284
}
237
285
238
286
size_t i = 1 ;
239
- for (auto &argument : call. get_arguments () )
287
+ for (auto &argument : arguments )
240
288
{
241
- Location arg_locus = argument-> get_locus ();
289
+ Location arg_locus = argument. get_locus ();
242
290
243
291
auto fnparam = type.param_at (i);
244
292
HIR::Pattern *fn_param_pattern = fnparam.first ;
@@ -248,41 +296,31 @@ TypeCheckMethodCallExpr::visit (FnType &type)
248
296
? mappings->lookup_location (param_ty->get_ref ())
249
297
: fn_param_pattern->get_locus ();
250
298
251
- auto argument_expr_tyty
252
- = Resolver::TypeCheckExpr::Resolve (argument.get ());
253
- if (argument_expr_tyty->get_kind () == TyTy::TypeKind::ERROR)
254
- {
255
- rust_error_at (
256
- argument->get_locus (),
257
- " failed to resolve type for argument expr in CallExpr" );
258
- return ;
259
- }
260
-
261
- HirId coercion_side_id = argument->get_mappings ().get_hirid ();
299
+ auto argument_expr_tyty = argument.get_argument_type ();
300
+ HirId coercion_side_id = argument.get_mappings ().get_hirid ();
262
301
auto resolved_argument_type = Resolver::TypeCheckBase::coercion_site (
263
302
coercion_side_id, TyWithLocation (param_ty, param_locus),
264
- TyWithLocation (argument_expr_tyty, arg_locus), argument-> get_locus () );
303
+ TyWithLocation (argument_expr_tyty, arg_locus), arg_locus );
265
304
if (resolved_argument_type->get_kind () == TyTy::TypeKind::ERROR)
266
305
{
267
- rust_error_at (argument->get_locus (),
268
- " Type Resolution failure on parameter" );
269
- return ;
306
+ rust_error_at (arg_locus, " Type Resolution failure on parameter" );
307
+ return new ErrorType (type.get_ref ());
270
308
}
271
309
272
310
i++;
273
311
}
274
312
275
313
if (i != num_args_to_call)
276
314
{
277
- rust_error_at (call. get_locus () ,
315
+ rust_error_at (call_locus ,
278
316
" unexpected number of arguments %lu expected %lu" ,
279
- (unsigned long ) i, (unsigned long ) call. num_params ());
280
- return ;
317
+ (unsigned long ) i, (unsigned long ) arguments. size ());
318
+ return new ErrorType (type. get_ref ()) ;
281
319
}
282
320
283
321
type.monomorphize ();
284
322
285
- resolved = type.get_return_type ()->monomorphized_clone ();
323
+ return type.get_return_type ()->monomorphized_clone ();
286
324
}
287
325
288
326
} // namespace TyTy
0 commit comments