-
Notifications
You must be signed in to change notification settings - Fork 77
Description
Describe the feature
For emitting events and calling functions, it is possible to use either unnamed or named arguments:
f(1, 2, 3)
f({ a: 1, b: 2, c: 3})
emit E(6, 7);
emit E({foo: 6, bar: 7})We want helpers to get named parameters for functions and events on Ty (and maybe also in Hir?). It is important to note that it is not currently possible to fully implement this for functions, so that should be stubbed out for now.
Additionally, we should have a helper function in the typechecker to match hir::CallArgs to function parameters. All the arguments must either be named, or unnamed. No mixing. If all arguments are unnamed, types are checked in sequence. Otherwise, named arguments must be matched to their named parameter counterpart.
Additional context
An example of how arguments are validated in sequence can be found here:
solar/crates/sema/src/typeck/checker.rs
Lines 787 to 808 in f6cf16d
| let ctor_param_types = self.gcx.item_parameter_types(ctor_id); | |
| // Check if arguments were provided and validate count | |
| if let Some(modifier) = modifier { | |
| let arg_count = modifier.args.exprs().len(); | |
| if arg_count != ctor_param_types.len() { | |
| self.dcx() | |
| .err(format!( | |
| "wrong number of arguments for base constructor: expected {}, found {}", | |
| ctor_param_types.len(), | |
| arg_count | |
| )) | |
| .span(modifier.span) | |
| .emit(); | |
| } else { | |
| for (arg_expr, expected_arg_ty) in | |
| modifier.args.exprs().zip(ctor_param_types.iter()) | |
| { | |
| let actual_arg_ty = | |
| self.check_expr_kind(arg_expr, Some(*expected_arg_ty)); | |
| self.check_expected(arg_expr, actual_arg_ty, *expected_arg_ty); | |
| } | |
| } |