aboutsummaryrefslogtreecommitdiff
path: root/typecheck.c
diff options
context:
space:
mode:
Diffstat (limited to 'typecheck.c')
-rw-r--r--typecheck.c8
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);
}