diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-03-17 22:06:55 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-03-17 22:06:55 -0400 |
| commit | 6905f759e5cdbbfa7e16cf183d01ca1f8a858f71 (patch) | |
| tree | 40915c44938daa8e1acec1e0ecb204fae4db97a1 /typecheck.c | |
| parent | 146d3542d5f626099f4c30a0190b6e1d963e70f4 (diff) | |
Empty enums use a singleton instead of a constructor
Diffstat (limited to 'typecheck.c')
| -rw-r--r-- | typecheck.c | 8 |
1 files changed, 6 insertions, 2 deletions
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); } |
