From 32c89531b1475ce8e3b8efdf7a07745da7bc854a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 24 Oct 2019 16:23:33 -0400 Subject: [PATCH] Add missing compile error when ptr used instead of array in array literals. Fixes #3524 --- src/ir.cpp | 5 ++++- test/compile_errors.zig | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/ir.cpp b/src/ir.cpp index 8aff5e4583..3b3814b3ad 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -17590,7 +17590,10 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct false); array_ptr_val->data.x_struct.fields[slice_ptr_index].data.x_ptr.mut = ConstPtrMutInfer; } else { - zig_unreachable(); + ir_add_error(ira, elem_ptr_instruction->init_array_type, + buf_sprintf("expected array type or [_], found '%s'", + buf_ptr(&array_type->name))); + return ira->codegen->invalid_instruction; } } diff --git a/test/compile_errors.zig b/test/compile_errors.zig index c7b0e09485..8f12ec2e57 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -2,6 +2,19 @@ const tests = @import("tests.zig"); const builtin = @import("builtin"); pub fn addCases(cases: *tests.CompileErrorContext) void { + cases.add( + "using an unknown len ptr type instead of array", + \\const resolutions = [*][*]const u8{ + \\ c"[320 240 ]", + \\ null, + \\}; + \\comptime { + \\ _ = resolutions; + \\} + , + "tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8'", + ); + cases.add( "comparison with error union and error value", \\export fn entry() void {