aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-03-17 18:34:37 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-03-17 18:34:37 -0400
commit748a3c0cf80cedb4d46db7cfbbc12a306b4d19da (patch)
treeccd106a37bf23da44aeb959ce30bdbc802bb54b8
parent3eae595c1749c8908e305a405f0767fb96c29acf (diff)
Fix 'when' expressions
-rw-r--r--compile.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/compile.c b/compile.c
index ddbcf74f..b476e80e 100644
--- a/compile.c
+++ b/compile.c
@@ -781,7 +781,7 @@ static CORD _compile_statement(env_t *env, ast_t *ast)
}
auto enum_t = Match(subject_t, EnumType);
- CORD code = CORD_all("WHEN(", compile(env, when->subject), ", when, {\n");
+ CORD code = CORD_all("WHEN(", compile(env, when->subject), ", _when_subject, {\n");
for (when_clause_t *clause = when->clauses; clause; clause = clause->next) {
if (clause->pattern->tag == Var) {
const char *clause_tag_name = Match(clause->pattern, Var)->name;
@@ -813,7 +813,7 @@ static CORD _compile_statement(env_t *env, ast_t *ast)
code_err(args->value, "This is not a valid variable to bind to");
const char *var_name = Match(args->value, Var)->name;
if (!streq(var_name, "_")) {
- code = CORD_all(code, compile_declaration(tag_type, compile(env, args->value)), " = when.", clause_tag_name, ";\n");
+ code = CORD_all(code, compile_declaration(tag_type, compile(env, args->value)), " = _when_subject.", clause_tag_name, ";\n");
scope = fresh_scope(scope);
set_binding(scope, Match(args->value, Var)->name, tag_type, CORD_EMPTY);
}
@@ -830,7 +830,7 @@ static CORD _compile_statement(env_t *env, ast_t *ast)
const char *var_name = Match(arg->value, Var)->name;
if (!streq(var_name, "_")) {
- code = CORD_all(code, compile_declaration(field->type, compile(env, arg->value)), " = when.", clause_tag_name, ".", field->name, ";\n");
+ code = CORD_all(code, compile_declaration(field->type, compile(env, arg->value)), " = _when_subject.", clause_tag_name, ".", field->name, ";\n");
set_binding(scope, Match(arg->value, Var)->name, field->type, CORD_EMPTY);
}
field = field->next;