fix error message for struct initialization on array

This commit is contained in:
Andrew Kelley 2016-01-15 19:05:51 -07:00
parent 8818c59cbc
commit 8bc3fae1cf
2 changed files with 6 additions and 1 deletions

View File

@ -1342,6 +1342,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
if (container_type->id == TypeTableEntryIdInvalid) { if (container_type->id == TypeTableEntryIdInvalid) {
return container_type; return container_type;
} else if (container_type->id == TypeTableEntryIdStruct && } else if (container_type->id == TypeTableEntryIdStruct &&
!container_type->data.structure.is_unknown_size_array &&
kind == ContainerInitKindStruct) kind == ContainerInitKindStruct)
{ {
StructValExprCodeGen *codegen = &container_init_expr->resolved_struct_val_expr; StructValExprCodeGen *codegen = &container_init_expr->resolved_struct_val_expr;
@ -1410,7 +1411,7 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
} }
} else { } else {
add_node_error(g, node, add_node_error(g, node,
buf_sprintf("type '%s' does not support %s syntax", buf_sprintf("type '%s' does not support %s initialization syntax",
buf_ptr(&container_type->name), err_container_init_syntax_name(kind))); buf_ptr(&container_type->name), err_container_init_syntax_name(kind)));
return g->builtin_types.entry_invalid; return g->builtin_types.entry_invalid;
} }

View File

@ -1419,6 +1419,10 @@ const b : @typeof(a) = 0;
add_compile_fail_case("noalias on non pointer param", R"SOURCE( add_compile_fail_case("noalias on non pointer param", R"SOURCE(
fn f(noalias x: i32) => {} fn f(noalias x: i32) => {}
)SOURCE", 1, ".tmp_source.zig:2:6: error: noalias on non-pointer parameter"); )SOURCE", 1, ".tmp_source.zig:2:6: error: noalias on non-pointer parameter");
add_compile_fail_case("struct init syntax for array", R"SOURCE(
const foo = []u16{.x = 1024,};
)SOURCE", 1, ".tmp_source.zig:2:18: error: type '[]u16' does not support struct initialization syntax");
} }
static void print_compiler_invocation(TestCase *test_case) { static void print_compiler_invocation(TestCase *test_case) {