From 6905f759e5cdbbfa7e16cf183d01ca1f8a858f71 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 17 Mar 2024 22:06:55 -0400 Subject: Empty enums use a singleton instead of a constructor --- typecheck.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'typecheck.c') diff --git a/typecheck.c b/typecheck.c index 6c26dc43..4a73b32d 100644 --- a/typecheck.c +++ b/typecheck.c @@ -165,8 +165,12 @@ void bind_statement(env_t *env, ast_t *statement) type->__data.EnumType.opaque = false; for (tag_t *tag = tags; tag; tag = tag->next) { - type_t *constructor_t = Type(FunctionType, .args=Match(tag->type, StructType)->fields, .ret=type); - set_binding(ns_env, tag->name, new(binding_t, .type=constructor_t, .code=CORD_all(env->file_prefix, def->name, "$tagged$", tag->name))); + if (Match(tag->type, StructType)->fields) { // Constructor: + type_t *constructor_t = Type(FunctionType, .args=Match(tag->type, StructType)->fields, .ret=type); + set_binding(ns_env, tag->name, new(binding_t, .type=constructor_t, .code=CORD_all(env->file_prefix, def->name, "$tagged$", tag->name))); + } else { // Empty singleton value: + set_binding(ns_env, tag->name, new(binding_t, .type=type, .code=CORD_all(env->file_prefix, def->name, "$tagged$", tag->name))); + } Table_str_set(env->types, heap_strf("%s$%s", def->name, tag->name), tag->type); } -- cgit v1.2.3