diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2024-07-19 14:16:51 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2024-07-19 14:16:51 -0400 |
| commit | 907122a049572f02880713620e0e6b024a5cff7f (patch) | |
| tree | a89e1f3bea2e378498dc6423a8f4ebda64443139 /typecheck.c | |
| parent | d3f14cf53cf857b90184900a726e3ee0875dea80 (diff) | |
Fix for unqualified enum names as return values
Diffstat (limited to 'typecheck.c')
| -rw-r--r-- | typecheck.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/typecheck.c b/typecheck.c index 2639da73..e61873d1 100644 --- a/typecheck.c +++ b/typecheck.c @@ -739,6 +739,19 @@ type_t *get_type(env_t *env, ast_t *ast) } case Return: { ast_t *val = Match(ast, Return)->value; + // Support unqualified enum return values: + if (env->fn_ctx && env->fn_ctx->return_type->tag == EnumType) { + env = fresh_scope(env); + auto enum_ = Match(env->fn_ctx->return_type, EnumType); + env_t *ns_env = enum_->env; + for (tag_t *tag = enum_->tags; tag; tag = tag->next) { + if (get_binding(env, tag->name)) + continue; + binding_t *b = get_binding(ns_env, tag->name); + assert(b); + set_binding(env, tag->name, b); + } + } return Type(ReturnType, .ret=(val ? get_type(env, val) : Type(VoidType))); } case Stop: case Skip: case PrintStatement: { |
