diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2016-04-21 09:47:41 -0700 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2016-04-21 09:47:41 -0700 |
| commit | a380b803ac8b4eefcde4d3d552cdcbc8010aa798 (patch) | |
| tree | de6309db31e1614467295bfd82c3bc27928bd27b | |
| parent | ae600d2f7f89989c297c036f189b7bedfde910af (diff) | |
| download | zig-a380b803ac8b4eefcde4d3d552cdcbc8010aa798.tar.gz zig-a380b803ac8b4eefcde4d3d552cdcbc8010aa798.zip | |
ability to use a struct with no fields
| -rw-r--r-- | src/analyze.cpp | 3 | ||||
| -rw-r--r-- | src/codegen.cpp | 4 | ||||
| -rw-r--r-- | test/self_hosted.zig | 10 |
3 files changed, 15 insertions, 2 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp index 73839716e0..ae1400048e 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -2219,7 +2219,8 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry return container_type; } else if (container_type->id == TypeTableEntryIdStruct && !container_type->data.structure.is_unknown_size_array && - kind == ContainerInitKindStruct) + (kind == ContainerInitKindStruct || (kind == ContainerInitKindArray && + container_init_expr->entries.length == 0))) { StructValExprCodeGen *codegen = &container_init_expr->resolved_struct_val_expr; codegen->type_entry = container_type; diff --git a/src/codegen.cpp b/src/codegen.cpp index 80eb4b2089..8ba76e0cfb 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -801,14 +801,16 @@ static LLVMValueRef gen_fn_call_expr(CodeGen *g, AstNode *node) { gen_param_values[gen_param_index] = node->data.fn_call_expr.tmp_ptr; gen_param_index += 1; } - if (struct_type) { + if (struct_type && type_has_bits(struct_type)) { gen_param_values[gen_param_index] = gen_expr(g, first_param_expr); + assert(gen_param_values[gen_param_index]); gen_param_index += 1; } for (int i = 0; i < fn_call_param_count; i += 1) { AstNode *expr_node = node->data.fn_call_expr.params.at(i); LLVMValueRef param_value = gen_expr(g, expr_node); + assert(param_value); TypeTableEntry *param_type = get_expr_type(expr_node); if (is_var_args || type_has_bits(param_type)) { gen_param_values[gen_param_index] = param_value; diff --git a/test/self_hosted.zig b/test/self_hosted.zig index e621dbf3f2..3bf19b61f5 100644 --- a/test/self_hosted.zig +++ b/test/self_hosted.zig @@ -1285,3 +1285,13 @@ fn mangle_string(s: []u8) { *c += 1; } } + +#attribute("test") +fn empty_struct_method_call() { + const es = EmptyStruct{}; + assert(es.method() == 1234); +} +struct EmptyStruct { + #static_eval_enable(false) + fn method(es: EmptyStruct) -> i32 { 1234 } +} |
