return NULL;
// NOTE: This check is safe because currently the arguments given without a name
- // always map to the beginning indidies of the argument array.
+ // always map to the beginning indicies of the argument array.
if (param->idx >= (u64) bh_arr_length(arg_arr)) {
OnyxToken* param_name = func->params[param->idx].local->token;
}
}
- if (param->idx <= (u64) bh_arr_length(func->params)) {
+ // This enables the following case:
+ //
+ // f :: (x: i32, $T: type_expr = i32) -> T { ... }
+ // f(10);
+ //
+ if (param->idx < (u64) bh_arr_length(func->params)) {
if (func->params[param->idx].default_value) {
return (AstTyped *) func->params[param->idx].default_value;
}
AstType *param_type_expr = func->params[param->idx].local->type_node;
if (param_type_expr == (AstType *) &basic_type_type_expr) {
if (!node_is_type((AstNode *) value)) {
- if (err_msg) *err_msg = "Expected type expression.";
+ if (err_msg)
+ // CLEANUP: Use a different allocator.
+ *err_msg = bh_aprintf(global_heap_allocator,
+ "Expected type expression here, got a '%s'.",
+ type_get_name(value->type));
return;
}
resolve_expression_type(value);
if ((value->flags & Ast_Flag_Comptime) == 0) {
- if (err_msg) *err_msg = "Expected compile-time known argument.";
+ if (err_msg) *err_msg = "Expected compile-time known argument here.";
return;
}
static SymresStatus symres_polyproc(AstFunction* pp) {
pp->flags |= Ast_Flag_Comptime;
pp->parent_scope_of_poly_proc = current_scope;
+
+ bh_arr_each(AstPolyParam, p, pp->poly_params) {
+ if (p->kind != PSK_Value) continue;
+
+ AstParam *param = &pp->params[p->idx];
+ if (param->default_value != NULL) {
+ SYMRES(expression, ¶m->default_value);
+ if (onyx_has_errors()) return Symres_Error;
+ }
+ }
+
return Symres_Success;
}