add compile error for slice.*.len

closes #1372
This commit is contained in:
Andrew Kelley 2018-09-18 16:32:40 -04:00
parent 148fe2e999
commit c1af360532
No known key found for this signature in database
GPG Key ID: 4E7CD66038A4D47C
2 changed files with 16 additions and 1 deletions

View File

@ -14874,8 +14874,13 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi
if (type_is_invalid(container_ptr->value.type))
return ira->codegen->builtin_types.entry_invalid;
if (container_ptr->value.type->id != ZigTypeIdPointer) {
ir_add_error_node(ira, field_ptr_instruction->base.source_node,
buf_sprintf("attempt to dereference non-pointer type '%s'",
buf_ptr(&container_ptr->value.type->name)));
return ira->codegen->builtin_types.entry_invalid;
}
ZigType *container_type = container_ptr->value.type->data.pointer.child_type;
assert(container_ptr->value.type->id == ZigTypeIdPointer);
Buf *field_name = field_ptr_instruction->field_name_buffer;
if (!field_name) {

View File

@ -1,6 +1,16 @@
const tests = @import("tests.zig");
pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"deref slice and get len field",
\\export fn entry() void {
\\ var a: []u8 = undefined;
\\ _ = a.*.len;
\\}
,
".tmp_source.zig:3:12: error: attempt to dereference non-pointer type '[]u8'",
);
cases.add(
"@ptrCast a 0 bit type to a non- 0 bit type",
\\export fn entry() bool {