authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-15 19:05:51-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-15 19:05:51-07:00
log8bc3fae1cf055e33e01e0cbbbbc67f307f60b95b
tree1fc0b4b9b4955d94e96e5bccef733afe2ec25a9f
parent8818c59cbc96e6b0699a408d2fbaa9846356d85a

fix error message for struct initialization on array


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

src/analyze.cpp+2-1
......@@ -1342,6 +1342,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
13421342 if (container_type->id == TypeTableEntryIdInvalid) {
13431343 return container_type;
13441344 } else if (container_type->id == TypeTableEntryIdStruct &&
1345 !container_type->data.structure.is_unknown_size_array &&
13451346 kind == ContainerInitKindStruct)
13461347 {
13471348 StructValExprCodeGen *codegen = &container_init_expr->resolved_struct_val_expr;
......@@ -1410,7 +1411,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
14101411 }
14111412 } else {
14121413 add_node_error(g, node,
1413 buf_sprintf("type '%s' does not support %s syntax",
1414 buf_sprintf("type '%s' does not support %s initialization syntax",
14141415 buf_ptr(&container_type->name), err_container_init_syntax_name(kind)));
14151416 return g->builtin_types.entry_invalid;
14161417 }
test/run_tests.cpp+4
......@@ -1419,6 +1419,10 @@ const b : @typeof(a) = 0;
14191419 add_compile_fail_case("noalias on non pointer param", R"SOURCE(
14201420fn f(noalias x: i32) => {}
14211421 )SOURCE", 1, ".tmp_source.zig:2:6: error: noalias on non-pointer parameter");
1422
1423 add_compile_fail_case("struct init syntax for array", R"SOURCE(
1424const foo = []u16{.x = 1024,};
1425 )SOURCE", 1, ".tmp_source.zig:2:18: error: type '[]u16' does not support struct initialization syntax");
14221426}
14231427
14241428static void print_compiler_invocation(TestCase *test_case) {