diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-09-21 17:44:08 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-09-21 17:44:08 -0400 |
| commit | c941b9a3325228eba404455afea7ccea0da45095 (patch) | |
| tree | d4ca88c6848ac2e6ceee635bb87add87ba6d2322 /src | |
| parent | 1cec086a6034ad546977cae7aeaf4bb876d21970 (diff) | |
Fix tests
Diffstat (limited to 'src')
| -rw-r--r-- | src/compile/assertions.c | 7 | ||||
| -rw-r--r-- | src/compile/comparisons.c | 5 | ||||
| -rw-r--r-- | src/environment.c | 4 | ||||
| -rw-r--r-- | src/parse/statements.c | 2 | ||||
| -rw-r--r-- | src/typecheck.c | 2 |
5 files changed, 9 insertions, 11 deletions
diff --git a/src/compile/assertions.c b/src/compile/assertions.c index 3ea6bf1e..5746b21e 100644 --- a/src/compile/assertions.c +++ b/src/compile/assertions.c @@ -4,7 +4,6 @@ #include "../config.h" #include "../environment.h" #include "../stdlib/datatypes.h" -#include "../stdlib/print.h" #include "../stdlib/text.h" #include "../stdlib/util.h" #include "../typecheck.h" @@ -17,7 +16,7 @@ Text_t compile_assertion(env_t *env, ast_t *ast) { const char *failure = NULL; switch (expr->tag) { case And: { - DeclareMatch(and_, ast, And); + DeclareMatch(and_, expr, And); return Texts(compile_statement(env, WrapAST(ast, Assert, .expr = and_->lhs, .message = message)), compile_statement(env, WrapAST(ast, Assert, .expr = and_->rhs, .message = message))); } @@ -32,13 +31,13 @@ Text_t compile_assertion(env_t *env, ast_t *ast) { assert_comparison: { binary_operands_t cmp = BINARY_OPERANDS(expr); type_t *lhs_t = get_type(env, cmp.lhs); - type_t *rhs_t = get_type(env, cmp.rhs); + type_t *rhs_t = get_type(with_enum_scope(env, lhs_t), cmp.rhs); type_t *operand_t; if (cmp.lhs->tag == Int && is_numeric_type(rhs_t)) { operand_t = rhs_t; } else if (cmp.rhs->tag == Int && is_numeric_type(lhs_t)) { operand_t = lhs_t; - } else if (can_compile_to_type(env, cmp.rhs, lhs_t)) { + } else if (can_compile_to_type(with_enum_scope(env, lhs_t), cmp.rhs, lhs_t)) { operand_t = lhs_t; } else if (can_compile_to_type(env, cmp.lhs, rhs_t)) { operand_t = rhs_t; diff --git a/src/compile/comparisons.c b/src/compile/comparisons.c index 0f9a7ddd..ffa04b9d 100644 --- a/src/compile/comparisons.c +++ b/src/compile/comparisons.c @@ -20,20 +20,19 @@ static CONSTFUNC const char *comparison_operator(ast_e tag) { } Text_t compile_comparison(env_t *env, ast_t *ast) { - switch (ast->tag) { case Equals: case NotEquals: { binary_operands_t binop = BINARY_OPERANDS(ast); type_t *lhs_t = get_type(env, binop.lhs); - type_t *rhs_t = get_type(env, binop.rhs); + type_t *rhs_t = get_type(with_enum_scope(env, lhs_t), binop.rhs); type_t *operand_t; if (binop.lhs->tag == Int && is_numeric_type(rhs_t)) { operand_t = rhs_t; } else if (binop.rhs->tag == Int && is_numeric_type(lhs_t)) { operand_t = lhs_t; - } else if (can_compile_to_type(env, binop.rhs, lhs_t)) { + } else if (can_compile_to_type(with_enum_scope(env, lhs_t), binop.rhs, lhs_t)) { operand_t = lhs_t; } else if (can_compile_to_type(env, binop.lhs, rhs_t)) { operand_t = rhs_t; diff --git a/src/environment.c b/src/environment.c index 603a04d9..ccbe4a8f 100644 --- a/src/environment.c +++ b/src/environment.c @@ -573,10 +573,10 @@ env_t *fresh_scope(env_t *env) { } env_t *with_enum_scope(env_t *env, type_t *t) { - while (t->tag == OptionalType) + while (t && t->tag == OptionalType) t = Match(t, OptionalType)->type; - if (t->tag != EnumType) return env; + if (t == NULL || t->tag != EnumType) return env; env = fresh_scope(env); env_t *ns_env = Match(t, EnumType)->env; for (tag_t *tag = Match(t, EnumType)->tags; tag; tag = tag->next) { diff --git a/src/parse/statements.c b/src/parse/statements.c index c767ae0b..24917a76 100644 --- a/src/parse/statements.c +++ b/src/parse/statements.c @@ -111,7 +111,7 @@ ast_t *parse_debug_log(parse_ctx_t *ctx, const char *pos) { spaces(&pos); } REVERSE_LIST(values); - whitespace(ctx, &pos); + // whitespace(ctx, &pos); return NewAST(ctx->file, start, pos, DebugLog, .values = values); } diff --git a/src/typecheck.c b/src/typecheck.c index 308ed259..57a1b994 100644 --- a/src/typecheck.c +++ b/src/typecheck.c @@ -354,7 +354,7 @@ void bind_statement(env_t *env, ast_t *statement) { switch (statement->tag) { case DebugLog: { for (ast_list_t *value = Match(statement, DebugLog)->values; value; value = value->next) - prebind_statement(env, value->ast); + bind_statement(env, value->ast); break; } case Assert: { |
