consistent reporting using our helpers.

This commit is contained in:
Luke Boswell 2025-06-23 12:25:16 +10:00
parent efe836d821
commit c67630533f
No known key found for this signature in database
GPG key ID: 54A7324B1B975757
30 changed files with 259 additions and 110 deletions

View file

@ -126,6 +126,7 @@ fn processSourceInternal(
// Get diagnostic Reports from CIR
const diagnostics = cir.getDiagnostics();
defer gpa.free(diagnostics);
for (diagnostics) |diagnostic| {
const report = cir.diagnosticToReport(diagnostic, gpa, source, filename) catch continue;
reports.append(report) catch continue;

View file

@ -500,33 +500,30 @@ fn processSnapshotFile(gpa: Allocator, snapshot_path: []const u8, maybe_fuzz_cor
for (parse_ast.tokenize_diagnostics.items) |diagnostic| {
tokenize_problems += 1;
// TODO implement `toReport` for tokenize
// var report: Report = try diagnostic.toReport(gpa, content.source);
// defer report.deinit();
// report.render(writer.any(), .plain_text) catch |err| {
// try writer.print("Error rendering report: {}\n", .{err});
// continue;
// };
try diagnostic.toStr(gpa, content.source, writer);
var report: Report = parse_ast.tokenizeDiagnosticToReport(diagnostic, gpa) catch |err| {
try writer.print("Error creating tokenize report: {}\n", .{err});
continue;
};
defer report.deinit();
report.render(writer.any(), .markdown) catch |err| {
try writer.print("Error rendering report: {}\n", .{err});
continue;
};
}
// Parser Diagnostics
for (parse_ast.parse_diagnostics.items) |diagnostic| {
parser_problems += 1;
// TODO implement `diagnosticToReport` for parser
// var report: Report = try parse_ast.diagnosticToReport(diagnostic, gpa);
// defer report.deinit();
// report.render(writer.any(), .plain_text) catch |err| {
// try writer.print("Error rendering report: {}\n", .{err});
// continue;
// };
const err_msg = try std.fmt.allocPrint(gpa, "PARSER: {s}\n", .{@tagName(diagnostic.tag)});
defer gpa.free(err_msg);
try writer.writeAll(err_msg);
var report: Report = parse_ast.parseDiagnosticToReport(diagnostic, gpa) catch |err| {
try writer.print("Error creating parse report: {}\n", .{err});
continue;
};
defer report.deinit();
report.render(writer.any(), .markdown) catch |err| {
try writer.print("Error rendering report: {}\n", .{err});
continue;
};
}
// Canonicalization Diagnostics
@ -535,7 +532,10 @@ fn processSnapshotFile(gpa: Allocator, snapshot_path: []const u8, maybe_fuzz_cor
for (diagnostics) |diagnostic| {
canonicalize_problems += 1;
var report: Report = try can_ir.diagnosticToReport(diagnostic, gpa, content.source, snapshot_path);
var report: Report = can_ir.diagnosticToReport(diagnostic, gpa, content.source, snapshot_path) catch |err| {
try writer.print("Error creating canonicalization report: {}\n", .{err});
continue;
};
defer report.deinit();
report.render(writer.any(), .markdown) catch |err| {
try writer.print("Error rendering report: {}\n", .{err});
@ -553,7 +553,7 @@ fn processSnapshotFile(gpa: Allocator, snapshot_path: []const u8, maybe_fuzz_cor
while (problems_itr.next()) |problem_idx| {
check_types_problem += 1;
const problem = solver.problems.problems.get(problem_idx);
var report: Report = try problem.buildReport(
var report: Report = problem.buildReport(
gpa,
&problem_buf,
&solver.snapshots,
@ -561,7 +561,10 @@ fn processSnapshotFile(gpa: Allocator, snapshot_path: []const u8, maybe_fuzz_cor
content.source,
snapshot_path,
&module_env,
);
) catch |err| {
try writer.print("Error creating type checking report: {}\n", .{err});
continue;
};
defer report.deinit();
report.render(writer.any(), .markdown) catch |err| {
try writer.print("Error rendering report: {}\n", .{err});

View file

@ -11,7 +11,9 @@ module []
var topLevelVar_ = 0
~~~
# PROBLEMS
PARSER: var_only_allowed_in_a_body
**PARSE ERROR**
A parsing error occurred.
# TOKENS
~~~zig
KwModule(1:1-1:7),OpenSquare(1:8-1:9),CloseSquare(1:9-1:10),Newline(1:1-1:1),

View file

@ -8,7 +8,9 @@ type=expr
3.14.15
~~~
# PROBLEMS
PARSER: expr_no_space_dot_int
**PARSE ERROR**
A parsing error occurred.
# TOKENS
~~~zig
Float(1:1-1:5),NoSpaceDotInt(1:5-1:8),EndOfFile(1:8-1:8),

View file

@ -8,8 +8,12 @@ type=expr
{ person & age: 31 }
~~~
# PROBLEMS
PARSER: expr_unexpected_token
PARSER: ty_anno_unexpected_token
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN TYPE ANNOTATION**
A parsing error occurred.
**UNDEFINED VARIABLE**
Nothing is named `person` in this scope.
Is there an `import` or `exposing` missing up-top?

View file

@ -26,11 +26,21 @@ type=expr
}
~~~
# PROBLEMS
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNDEFINED VARIABLE**
Nothing is named `x` in this scope.
Is there an `import` or `exposing` missing up-top?

View file

@ -8,7 +8,9 @@ type=expr
!isValid
~~~
# PROBLEMS
PARSER: expr_unexpected_token
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
# TOKENS
~~~zig
OpBang(1:1-1:2),LowerIdent(1:2-1:9),EndOfFile(1:9-1:9),

View file

@ -8,7 +8,9 @@ type=expr
1 ++ 2
~~~
# PROBLEMS
PARSER: expr_unexpected_token
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNKNOWN OPERATOR**
This looks like an operator, but it's not one I recognize!
Check the spelling and make sure you're using a valid Roc operator.

View file

@ -10,7 +10,9 @@ module []
foo = if tru then 0
~~~
# PROBLEMS
PARSER: no_else
**PARSE ERROR**
A parsing error occurred.
**UNKNOWN OPERATOR**
This looks like an operator, but it's not one I recognize!
Check the spelling and make sure you're using a valid Roc operator.

View file

@ -10,7 +10,9 @@ module []
foo = asd.0
~~~
# PROBLEMS
PARSER: expr_no_space_dot_int
**PARSE ERROR**
A parsing error occurred.
**UNKNOWN OPERATOR**
This looks like an operator, but it's not one I recognize!
Check the spelling and make sure you're using a valid Roc operator.

View file

@ -8,9 +8,15 @@ type=file
mo|%
~~~
# PROBLEMS
PARSER: missing_header
PARSER: pattern_unexpected_token
PARSER: expected_expr_bar
**MISSING HEADER**
Roc files must start with a module header like 'module [main]' or 'app [main] { pf: platform "..." }'.
**UNEXPECTED TOKEN IN PATTERN**
This token is not expected in a pattern.
**PARSE ERROR**
A parsing error occurred.
**INVALID STATEMENT**
The statement **expr** is not allowed at the top level.
Only definitions, type annotations, and imports are allowed at the top level.

View file

@ -8,25 +8,63 @@ type=file
modu:;::::::::::::::le[%
~~~
# PROBLEMS
PARSER: missing_header
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
PARSER: expected_expr_close_square_or_comma
**MISSING HEADER**
Roc files must start with a module header like 'module [main]' or 'app [main] { pf: platform "..." }'.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**PARSE ERROR**
A parsing error occurred.
**INVALID STATEMENT**
The statement **expr** is not allowed at the top level.
Only definitions, type annotations, and imports are allowed at the top level.

View file

@ -8,9 +8,12 @@ type=file
= "te
~~~
# PROBLEMS
TOKENIZE: (1:4-1:6) UnclosedString:
= "te
^^PARSER: missing_header
**UNCLOSED STRING**
This string is missing a closing quote.
**MISSING HEADER**
Roc files must start with a module header like 'module [main]' or 'app [main] { pf: platform "..." }'.
**INVALID STATEMENT**
The statement **expr** is not allowed at the top level.
Only definitions, type annotations, and imports are allowed at the top level.

View file

@ -8,7 +8,9 @@ type=file
F
~~~
# PROBLEMS
PARSER: missing_header
**MISSING HEADER**
Roc files must start with a module header like 'module [main]' or 'app [main] { pf: platform "..." }'.
# TOKENS
~~~zig
UpperIdent(1:1-1:2),EndOfFile(1:2-1:2),

View file

@ -8,7 +8,9 @@ type=file
modu
~~~
# PROBLEMS
PARSER: missing_header
**MISSING HEADER**
Roc files must start with a module header like 'module [main]' or 'app [main] { pf: platform "..." }'.
# TOKENS
~~~zig
LowerIdent(1:1-1:5),EndOfFile(1:5-1:5),

View file

@ -8,9 +8,15 @@ type=file
ff8.8.d
~~~
# PROBLEMS
PARSER: missing_header
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
**MISSING HEADER**
Roc files must start with a module header like 'module [main]' or 'app [main] { pf: platform "..." }'.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**INVALID STATEMENT**
The statement **expr** is not allowed at the top level.
Only definitions, type annotations, and imports are allowed at the top level.

View file

@ -8,10 +8,15 @@ type=file
||1
~~~
# PROBLEMS
TOKENIZE: (1:2-1:2) AsciiControl:
||1
^PARSER: missing_header
PARSER: expected_expr_bar
**ASCII CONTROL CHARACTER**
ASCII control characters are not allowed in Roc source code.
**MISSING HEADER**
Roc files must start with a module header like 'module [main]' or 'app [main] { pf: platform "..." }'.
**PARSE ERROR**
A parsing error occurred.
**INVALID STATEMENT**
The statement **expr** is not allowed at the top level.
Only definitions, type annotations, and imports are allowed at the top level.

View file

@ -13,11 +13,15 @@ foo =
"onmo %
~~~
# PROBLEMS
TOKENIZE: (2:6-2:6) MismatchedBrace:
]
^TOKENIZE: (6:6-6:12) UnclosedString:
"onmo %
^^^^^^PARSER: missing_header
**MISMATCHED BRACE**
This brace does not match the corresponding opening brace.
**UNCLOSED STRING**
This string is missing a closing quote.
**MISSING HEADER**
Roc files must start with a module header like 'module [main]' or 'app [main] { pf: platform "..." }'.
**INVALID STATEMENT**
The statement **expr** is not allowed at the top level.
Only definitions, type annotations, and imports are allowed at the top level.

View file

@ -12,13 +12,18 @@ foo =
"on (string 'onmo %')))
~~~
# PROBLEMS
TOKENIZE: (2:3-2:3) AsciiControl:
 ]
^TOKENIZE: (2:6-2:6) MismatchedBrace:
 ]
^TOKENIZE: (5:6-5:35) UnclosedString:
"on (string 'onmo %')))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^PARSER: missing_header
**ASCII CONTROL CHARACTER**
ASCII control characters are not allowed in Roc source code.
**MISMATCHED BRACE**
This brace does not match the corresponding opening brace.
**UNCLOSED STRING**
This string is missing a closing quote.
**MISSING HEADER**
Roc files must start with a module header like 'module [main]' or 'app [main] { pf: platform "..." }'.
**INVALID STATEMENT**
The statement **expr** is not allowed at the top level.
Only definitions, type annotations, and imports are allowed at the top level.

View file

@ -8,10 +8,15 @@ type=file
module P]F
~~~
# PROBLEMS
TOKENIZE: (1:9-1:9) OverClosedBrace:
module P]F
^PARSER: header_expected_open_square
PARSER: expected_colon_after_type_annotation
**OVER CLOSED BRACE**
There are too many closing braces here.
**PARSE ERROR**
A parsing error occurred.
**PARSE ERROR**
A parsing error occurred.
# TOKENS
~~~zig
KwModule(1:1-1:7),UpperIdent(1:8-1:9),UpperIdent(1:10-1:11),EndOfFile(1:11-1:11),

View file

@ -8,10 +8,18 @@ type=file
||(|(l888888888|
~~~
# PROBLEMS
PARSER: missing_header
PARSER: pattern_unexpected_token
PARSER: pattern_unexpected_token
PARSER: expected_expr_bar
**MISSING HEADER**
Roc files must start with a module header like 'module [main]' or 'app [main] { pf: platform "..." }'.
**UNEXPECTED TOKEN IN PATTERN**
This token is not expected in a pattern.
**UNEXPECTED TOKEN IN PATTERN**
This token is not expected in a pattern.
**PARSE ERROR**
A parsing error occurred.
**INVALID STATEMENT**
The statement **expr** is not allowed at the top level.
Only definitions, type annotations, and imports are allowed at the top level.

View file

@ -8,7 +8,9 @@ type=file
0{
~~~
# PROBLEMS
PARSER: missing_header
**MISSING HEADER**
Roc files must start with a module header like 'module [main]' or 'app [main] { pf: platform "..." }'.
**INVALID STATEMENT**
The statement **expr** is not allowed at the top level.
Only definitions, type annotations, and imports are allowed at the top level.

View file

@ -10,10 +10,18 @@ type=file
0u22
~~~
# PROBLEMS
PARSER: missing_header
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
PARSER: expr_unexpected_token
**MISSING HEADER**
Roc files must start with a module header like 'module [main]' or 'app [main] { pf: platform "..." }'.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**INVALID STATEMENT**
The statement **expr** is not allowed at the top level.
Only definitions, type annotations, and imports are allowed at the top level.

View file

@ -11,11 +11,18 @@ type=file
0_
~~~
# PROBLEMS
TOKENIZE: (2:3-2:3) LeadingZero:
0_0
^PARSER: missing_header
PARSER: expr_unexpected_token
PARSER: expr_no_space_dot_int
**LEADING ZERO**
Numbers cannot have leading zeros.
**MISSING HEADER**
Roc files must start with a module header like 'module [main]' or 'app [main] { pf: platform "..." }'.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**PARSE ERROR**
A parsing error occurred.
**INVALID STATEMENT**
The statement **expr** is not allowed at the top level.
Only definitions, type annotations, and imports are allowed at the top level.

View file

@ -8,8 +8,12 @@ type=file
0|
~~~
# PROBLEMS
PARSER: missing_header
PARSER: expected_expr_bar
**MISSING HEADER**
Roc files must start with a module header like 'module [main]' or 'app [main] { pf: platform "..." }'.
**PARSE ERROR**
A parsing error occurred.
**INVALID STATEMENT**
The statement **expr** is not allowed at the top level.
Only definitions, type annotations, and imports are allowed at the top level.

View file

@ -9,9 +9,15 @@ me = "luc"
foo = "hello ${namF
~~~
# PROBLEMS
PARSER: missing_header
PARSER: expr_unexpected_token
PARSER: string_expected_close_interpolation
**MISSING HEADER**
Roc files must start with a module header like 'module [main]' or 'app [main] { pf: platform "..." }'.
**UNEXPECTED TOKEN IN EXPRESSION**
This token is not expected in an expression.
**PARSE ERROR**
A parsing error occurred.
**INVALID STATEMENT**
The statement **expr** is not allowed at the top level.
Only definitions, type annotations, and imports are allowed at the top level.

View file

@ -9,7 +9,9 @@ type=file
.R
~~~
# PROBLEMS
PARSER: missing_header
**MISSING HEADER**
Roc files must start with a module header like 'module [main]' or 'app [main] { pf: platform "..." }'.
**NOT IMPLEMENTED**
This feature is not yet implemented: top-level type_anno

View file

@ -8,8 +8,12 @@ type=file
0 (
~~~
# PROBLEMS
PARSER: missing_header
PARSER: expected_expr_close_round_or_comma
**MISSING HEADER**
Roc files must start with a module header like 'module [main]' or 'app [main] { pf: platform "..." }'.
**PARSE ERROR**
A parsing error occurred.
**INVALID STATEMENT**
The statement **expr** is not allowed at the top level.
Only definitions, type annotations, and imports are allowed at the top level.

View file

@ -8,7 +8,9 @@ type=file
module
~~~
# PROBLEMS
PARSER: header_expected_open_square
**PARSE ERROR**
A parsing error occurred.
# TOKENS
~~~zig
KwModule(1:1-1:7),EndOfFile(1:7-1:7),