From 56fad6a19554b83f54c3cdf12b93510546346068 Mon Sep 17 00:00:00 2001 From: wooster0 Date: Thu, 8 May 2025 14:47:22 +0900 Subject: [PATCH] make error messages prettier Error messages never contain periods or grave accents. Get rid of the periods and use apostrophes instead in probably the only two error messages that had them. --- lib/std/zig/Ast.zig | 4 ++-- lib/std/zig/AstGen.zig | 4 ++-- .../Issue_6823_dont_allow_._to_be_followed_by_.zig | 2 +- test/cases/compile_errors/missing_parameter_name.zig | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/std/zig/Ast.zig b/lib/std/zig/Ast.zig index 7950df7152..d0e819e943 100644 --- a/lib/std/zig/Ast.zig +++ b/lib/std/zig/Ast.zig @@ -323,7 +323,7 @@ pub fn renderError(tree: Ast, parse_error: Error, stream: anytype) !void { .asterisk_after_ptr_deref => { // Note that the token will point at the `.*` but ideally the source // location would point to the `*` after the `.*`. - return stream.writeAll("'.*' cannot be followed by '*'. Are you missing a space?"); + return stream.writeAll("'.*' cannot be followed by '*'; are you missing a space?"); }, .chained_comparison_operators => { return stream.writeAll("comparison operators cannot be chained"); @@ -526,7 +526,7 @@ pub fn renderError(tree: Ast, parse_error: Error, stream: anytype) !void { return stream.writeAll("expected field initializer"); }, .mismatched_binary_op_whitespace => { - return stream.print("binary operator `{s}` has whitespace on one side, but not the other.", .{tree.tokenTag(parse_error.token).lexeme().?}); + return stream.print("binary operator '{s}' has whitespace on one side, but not the other", .{tree.tokenTag(parse_error.token).lexeme().?}); }, .invalid_ampersand_ampersand => { return stream.writeAll("ambiguous use of '&&'; use 'and' for logical AND, or change whitespace to ' & &' for bitwise AND"); diff --git a/lib/std/zig/AstGen.zig b/lib/std/zig/AstGen.zig index 55bc743951..b349903742 100644 --- a/lib/std/zig/AstGen.zig +++ b/lib/std/zig/AstGen.zig @@ -4299,12 +4299,12 @@ fn fnDeclInner( &[_]u32{ try astgen.errNoteNode( type_expr, - "if this is a name, annotate its type '{s}: T'", + "if this is a name, annotate its type: '{s}: T'", .{identifier_str}, ), try astgen.errNoteNode( type_expr, - "if this is a type, give it a name ': {s}'", + "if this is a type, give it a name: 'name: {s}'", .{identifier_str}, ), }, diff --git a/test/cases/compile_errors/Issue_6823_dont_allow_._to_be_followed_by_.zig b/test/cases/compile_errors/Issue_6823_dont_allow_._to_be_followed_by_.zig index 20c9528847..a1a57d1e97 100644 --- a/test/cases/compile_errors/Issue_6823_dont_allow_._to_be_followed_by_.zig +++ b/test/cases/compile_errors/Issue_6823_dont_allow_._to_be_followed_by_.zig @@ -7,4 +7,4 @@ fn foo() void { // backend=stage2 // target=native // -// :2:28: error: '.*' cannot be followed by '*'. Are you missing a space? +// :2:28: error: '.*' cannot be followed by '*'; are you missing a space? diff --git a/test/cases/compile_errors/missing_parameter_name.zig b/test/cases/compile_errors/missing_parameter_name.zig index 3e576a1a6d..29e2239eea 100644 --- a/test/cases/compile_errors/missing_parameter_name.zig +++ b/test/cases/compile_errors/missing_parameter_name.zig @@ -15,5 +15,5 @@ fn f1(x) u64 { // :1:7: error: missing parameter name // :4:7: error: missing parameter name // :7:7: error: missing parameter name or type -// :7:7: note: if this is a name, annotate its type 'x: T' -// :7:7: note: if this is a type, give it a name ': x' +// :7:7: note: if this is a name, annotate its type: 'x: T' +// :7:7: note: if this is a type, give it a name: 'name: x'