diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-08-31 16:30:46 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-08-31 16:30:46 -0400 |
| commit | 67b6dd28ec70937a29176719b56457ee17b1c136 (patch) | |
| tree | cf6e7e1585d8cb1b56ba77ec53562f7502c5e65d /src | |
| parent | eb0979189be33d6d957dad5104650cb5c532055b (diff) | |
| download | zig-67b6dd28ec70937a29176719b56457ee17b1c136.tar.gz zig-67b6dd28ec70937a29176719b56457ee17b1c136.zip | |
allow array literals to have size and fix comptime bug
Diffstat (limited to 'src')
| -rw-r--r-- | src/all_types.hpp | 1 | ||||
| -rw-r--r-- | src/ir.cpp | 31 |
2 files changed, 23 insertions, 9 deletions
diff --git a/src/all_types.hpp b/src/all_types.hpp index 39e6033988..9f1dc15a39 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -50,6 +50,7 @@ struct IrExecutable { size_t next_debug_id; size_t *backward_branch_count; size_t backward_branch_quota; + bool reported_quota_exceeded; bool invalid; ZigList<LabelTableEntry *> all_labels; ZigList<IrGotoItem> goto_list; diff --git a/src/ir.cpp b/src/ir.cpp index f37194a557..f8b6c4cdf7 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -7604,12 +7604,13 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instru size_t *bbc = ira->new_irb.exec->backward_branch_count; size_t quota = ira->new_irb.exec->backward_branch_quota; - // If we're already over quota, we've already given an error message for this. - if (*bbc > quota) + if (ira->new_irb.exec->reported_quota_exceeded) { return false; + } *bbc += 1; if (*bbc > quota) { + ira->new_irb.exec->reported_quota_exceeded = true; ir_add_error(ira, source_instruction, buf_sprintf("evaluation exceeded %" ZIG_PRI_usize " backwards branches", quota)); return false; } @@ -12815,10 +12816,25 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira if (container_type->id == TypeTableEntryIdStruct && !is_slice(container_type) && elem_count == 0) { return ir_analyze_container_init_fields(ira, &instruction->base, container_type, 0, nullptr); - } else if (is_slice(container_type)) { - TypeTableEntry *pointer_type = container_type->data.structure.fields[slice_ptr_index].type_entry; - assert(pointer_type->id == TypeTableEntryIdPointer); - TypeTableEntry *child_type = pointer_type->data.pointer.child_type; + } else if (is_slice(container_type) || container_type->id == TypeTableEntryIdArray) { + // array is same as slice init but we make a compile error if the length is wrong + TypeTableEntry *child_type; + if (container_type->id == TypeTableEntryIdArray) { + child_type = container_type->data.array.child_type; + if (container_type->data.array.len != elem_count) { + TypeTableEntry *literal_type = get_array_type(ira->codegen, child_type, elem_count); + + ir_add_error(ira, &instruction->base, + buf_sprintf("expected %s literal, found %s literal", + buf_ptr(&container_type->name), buf_ptr(&literal_type->name))); + return ira->codegen->builtin_types.entry_invalid; + } + } else { + TypeTableEntry *pointer_type = container_type->data.structure.fields[slice_ptr_index].type_entry; + assert(pointer_type->id == TypeTableEntryIdPointer); + child_type = pointer_type->data.pointer.child_type; + } + TypeTableEntry *fixed_size_array_type = get_array_type(ira->codegen, child_type, elem_count); ConstExprValue const_val = {}; @@ -12882,9 +12898,6 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira container_type_value, elem_count, new_items); ir_add_alloca(ira, new_instruction, fixed_size_array_type); return fixed_size_array_type; - } else if (container_type->id == TypeTableEntryIdArray) { - // same as slice init but we make a compile error if the length is wrong - zig_panic("TODO array container init"); } else if (container_type->id == TypeTableEntryIdVoid) { if (elem_count != 0) { ir_add_error_node(ira, instruction->base.source_node, |
