| author | |
| committer | |
| log | 21932a0ef25a7055cd3c0850fa58c2fda2ba383b |
| tree | bc154b72c1162381e4d0b560b43e68507b442997 |
| parent | b022db16ece48f2cdec47c5716601fec2fc07ef4 |
* Prevent the next_param_index to become greater than the param_count
one as it's expected by every other function.
* Fix a typo in a error message.
Closes #43813 files changed, 14 insertions(+), 3 deletions(-)
src/ir.cpp+2-2| ... | @@ -11864,7 +11864,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted | ... | @@ -11864,7 +11864,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted |
| 11864 | } | 11864 | } |
| 11865 | assert(wanted_type->data.fn.is_generic || | 11865 | assert(wanted_type->data.fn.is_generic || |
| 11866 | wanted_type->data.fn.fn_type_id.next_param_index == wanted_type->data.fn.fn_type_id.param_count); | 11866 | wanted_type->data.fn.fn_type_id.next_param_index == wanted_type->data.fn.fn_type_id.param_count); |
| 11867 | for (size_t i = 0; i < wanted_type->data.fn.fn_type_id.next_param_index; i += 1) { | 11867 | for (size_t i = 0; i < wanted_type->data.fn.fn_type_id.param_count; i += 1) { |
| 11868 | // note it's reversed for parameters | 11868 | // note it's reversed for parameters |
| 11869 | FnTypeParamInfo *actual_param_info = &actual_type->data.fn.fn_type_id.param_info[i]; | 11869 | FnTypeParamInfo *actual_param_info = &actual_type->data.fn.fn_type_id.param_info[i]; |
| 11870 | FnTypeParamInfo *expected_param_info = &wanted_type->data.fn.fn_type_id.param_info[i]; | 11870 | FnTypeParamInfo *expected_param_info = &wanted_type->data.fn.fn_type_id.param_info[i]; |
| ... | @@ -30285,7 +30285,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La | ... | @@ -30285,7 +30285,7 @@ static ZigType *ir_resolve_lazy_fn_type(IrAnalyze *ira, AstNode *source_node, La |
| 30285 | if (param_is_var_args) { | 30285 | if (param_is_var_args) { |
| 30286 | if (fn_type_id.cc == CallingConventionC) { | 30286 | if (fn_type_id.cc == CallingConventionC) { |
| 30287 | fn_type_id.param_count = fn_type_id.next_param_index; | 30287 | fn_type_id.param_count = fn_type_id.next_param_index; |
| 30288 | continue; | 30288 | break; |
| 30289 | } else if (fn_type_id.cc == CallingConventionUnspecified) { | 30289 | } else if (fn_type_id.cc == CallingConventionUnspecified) { |
| 30290 | return get_generic_fn_type(ira->codegen, &fn_type_id); | 30290 | return get_generic_fn_type(ira->codegen, &fn_type_id); |
| 30291 | } else { | 30291 | } else { |
src/parser.cpp+1-1| ... | @@ -806,7 +806,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc) { | ... | @@ -806,7 +806,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc) { |
| 806 | if (param_decl->data.param_decl.is_var_args) | 806 | if (param_decl->data.param_decl.is_var_args) |
| 807 | res->data.fn_proto.is_var_args = true; | 807 | res->data.fn_proto.is_var_args = true; |
| 808 | if (i != params.length - 1 && res->data.fn_proto.is_var_args) | 808 | if (i != params.length - 1 && res->data.fn_proto.is_var_args) |
| 809 | ast_error(pc, first, "Function prototype have varargs as a none last paramter."); | 809 | ast_error(pc, first, "Function prototype have varargs as a none last parameter."); |
| 810 | } | 810 | } |
| 811 | return res; | 811 | return res; |
| 812 | } | 812 | } |
test/compile_errors.zig+11| ... | @@ -3,6 +3,17 @@ const builtin = @import("builtin"); | ... | @@ -3,6 +3,17 @@ const builtin = @import("builtin"); |
| 3 | const Target = @import("std").Target; | 3 | const Target = @import("std").Target; |
| 4 | 4 | ||
| 5 | pub fn addCases(cases: *tests.CompileErrorContext) void { | 5 | pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 6 | cases.addTest("type mismatch in C prototype with varargs", | ||
| 7 | \\const fn_ty = ?fn ([*c]u8, ...) callconv(.C) void; | ||
| 8 | \\extern fn fn_decl(fmt: [*:0]u8, ...) void; | ||
| 9 | \\ | ||
| 10 | \\export fn main() void { | ||
| 11 | \\ const x: fn_ty = fn_decl; | ||
| 12 | \\} | ||
| 13 | , &[_][]const u8{ | ||
| 14 | "tmp.zig:5:22: error: expected type 'fn([*c]u8, ...) callconv(.C) void', found 'fn([*:0]u8, ...) callconv(.C) void'", | ||
| 15 | }); | ||
| 16 | |||
| 6 | cases.addTest("dependency loop in top-level decl with @TypeInfo", | 17 | cases.addTest("dependency loop in top-level decl with @TypeInfo", |
| 7 | \\export const foo = @typeInfo(@This()); | 18 | \\export const foo = @typeInfo(@This()); |
| 8 | , &[_][]const u8{ | 19 | , &[_][]const u8{ |