Allow specifying args like func foo(xs:[Int] = [])
This commit is contained in:
parent
2acc9c1f96
commit
fadcb45baf
@ -2004,7 +2004,7 @@ CORD compile_arguments(env_t *env, ast_t *call_ast, arg_t *spec_args, arg_ast_t
|
||||
|
||||
if (spec_arg->default_val) {
|
||||
if (code) code = CORD_cat(code, ", ");
|
||||
code = CORD_cat(code, compile_maybe_incref(default_scope, spec_arg->default_val, get_type(env, spec_arg->default_val)));
|
||||
code = CORD_cat(code, compile_maybe_incref(default_scope, spec_arg->default_val, get_arg_type(env, spec_arg)));
|
||||
goto found_it;
|
||||
}
|
||||
|
||||
|
14
src/parse.c
14
src/parse.c
@ -2157,13 +2157,17 @@ arg_ast_t *parse_args(parse_ctx_t *ctx, const char **pos)
|
||||
const char *name = get_id(pos);
|
||||
if (!name) break;
|
||||
whitespace(pos);
|
||||
if (strncmp(*pos, "==", 2) != 0 && match(pos, "=")) {
|
||||
default_val = expect(ctx, *pos-1, pos, parse_term, "I expected a value after this '='");
|
||||
names = new(name_list_t, .name=name, .next=names);
|
||||
break;
|
||||
} else if (match(pos, ":")) {
|
||||
|
||||
if (match(pos, ":")) {
|
||||
type = expect(ctx, *pos-1, pos, parse_type, "I expected a type here");
|
||||
names = new(name_list_t, .name=name, .next=names);
|
||||
whitespace(pos);
|
||||
if (match(pos, "="))
|
||||
default_val = expect(ctx, *pos-1, pos, parse_term, "I expected a value after this '='");
|
||||
break;
|
||||
} else if (strncmp(*pos, "==", 2) != 0 && match(pos, "=")) {
|
||||
default_val = expect(ctx, *pos-1, pos, parse_term, "I expected a value after this '='");
|
||||
names = new(name_list_t, .name=name, .next=names);
|
||||
break;
|
||||
} else if (name) {
|
||||
names = new(name_list_t, .name=name, .next=names);
|
||||
|
Loading…
Reference in New Issue
Block a user