diff --git a/src/build_settings.cpp b/src/build_settings.cpp index a3873be82..ff372f418 100644 --- a/src/build_settings.cpp +++ b/src/build_settings.cpp @@ -288,7 +288,7 @@ struct BuildContext { bool ignore_warnings; bool warnings_as_errors; - bool show_error_line; + bool hide_error_line; bool ignore_lazy; bool ignore_llvm_build; @@ -1033,7 +1033,7 @@ gb_internal String get_fullpath_core(gbAllocator a, String path) { } gb_internal bool show_error_line(void) { - return build_context.show_error_line; + return !build_context.hide_error_line; } gb_internal bool has_asm_extension(String const &path) { diff --git a/src/check_expr.cpp b/src/check_expr.cpp index d7e7b29a4..f42483c86 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -1679,9 +1679,13 @@ gb_internal bool check_unary_op(CheckerContext *c, Operand *o, Token op) { case Token_Not: if (!is_type_boolean(type)) { + ERROR_BLOCK(); str = expr_to_string(o->expr); - error(op, "Operator '%.*s' is only allowed on boolean expression", LIT(op.string)); + error(op, "Operator '%.*s' is only allowed on boolean expressions", LIT(op.string)); gb_string_free(str); + if (is_type_integer(type)) { + error_line("\tSuggestion: Did you mean to use the bitwise not operator '~'?\n"); + } } break; diff --git a/src/error.cpp b/src/error.cpp index 33157948f..cb2aa4836 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -121,7 +121,26 @@ gb_internal void end_error_block(void) { isize n = global_error_collector.error_buffer.count; if (n > 0) { u8 *text = global_error_collector.error_buffer.data; - if (show_error_line() && n >= 2 && !(text[n-2] == '\n' && text[n-1] == '\n')) { + + bool add_extra_newline = false; + + if (show_error_line()) { + if (n >= 2 && !(text[n-2] == '\n' && text[n-1] == '\n')) { + add_extra_newline = true; + } + } else { + isize newline_count = 0; + for (isize i = 0; i < n; i++) { + if (text[i] == '\n') { + newline_count += 1; + } + } + if (newline_count > 1) { + add_extra_newline = true; + } + } + + if (add_extra_newline) { // add an extra new line as padding when the error line is being shown error_line("\n"); } @@ -198,12 +217,12 @@ gb_internal bool show_error_on_line(TokenPos const &pos, TokenPos end) { // TODO(bill): This assumes ASCII enum { - MAX_LINE_LENGTH = 76, + MAX_LINE_LENGTH = 80, MAX_TAB_WIDTH = 8, - ELLIPSIS_PADDING = 8 + ELLIPSIS_PADDING = 8 // `... ...` }; - error_out("\n\t"); + error_out("\t"); if (line.len+MAX_TAB_WIDTH+ELLIPSIS_PADDING > MAX_LINE_LENGTH) { i32 const half_width = MAX_LINE_LENGTH/2; i32 left = cast(i32)(offset); @@ -244,7 +263,7 @@ gb_internal bool show_error_on_line(TokenPos const &pos, TokenPos end) { } } - error_out("\n\n"); + error_out("\n"); return true; } return false; diff --git a/src/exact_value.cpp b/src/exact_value.cpp index fc4ae2155..1ab50800d 100644 --- a/src/exact_value.cpp +++ b/src/exact_value.cpp @@ -578,9 +578,7 @@ gb_internal ExactValue exact_unary_operator_value(TokenKind op, ExactValue v, i3 } } -failure: - GB_PANIC("Invalid unary operation, %.*s", LIT(token_strings[op])); - +failure:; ExactValue error_value = {}; return error_value; } diff --git a/src/main.cpp b/src/main.cpp index 480930d4a..02996065a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -659,6 +659,7 @@ enum BuildFlagKind { BuildFlag_IgnoreWarnings, BuildFlag_WarningsAsErrors, + BuildFlag_TerseErrors, BuildFlag_VerboseErrors, BuildFlag_ErrorPosStyle, @@ -832,6 +833,7 @@ gb_internal bool parse_build_flags(Array args) { add_flag(&build_flags, BuildFlag_IgnoreWarnings, str_lit("ignore-warnings"), BuildFlagParam_None, Command_all); add_flag(&build_flags, BuildFlag_WarningsAsErrors, str_lit("warnings-as-errors"), BuildFlagParam_None, Command_all); + add_flag(&build_flags, BuildFlag_TerseErrors, str_lit("terse-errors"), BuildFlagParam_None, Command_all); add_flag(&build_flags, BuildFlag_VerboseErrors, str_lit("verbose-errors"), BuildFlagParam_None, Command_all); add_flag(&build_flags, BuildFlag_ErrorPosStyle, str_lit("error-pos-style"), BuildFlagParam_String, Command_all); @@ -1462,8 +1464,13 @@ gb_internal bool parse_build_flags(Array args) { } break; } + + case BuildFlag_TerseErrors: + build_context.hide_error_line = true; + break; case BuildFlag_VerboseErrors: - build_context.show_error_line = true; + gb_printf_err("-verbose-errors is not the default, -terse-errors can now disable it\n"); + build_context.hide_error_line = false; break; case BuildFlag_ErrorPosStyle: