| author | |
| committer | |
| log | 1b0f4d59763e273901717199e47764745aed2631 |
| tree | 5288ec6ed5493cc216bca92c8c700ce3ca5650e8 |
| parent | 518ff33e64f3970e6fc053d2cffe0751e21b0700 |
| signature | Commit is signed but in an unrecognized format. |
2 files changed, 29 insertions(+), 5 deletions(-)
src/ir.cpp+13-1| ... | ... | @@ -67,6 +67,8 @@ enum ConstCastResultId { |
| 67 | 67 | struct ConstCastOnly; |
| 68 | 68 | struct ConstCastArg { |
| 69 | 69 | size_t arg_index; |
| 70 | ZigType *actual_param_type; | |
| 71 | ZigType *expected_param_type; | |
| 70 | 72 | ConstCastOnly *child; |
| 71 | 73 | }; |
| 72 | 74 | |
| ... | ... | @@ -8638,6 +8640,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 8638 | 8640 | if (arg_child.id != ConstCastResultIdOk) { |
| 8639 | 8641 | result.id = ConstCastResultIdFnArg; |
| 8640 | 8642 | result.data.fn_arg.arg_index = i; |
| 8643 | result.data.fn_arg.actual_param_type = actual_param_info->type; | |
| 8644 | result.data.fn_arg.expected_param_type = expected_param_info->type; | |
| 8641 | 8645 | result.data.fn_arg.child = allocate_nonzero<ConstCastOnly>(1); |
| 8642 | 8646 | *result.data.fn_arg.child = arg_child; |
| 8643 | 8647 | return result; |
| ... | ... | @@ -10483,6 +10487,15 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa |
| 10483 | 10487 | } |
| 10484 | 10488 | break; |
| 10485 | 10489 | } |
| 10490 | case ConstCastResultIdFnArg: { | |
| 10491 | ErrorMsg *msg = add_error_note(ira->codegen, parent_msg, source_node, | |
| 10492 | buf_sprintf("parameter %" ZIG_PRI_usize ": '%s' cannot cast into '%s'", | |
| 10493 | cast_result->data.fn_arg.arg_index, | |
| 10494 | buf_ptr(&cast_result->data.fn_arg.actual_param_type->name), | |
| 10495 | buf_ptr(&cast_result->data.fn_arg.expected_param_type->name))); | |
| 10496 | report_recursive_error(ira, source_node, cast_result->data.fn_arg.child, msg); | |
| 10497 | break; | |
| 10498 | } | |
| 10486 | 10499 | case ConstCastResultIdFnAlign: // TODO |
| 10487 | 10500 | case ConstCastResultIdFnCC: // TODO |
| 10488 | 10501 | case ConstCastResultIdFnVarArgs: // TODO |
| ... | ... | @@ -10490,7 +10503,6 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa |
| 10490 | 10503 | case ConstCastResultIdFnReturnType: // TODO |
| 10491 | 10504 | case ConstCastResultIdFnArgCount: // TODO |
| 10492 | 10505 | case ConstCastResultIdFnGenericArgCount: // TODO |
| 10493 | case ConstCastResultIdFnArg: // TODO | |
| 10494 | 10506 | case ConstCastResultIdFnArgNoAlias: // TODO |
| 10495 | 10507 | case ConstCastResultIdUnresolvedInferredErrSet: // TODO |
| 10496 | 10508 | case ConstCastResultIdAsyncAllocatorType: // TODO |
test/compile_errors.zig+16-4| ... | ... | @@ -1,6 +1,18 @@ |
| 1 | 1 | const tests = @import("tests.zig"); |
| 2 | 2 | |
| 3 | 3 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 4 | cases.add( | |
| 5 | "error note for function parameter incompatibility", | |
| 6 | \\fn do_the_thing(func: fn (arg: i32) void) void {} | |
| 7 | \\fn bar(arg: bool) void {} | |
| 8 | \\export fn entry() void { | |
| 9 | \\ do_the_thing(bar); | |
| 10 | \\} | |
| 11 | , | |
| 12 | ".tmp_source.zig:4:18: error: expected type 'fn(i32) void', found 'fn(bool) void", | |
| 13 | ".tmp_source.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32'", | |
| 14 | ); | |
| 15 | ||
| 4 | 16 | cases.add( |
| 5 | 17 | "cast negative value to unsigned integer", |
| 6 | 18 | \\comptime { |
| ... | ... | @@ -5248,8 +5260,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5248 | 5260 | \\export fn foo() void { |
| 5249 | 5261 | \\ asm volatile ("" : : [bar]"r"(3) : ""); |
| 5250 | 5262 | \\} |
| 5251 | , | |
| 5252 | ".tmp_source.zig:2:35: error: expected sized integer or sized float, found comptime_int", | |
| 5263 | , | |
| 5264 | ".tmp_source.zig:2:35: error: expected sized integer or sized float, found comptime_int", | |
| 5253 | 5265 | ); |
| 5254 | 5266 | |
| 5255 | 5267 | cases.add( |
| ... | ... | @@ -5257,7 +5269,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 5257 | 5269 | \\export fn foo() void { |
| 5258 | 5270 | \\ asm volatile ("" : : [bar]"r"(3.17) : ""); |
| 5259 | 5271 | \\} |
| 5260 | , | |
| 5261 | ".tmp_source.zig:2:35: error: expected sized integer or sized float, found comptime_float", | |
| 5272 | , | |
| 5273 | ".tmp_source.zig:2:35: error: expected sized integer or sized float, found comptime_float", | |
| 5262 | 5274 | ); |
| 5263 | 5275 | } |