From 6e5fb2ac4e5b780c74f310446ddd80d571170b0d Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 12 Oct 2025 14:19:59 -0400 Subject: More code cleanups --- src/compile/assignments.c | 2 ++ src/compile/cli.c | 10 +++++++--- src/compile/functions.c | 3 --- 3 files changed, 9 insertions(+), 6 deletions(-) (limited to 'src/compile') diff --git a/src/compile/assignments.c b/src/compile/assignments.c index 921b5320..74d1b543 100644 --- a/src/compile/assignments.c +++ b/src/compile/assignments.c @@ -161,6 +161,7 @@ Text_t compile_lvalue(env_t *env, ast_t *ast) { container_t = value_type(container_t); type_t *index_t = get_type(env, index->index); if (container_t->tag == ListType) { + if (!index->index) code_err(ast, "This list needs an index"); Text_t target_code = compile_to_pointer_depth(env, index->indexed, 1, false); type_t *item_type = Match(container_t, ListType)->item_type; Text_t index_code = @@ -171,6 +172,7 @@ Text_t compile_lvalue(env_t *env, ast_t *ast) { return Texts("List_lvalue(", compile_type(item_type), ", ", target_code, ", ", index_code, ", ", (int64_t)(ast->start - ast->file->text), ", ", (int64_t)(ast->end - ast->file->text), ")"); } else if (container_t->tag == TableType) { + if (!index->index) code_err(ast, "This table needs an index"); DeclareMatch(table_type, container_t, TableType); if (table_type->default_value) { type_t *value_type = get_type(env, table_type->default_value); diff --git a/src/compile/cli.c b/src/compile/cli.c index f138bd78..4138b778 100644 --- a/src/compile/cli.c +++ b/src/compile/cli.c @@ -88,9 +88,13 @@ Text_t compile_cli_arg_call(env_t *env, Text_t fn_name, type_t *fn_type, const c for (arg_t *arg = fn_info->args; arg; arg = arg->next) { code = Texts(code, compile_declaration(arg->type, Texts("_$", Text$from_str(arg->name)))); if (arg->default_val) { - Text_t default_val = - arg->type ? compile_to_type(env, arg->default_val, arg->type) : compile(env, arg->default_val); - if (arg->type->tag != OptionalType) default_val = promote_to_optional(arg->type, default_val); + Text_t default_val; + if (arg->type) { + default_val = compile_to_type(env, arg->default_val, arg->type); + if (arg->type->tag != OptionalType) default_val = promote_to_optional(arg->type, default_val); + } else { + default_val = compile(env, arg->default_val); + } code = Texts(code, " = ", default_val); } else { code = Texts(code, " = ", compile_empty(arg->type)); diff --git a/src/compile/functions.c b/src/compile/functions.c index 757df073..4a2812ba 100644 --- a/src/compile/functions.c +++ b/src/compile/functions.c @@ -784,9 +784,6 @@ Text_t compile_function(env_t *env, Text_t name_code, ast_t *ast, Text_t *static } } - Text_t qualified_name = Text$from_str(function_name); - if (env->namespace && env->namespace->parent && env->namespace->name) - qualified_name = Texts(env->namespace->name, ".", qualified_name); return definition; } -- cgit v1.2.3