authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-18 16:32:40-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-18 16:32:40-04:00
logc1af3605328d21f59ee8ceba3c7350193f0a2429
treea0a7ae69ff7a6772e8f341aad291278833d389ad
parent148fe2e99970ca880a8e10ded5af308e28bbc342
signaturelock-open Commit is signed but in an unrecognized format.

add compile error for slice.*.len

closes #1372

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

src/ir.cpp+6-1
...@@ -14874,8 +14874,13 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi...@@ -14874,8 +14874,13 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi
14874 if (type_is_invalid(container_ptr->value.type))14874 if (type_is_invalid(container_ptr->value.type))
14875 return ira->codegen->builtin_types.entry_invalid;14875 return ira->codegen->builtin_types.entry_invalid;
1487614876
14877 if (container_ptr->value.type->id != ZigTypeIdPointer) {
14878 ir_add_error_node(ira, field_ptr_instruction->base.source_node,
14879 buf_sprintf("attempt to dereference non-pointer type '%s'",
14880 buf_ptr(&container_ptr->value.type->name)));
14881 return ira->codegen->builtin_types.entry_invalid;
14882 }
14877 ZigType *container_type = container_ptr->value.type->data.pointer.child_type;14883 ZigType *container_type = container_ptr->value.type->data.pointer.child_type;
14878 assert(container_ptr->value.type->id == ZigTypeIdPointer);
1487914884
14880 Buf *field_name = field_ptr_instruction->field_name_buffer;14885 Buf *field_name = field_ptr_instruction->field_name_buffer;
14881 if (!field_name) {14886 if (!field_name) {
test/compile_errors.zig+10
...@@ -1,6 +1,16 @@...@@ -1,6 +1,16 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: *tests.CompileErrorContext) void {3pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.add(
5 "deref slice and get len field",
6 \\export fn entry() void {
7 \\ var a: []u8 = undefined;
8 \\ _ = a.*.len;
9 \\}
10 ,
11 ".tmp_source.zig:3:12: error: attempt to dereference non-pointer type '[]u8'",
12 );
13
4 cases.add(14 cases.add(
5 "@ptrCast a 0 bit type to a non- 0 bit type",15 "@ptrCast a 0 bit type to a non- 0 bit type",
6 \\export fn entry() bool {16 \\export fn entry() bool {