aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-03-10 13:40:58 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-03-10 13:40:58 -0400
commit839abfc29425873f5610467b8facac44ad784e19 (patch)
tree98641ce9b9f1395b1330ee3cdbb493e0ffefc734
parent7f75a34bcea9688f4bb0d5947f01063ff02c837b (diff)
Be more conservative about disallowing constructors as top-level
initializers
-rw-r--r--typecheck.c21
1 files changed, 1 insertions, 20 deletions
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;
}