From ae9cb9e7e33742773f088d7abe2076f6db4c6f9c Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 15 May 2024 13:19:00 -0400 Subject: Allow returning enums without qualifiers --- compile.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/compile.c b/compile.c index d52ef978..daed549c 100644 --- a/compile.c +++ b/compile.c @@ -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)) -- cgit v1.2.3