From 839abfc29425873f5610467b8facac44ad784e19 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Mon, 10 Mar 2025 13:40:58 -0400 Subject: Be more conservative about disallowing constructors as top-level initializers --- typecheck.c | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) (limited to 'typecheck.c') diff --git a/typecheck.c b/typecheck.c index 9d3fab76..16863f08 100644 --- a/typecheck.c +++ b/typecheck.c @@ -1549,26 +1549,7 @@ PUREFUNC bool is_constant(env_t *env, ast_t *ast) } } case Use: return true; - case FunctionCall: { - // Constructors are allowed: - auto call = Match(ast, FunctionCall); - if (call->fn->tag != Var) return false; - binding_t *b = get_binding(env, Match(call->fn, Var)->name); - if (b == NULL || b->type->tag != TypeInfoType) return false; - - type_t *t = Match(b->type, TypeInfoType)->type; - if (t->tag == IntType) { - return call->args->value->tag == Int; - } else if (t->tag == NumType) { - return call->args->value->tag == Num; - } - - for (arg_ast_t *arg = call->args; arg; arg = arg->next) { - if (!is_constant(env, arg->value)) - return false; - } - return true; - } + case FunctionCall: return false; case InlineCCode: return true; default: return false; } -- cgit v1.2.3