authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-24 16:23:33-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-10-24 16:23:33-04:00
log32c89531b1475ce8e3b8efdf7a07745da7bc854a
tree848ea8ac81eabbe6293eacdfc16210b1d6973a99
parent345042ecbc7fb645fd17b69df4e57ffefa5be5a5
signaturelock-open Commit is signed but in an unrecognized format.

Add missing compile error when ptr used instead of array

in array literals. Fixes #3524

2 files changed, 17 insertions(+), 1 deletions(-)

src/ir.cpp+4-1
......@@ -17590,7 +17590,10 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1759017590 false);
1759117591 array_ptr_val->data.x_struct.fields[slice_ptr_index].data.x_ptr.mut = ConstPtrMutInfer;
1759217592 } else {
17593 zig_unreachable();
17593 ir_add_error(ira, elem_ptr_instruction->init_array_type,
17594 buf_sprintf("expected array type or [_], found '%s'",
17595 buf_ptr(&array_type->name)));
17596 return ira->codegen->invalid_instruction;
1759417597 }
1759517598 }
1759617599
test/compile_errors.zig+13
......@@ -2,6 +2,19 @@ const tests = @import("tests.zig");
22const builtin = @import("builtin");
33
44pub fn addCases(cases: *tests.CompileErrorContext) void {
5 cases.add(
6 "using an unknown len ptr type instead of array",
7 \\const resolutions = [*][*]const u8{
8 \\ c"[320 240 ]",
9 \\ null,
10 \\};
11 \\comptime {
12 \\ _ = resolutions;
13 \\}
14 ,
15 "tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8'",
16 );
17
518 cases.add(
619 "comparison with error union and error value",
720 \\export fn entry() void {