Skip to content

make error messages prettier #23829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/std/zig/Ast.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions lib/std/zig/AstGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<name>: {s}'",
"if this is a type, give it a name: 'name: {s}'",
.{identifier_str},
),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?
4 changes: 2 additions & 2 deletions test/cases/compile_errors/missing_parameter_name.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<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'