diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-05-15 13:19:00 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-05-15 13:19:00 -0400 |
| commit | ae9cb9e7e33742773f088d7abe2076f6db4c6f9c (patch) | |
| tree | 639f7a40df9cd79974c16510c67851610969c583 /compile.c | |
| parent | dda0392dc6d61327b1d420aec7bd17a771ce1cfc (diff) | |
Allow returning enums without qualifiers
Diffstat (limited to 'compile.c')
| -rw-r--r-- | compile.c | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -572,6 +572,15 @@ CORD compile_statement(env_t *env, ast_t *ast) auto ret = Match(ast, Return)->value; assert(env->fn_ctx->return_type); if (ret) { + if (env->fn_ctx->return_type->tag == EnumType) { + env = fresh_scope(env); + env_t *ns_env = Match(env->fn_ctx->return_type, EnumType)->env; + for (tag_t *tag = Match(env->fn_ctx->return_type, EnumType)->tags; tag; tag = tag->next) { + if (get_binding(env, tag->name)) + continue; + set_binding(env, tag->name, get_binding(ns_env, tag->name)); + } + } type_t *ret_t = get_type(env, ret); CORD value = compile(env, ret); if (!promote(env, &value, ret_t, env->fn_ctx->return_type)) |
