| author | |
| committer | |
| log | 46ddd5f5f4db7977010f78129fade7dfa5b9d8d3 |
| tree | 1247e46cfd016c69e23620f9370670fe02caad4b |
| parent | c2db077574be841da586fa62d67619c901dd535d |
| signature |
closes #19353 files changed, 29 insertions(+), 5 deletions(-)
src/ir.cpp+7-4| ... | ... | @@ -11510,10 +11510,13 @@ static IrInstruction *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructio |
| 11510 | 11510 | return ir_unreach_error(ira); |
| 11511 | 11511 | |
| 11512 | 11512 | IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->explicit_return_type); |
| 11513 | if (type_is_invalid(casted_value->value.type) && ira->explicit_return_type_source_node != nullptr) { | |
| 11514 | ErrorMsg *msg = ira->codegen->errors.last(); | |
| 11515 | add_error_note(ira->codegen, msg, ira->explicit_return_type_source_node, | |
| 11516 | buf_sprintf("return type declared here")); | |
| 11513 | if (type_is_invalid(casted_value->value.type)) { | |
| 11514 | AstNode *source_node = ira->explicit_return_type_source_node; | |
| 11515 | if (source_node != nullptr) { | |
| 11516 | ErrorMsg *msg = ira->codegen->errors.last(); | |
| 11517 | add_error_note(ira->codegen, msg, source_node, | |
| 11518 | buf_sprintf("return type declared here")); | |
| 11519 | } | |
| 11517 | 11520 | return ir_unreach_error(ira); |
| 11518 | 11521 | } |
| 11519 | 11522 |
test/compile_errors.zig+7| ... | ... | @@ -1,6 +1,13 @@ |
| 1 | 1 | const tests = @import("tests.zig"); |
| 2 | 2 | |
| 3 | 3 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4 | cases.addTest( | |
| 5 | "return invalid type from test", | |
| 6 | \\test "example" { return 1; } | |
| 7 | , | |
| 8 | ".tmp_source.zig:1:25: error: integer value 1 cannot be implicitly casted to type 'void'", | |
| 9 | ); | |
| 10 | ||
| 4 | 11 | cases.add( |
| 5 | 12 | "threadlocal qualifier on const", |
| 6 | 13 | \\threadlocal const x: i32 = 1234; |
test/tests.zig+15-1| ... | ... | @@ -538,6 +538,7 @@ pub const CompileErrorContext = struct { |
| 538 | 538 | expected_errors: ArrayList([]const u8), |
| 539 | 539 | link_libc: bool, |
| 540 | 540 | is_exe: bool, |
| 541 | is_test: bool, | |
| 541 | 542 | |
| 542 | 543 | const SourceFile = struct { |
| 543 | 544 | filename: []const u8, |
| ... | ... | @@ -596,7 +597,13 @@ pub const CompileErrorContext = struct { |
| 596 | 597 | var zig_args = ArrayList([]const u8).init(b.allocator); |
| 597 | 598 | zig_args.append(b.zig_exe) catch unreachable; |
| 598 | 599 | |
| 599 | zig_args.append(if (self.case.is_exe) "build-exe" else "build-obj") catch unreachable; | |
| 600 | if (self.case.is_exe) { | |
| 601 | try zig_args.append("build-exe"); | |
| 602 | } else if (self.case.is_test) { | |
| 603 | try zig_args.append("test"); | |
| 604 | } else { | |
| 605 | try zig_args.append("build-obj"); | |
| 606 | } | |
| 600 | 607 | zig_args.append(b.pathFromRoot(root_src)) catch unreachable; |
| 601 | 608 | |
| 602 | 609 | zig_args.append("--name") catch unreachable; |
| ... | ... | @@ -699,6 +706,7 @@ pub const CompileErrorContext = struct { |
| 699 | 706 | .expected_errors = ArrayList([]const u8).init(self.b.allocator), |
| 700 | 707 | .link_libc = false, |
| 701 | 708 | .is_exe = false, |
| 709 | .is_test = false, | |
| 702 | 710 | }; |
| 703 | 711 | |
| 704 | 712 | tc.addSourceFile(".tmp_source.zig", source); |
| ... | ... | @@ -726,6 +734,12 @@ pub const CompileErrorContext = struct { |
| 726 | 734 | self.addCase(tc); |
| 727 | 735 | } |
| 728 | 736 | |
| 737 | pub fn addTest(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void { | |
| 738 | const tc = self.create(name, source, expected_lines); | |
| 739 | tc.is_test = true; | |
| 740 | self.addCase(tc); | |
| 741 | } | |
| 742 | ||
| 729 | 743 | pub fn addCase(self: *CompileErrorContext, case: *const TestCase) void { |
| 730 | 744 | const b = self.b; |
| 731 | 745 |