mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-10 05:11:37 -07:00
Improve error bounds for check_comparison
This commit is contained in:
+3
-3
@@ -2397,7 +2397,7 @@ gb_internal void add_comparison_procedures_for_fields(CheckerContext *c, Type *t
|
||||
}
|
||||
|
||||
|
||||
gb_internal void check_comparison(CheckerContext *c, Operand *x, Operand *y, TokenKind op) {
|
||||
gb_internal void check_comparison(CheckerContext *c, Ast *node, Operand *x, Operand *y, TokenKind op) {
|
||||
if (x->mode == Addressing_Type && y->mode == Addressing_Type) {
|
||||
bool comp = are_types_identical(x->type, y->type);
|
||||
switch (op) {
|
||||
@@ -2485,7 +2485,7 @@ gb_internal void check_comparison(CheckerContext *c, Operand *x, Operand *y, Tok
|
||||
}
|
||||
|
||||
if (err_str != nullptr) {
|
||||
error(x->expr, "Cannot compare expression, %s", err_str);
|
||||
error(node, "Cannot compare expression, %s", err_str);
|
||||
x->type = t_untyped_bool;
|
||||
} else {
|
||||
if (x->mode == Addressing_Constant &&
|
||||
@@ -3498,7 +3498,7 @@ gb_internal void check_binary_expr(CheckerContext *c, Operand *x, Ast *node, Typ
|
||||
|
||||
|
||||
if (token_is_comparison(op.kind)) {
|
||||
check_comparison(c, x, y, op.kind);
|
||||
check_comparison(c, node, x, y, op.kind);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -978,19 +978,19 @@ gb_internal void check_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags
|
||||
|
||||
Operand a = lhs;
|
||||
Operand b = rhs;
|
||||
check_comparison(ctx, &a, &x, Token_LtEq);
|
||||
check_comparison(ctx, expr, &a, &x, Token_LtEq);
|
||||
if (a.mode == Addressing_Invalid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
check_comparison(ctx, &b, &x, upper_op);
|
||||
check_comparison(ctx, expr, &b, &x, upper_op);
|
||||
if (b.mode == Addressing_Invalid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Operand a1 = lhs;
|
||||
Operand b1 = rhs;
|
||||
check_comparison(ctx, &a1, &b1, Token_LtEq);
|
||||
check_comparison(ctx, expr, &a1, &b1, Token_LtEq);
|
||||
|
||||
add_to_seen_map(ctx, &seen, upper_op, x, lhs, rhs);
|
||||
|
||||
@@ -1029,7 +1029,7 @@ gb_internal void check_switch_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags
|
||||
|
||||
// NOTE(bill): the ordering here matters
|
||||
Operand z = y;
|
||||
check_comparison(ctx, &z, &x, Token_CmpEq);
|
||||
check_comparison(ctx, expr, &z, &x, Token_CmpEq);
|
||||
if (z.mode == Addressing_Invalid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
+7
-1
@@ -264,7 +264,7 @@ gb_internal bool show_error_on_line(TokenPos const &pos, TokenPos end) {
|
||||
ELLIPSIS_PADDING = 8 // `... ...`
|
||||
};
|
||||
|
||||
error_out("\t");
|
||||
error_out("\n\t");
|
||||
|
||||
terminal_set_colours(TerminalStyle_Bold, TerminalColour_White);
|
||||
|
||||
@@ -345,6 +345,9 @@ gb_internal void error_va(TokenPos const &pos, TokenPos end, char const *fmt, va
|
||||
} else if (global_error_collector.prev != pos) {
|
||||
global_error_collector.prev = pos;
|
||||
error_out_pos(pos);
|
||||
if (has_ansi_terminal_colours()) {
|
||||
error_out_coloured("Error: ", TerminalStyle_Normal, TerminalColour_Red);
|
||||
}
|
||||
error_out_va(fmt, va);
|
||||
error_out("\n");
|
||||
show_error_on_line(pos, end);
|
||||
@@ -395,6 +398,9 @@ gb_internal void error_no_newline_va(TokenPos const &pos, char const *fmt, va_li
|
||||
} else if (global_error_collector.prev != pos) {
|
||||
global_error_collector.prev = pos;
|
||||
error_out_pos(pos);
|
||||
if (has_ansi_terminal_colours()) {
|
||||
error_out_coloured("Error: ", TerminalStyle_Normal, TerminalColour_Red);
|
||||
}
|
||||
error_out_va(fmt, va);
|
||||
}
|
||||
mutex_unlock(&global_error_collector.mutex);
|
||||
|
||||
Reference in New Issue
Block a user