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...@@ -1342,6 +1342,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
1342 if (container_type->id == TypeTableEntryIdInvalid) {1342 if (container_type->id == TypeTableEntryIdInvalid) {
1343 return container_type;1343 return container_type;
1344 } else if (container_type->id == TypeTableEntryIdStruct &&1344 } else if (container_type->id == TypeTableEntryIdStruct &&
1345 !container_type->data.structure.is_unknown_size_array &&
1345 kind == ContainerInitKindStruct)1346 kind == ContainerInitKindStruct)
1346 {1347 {
1347 StructValExprCodeGen *codegen = &container_init_expr->resolved_struct_val_expr;1348 StructValExprCodeGen *codegen = &container_init_expr->resolved_struct_val_expr;
...@@ -1410,7 +1411,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry...@@ -1410,7 +1411,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
1410 }1411 }
1411 } else {1412 } else {
1412 add_node_error(g, node,1413 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",
1414 buf_ptr(&container_type->name), err_container_init_syntax_name(kind)));1415 buf_ptr(&container_type->name), err_container_init_syntax_name(kind)));
1415 return g->builtin_types.entry_invalid;1416 return g->builtin_types.entry_invalid;
1416 }1417 }
test/run_tests.cpp+4
...@@ -1419,6 +1419,10 @@ const b : @typeof(a) = 0;...@@ -1419,6 +1419,10 @@ const b : @typeof(a) = 0;
1419 add_compile_fail_case("noalias on non pointer param", R"SOURCE(1419 add_compile_fail_case("noalias on non pointer param", R"SOURCE(
1420fn f(noalias x: i32) => {}1420fn f(noalias x: i32) => {}
1421 )SOURCE", 1, ".tmp_source.zig:2:6: error: noalias on non-pointer parameter");1421 )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");
1422}1426}
14231427
1424static void print_compiler_invocation(TestCase *test_case) {1428static void print_compiler_invocation(TestCase *test_case) {