diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-04-03 15:47:05 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-04-03 15:47:05 -0400 |
| commit | fadcb45baf1274e06cfe37b87655b9146aa52874 (patch) | |
| tree | 97d0368f99870e6ec5029f38c513f89af2737fe6 /src | |
| parent | 2acc9c1f968a9d8ac24df47c4cb7ecc44c7d3826 (diff) | |
Allow specifying args like `func foo(xs:[Int] = [])`
Diffstat (limited to 'src')
| -rw-r--r-- | src/compile.c | 2 | ||||
| -rw-r--r-- | src/parse.c | 12 |
2 files changed, 9 insertions, 5 deletions
diff --git a/src/compile.c b/src/compile.c index 6b465b20..95cf5c9a 100644 --- a/src/compile.c +++ b/src/compile.c @@ -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; } diff --git a/src/parse.c b/src/parse.c index 43cd150d..63f5deb0 100644 --- a/src/parse.c +++ b/src/parse.c @@ -2157,12 +2157,16 @@ 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 '='"); + + 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 (match(pos, ":")) { - type = expect(ctx, *pos-1, pos, parse_type, "I expected a type here"); + } 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) { |
