authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-30 11:52:03-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-30 11:52:03-05:00
log3ef6a00bb8854119d39bba521a0256d4884001f5
treeb0ae89e6811a01c300207b6cd02524176e1057dd
parent0995a81b8b59b627654ecbf55fa86cd8e98161c6

add compile error for duplicate struct, enum, union fields

closes #730

4 files changed, 117 insertions(+), 25 deletions(-)

src/all_types.hpp+9
...@@ -331,12 +331,14 @@ struct TypeEnumField {...@@ -331,12 +331,14 @@ struct TypeEnumField {
331 Buf *name;331 Buf *name;
332 BigInt value;332 BigInt value;
333 uint32_t decl_index;333 uint32_t decl_index;
334 AstNode *decl_node;
334};335};
335336
336struct TypeUnionField {337struct TypeUnionField {
337 Buf *name;338 Buf *name;
338 TypeEnumField *enum_field;339 TypeEnumField *enum_field;
339 TypeTableEntry *type_entry;340 TypeTableEntry *type_entry;
341 AstNode *decl_node;
340 uint32_t gen_index;342 uint32_t gen_index;
341};343};
342344
...@@ -961,6 +963,7 @@ struct TypeStructField {...@@ -961,6 +963,7 @@ struct TypeStructField {
961 size_t packed_bits_offset;963 size_t packed_bits_offset;
962 size_t packed_bits_size;964 size_t packed_bits_size;
963 size_t unaligned_bit_count;965 size_t unaligned_bit_count;
966 AstNode *decl_node;
964};967};
965struct TypeTableEntryStruct {968struct TypeTableEntryStruct {
966 AstNode *decl_node;969 AstNode *decl_node;
...@@ -982,6 +985,8 @@ struct TypeTableEntryStruct {...@@ -982,6 +985,8 @@ struct TypeTableEntryStruct {
982 bool zero_bits_loop_flag;985 bool zero_bits_loop_flag;
983 bool zero_bits_known;986 bool zero_bits_known;
984 uint32_t abi_alignment; // also figured out with zero_bits pass987 uint32_t abi_alignment; // also figured out with zero_bits pass
988
989 HashMap<Buf *, TypeStructField *, buf_hash, buf_eql_buf> fields_by_name;
985};990};
986991
987struct TypeTableEntryMaybe {992struct TypeTableEntryMaybe {
...@@ -1013,6 +1018,8 @@ struct TypeTableEntryEnum {...@@ -1013,6 +1018,8 @@ struct TypeTableEntryEnum {
10131018
1014 bool generate_name_table;1019 bool generate_name_table;
1015 LLVMValueRef name_table;1020 LLVMValueRef name_table;
1021
1022 HashMap<Buf *, TypeEnumField *, buf_hash, buf_eql_buf> fields_by_name;
1016};1023};
10171024
1018uint32_t type_ptr_hash(const TypeTableEntry *ptr);1025uint32_t type_ptr_hash(const TypeTableEntry *ptr);
...@@ -1045,6 +1052,8 @@ struct TypeTableEntryUnion {...@@ -1045,6 +1052,8 @@ struct TypeTableEntryUnion {
10451052
1046 uint32_t union_size_bytes;1053 uint32_t union_size_bytes;
1047 TypeTableEntry *most_aligned_union_member;1054 TypeTableEntry *most_aligned_union_member;
1055
1056 HashMap<Buf *, TypeUnionField *, buf_hash, buf_eql_buf> fields_by_name;
1048};1057};
10491058
1050struct FnGenParamInfo {1059struct FnGenParamInfo {
src/analyze.cpp+70-23
...@@ -633,20 +633,27 @@ TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t...@@ -633,20 +633,27 @@ TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t
633633
634static void slice_type_common_init(CodeGen *g, TypeTableEntry *pointer_type, TypeTableEntry *entry) {634static void slice_type_common_init(CodeGen *g, TypeTableEntry *pointer_type, TypeTableEntry *entry) {
635 unsigned element_count = 2;635 unsigned element_count = 2;
636 Buf *ptr_field_name = buf_create_from_str("ptr");
637 Buf *len_field_name = buf_create_from_str("len");
638
636 entry->data.structure.layout = ContainerLayoutAuto;639 entry->data.structure.layout = ContainerLayoutAuto;
637 entry->data.structure.is_slice = true;640 entry->data.structure.is_slice = true;
638 entry->data.structure.src_field_count = element_count;641 entry->data.structure.src_field_count = element_count;
639 entry->data.structure.gen_field_count = element_count;642 entry->data.structure.gen_field_count = element_count;
640 entry->data.structure.fields = allocate<TypeStructField>(element_count);643 entry->data.structure.fields = allocate<TypeStructField>(element_count);
641 entry->data.structure.fields[slice_ptr_index].name = buf_create_from_str("ptr");644 entry->data.structure.fields_by_name.init(element_count);
645 entry->data.structure.fields[slice_ptr_index].name = ptr_field_name;
642 entry->data.structure.fields[slice_ptr_index].type_entry = pointer_type;646 entry->data.structure.fields[slice_ptr_index].type_entry = pointer_type;
643 entry->data.structure.fields[slice_ptr_index].src_index = slice_ptr_index;647 entry->data.structure.fields[slice_ptr_index].src_index = slice_ptr_index;
644 entry->data.structure.fields[slice_ptr_index].gen_index = 0;648 entry->data.structure.fields[slice_ptr_index].gen_index = 0;
645 entry->data.structure.fields[slice_len_index].name = buf_create_from_str("len");649 entry->data.structure.fields[slice_len_index].name = len_field_name;
646 entry->data.structure.fields[slice_len_index].type_entry = g->builtin_types.entry_usize;650 entry->data.structure.fields[slice_len_index].type_entry = g->builtin_types.entry_usize;
647 entry->data.structure.fields[slice_len_index].src_index = slice_len_index;651 entry->data.structure.fields[slice_len_index].src_index = slice_len_index;
648 entry->data.structure.fields[slice_len_index].gen_index = 1;652 entry->data.structure.fields[slice_len_index].gen_index = 1;
649653
654 entry->data.structure.fields_by_name.put(ptr_field_name, &entry->data.structure.fields[slice_ptr_index]);
655 entry->data.structure.fields_by_name.put(len_field_name, &entry->data.structure.fields[slice_len_index]);
656
650 assert(type_has_zero_bits_known(pointer_type->data.pointer.child_type));657 assert(type_has_zero_bits_known(pointer_type->data.pointer.child_type));
651 if (pointer_type->data.pointer.child_type->zero_bits) {658 if (pointer_type->data.pointer.child_type->zero_bits) {
652 entry->data.structure.gen_field_count = 1;659 entry->data.structure.gen_field_count = 1;
...@@ -1555,6 +1562,7 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f...@@ -1555,6 +1562,7 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f
1555 struct_type->data.structure.zero_bits_known = true;1562 struct_type->data.structure.zero_bits_known = true;
1556 struct_type->data.structure.complete = true;1563 struct_type->data.structure.complete = true;
1557 struct_type->data.structure.fields = allocate<TypeStructField>(field_count);1564 struct_type->data.structure.fields = allocate<TypeStructField>(field_count);
1565 struct_type->data.structure.fields_by_name.init(field_count);
15581566
1559 ZigLLVMDIType **di_element_types = allocate<ZigLLVMDIType*>(field_count);1567 ZigLLVMDIType **di_element_types = allocate<ZigLLVMDIType*>(field_count);
1560 LLVMTypeRef *element_types = allocate<LLVMTypeRef>(field_count);1568 LLVMTypeRef *element_types = allocate<LLVMTypeRef>(field_count);
...@@ -1566,6 +1574,9 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f...@@ -1566,6 +1574,9 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f
1566 field->type_entry = field_types[i];1574 field->type_entry = field_types[i];
1567 field->src_index = i;1575 field->src_index = i;
1568 field->gen_index = i;1576 field->gen_index = i;
1577
1578 auto prev_entry = struct_type->data.structure.fields_by_name.put_unique(field->name, field);
1579 assert(prev_entry == nullptr);
1569 }1580 }
15701581
1571 struct_type->type_ref = LLVMStructCreateNamed(LLVMGetGlobalContext(), type_name);1582 struct_type->type_ref = LLVMStructCreateNamed(LLVMGetGlobalContext(), type_name);
...@@ -2102,6 +2113,7 @@ static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {...@@ -2102,6 +2113,7 @@ static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
21022113
2103 enum_type->data.enumeration.src_field_count = field_count;2114 enum_type->data.enumeration.src_field_count = field_count;
2104 enum_type->data.enumeration.fields = allocate<TypeEnumField>(field_count);2115 enum_type->data.enumeration.fields = allocate<TypeEnumField>(field_count);
2116 enum_type->data.enumeration.fields_by_name.init(field_count);
21052117
2106 Scope *scope = &enum_type->data.enumeration.decls_scope->base;2118 Scope *scope = &enum_type->data.enumeration.decls_scope->base;
21072119
...@@ -2139,6 +2151,7 @@ static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {...@@ -2139,6 +2151,7 @@ static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
2139 TypeEnumField *type_enum_field = &enum_type->data.enumeration.fields[field_i];2151 TypeEnumField *type_enum_field = &enum_type->data.enumeration.fields[field_i];
2140 type_enum_field->name = field_node->data.struct_field.name;2152 type_enum_field->name = field_node->data.struct_field.name;
2141 type_enum_field->decl_index = field_i;2153 type_enum_field->decl_index = field_i;
2154 type_enum_field->decl_node = field_node;
21422155
2143 if (field_node->data.struct_field.type != nullptr) {2156 if (field_node->data.struct_field.type != nullptr) {
2144 ErrorMsg *msg = add_node_error(g, field_node->data.struct_field.type,2157 ErrorMsg *msg = add_node_error(g, field_node->data.struct_field.type,
...@@ -2147,6 +2160,15 @@ static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {...@@ -2147,6 +2160,15 @@ static void resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) {
2147 buf_sprintf("consider 'union(enum)' here"));2160 buf_sprintf("consider 'union(enum)' here"));
2148 }2161 }
21492162
2163 auto field_entry = enum_type->data.enumeration.fields_by_name.put_unique(type_enum_field->name, type_enum_field);
2164 if (field_entry != nullptr) {
2165 ErrorMsg *msg = add_node_error(g, field_node,
2166 buf_sprintf("duplicate enum field: '%s'", buf_ptr(type_enum_field->name)));
2167 add_error_note(g, msg, field_entry->value->decl_node, buf_sprintf("other field here"));
2168 enum_type->data.enumeration.is_invalid = true;
2169 continue;
2170 }
2171
2150 AstNode *tag_value = field_node->data.struct_field.value;2172 AstNode *tag_value = field_node->data.struct_field.value;
21512173
2152 // In this first pass we resolve explicit tag values.2174 // In this first pass we resolve explicit tag values.
...@@ -2242,6 +2264,7 @@ static void resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {...@@ -2242,6 +2264,7 @@ static void resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {
2242 size_t field_count = decl_node->data.container_decl.fields.length;2264 size_t field_count = decl_node->data.container_decl.fields.length;
2243 struct_type->data.structure.src_field_count = (uint32_t)field_count;2265 struct_type->data.structure.src_field_count = (uint32_t)field_count;
2244 struct_type->data.structure.fields = allocate<TypeStructField>(field_count);2266 struct_type->data.structure.fields = allocate<TypeStructField>(field_count);
2267 struct_type->data.structure.fields_by_name.init(field_count);
22452268
2246 Scope *scope = &struct_type->data.structure.decls_scope->base;2269 Scope *scope = &struct_type->data.structure.decls_scope->base;
22472270
...@@ -2250,6 +2273,7 @@ static void resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {...@@ -2250,6 +2273,7 @@ static void resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {
2250 AstNode *field_node = decl_node->data.container_decl.fields.at(i);2273 AstNode *field_node = decl_node->data.container_decl.fields.at(i);
2251 TypeStructField *type_struct_field = &struct_type->data.structure.fields[i];2274 TypeStructField *type_struct_field = &struct_type->data.structure.fields[i];
2252 type_struct_field->name = field_node->data.struct_field.name;2275 type_struct_field->name = field_node->data.struct_field.name;
2276 type_struct_field->decl_node = field_node;
22532277
2254 if (field_node->data.struct_field.type == nullptr) {2278 if (field_node->data.struct_field.type == nullptr) {
2255 add_node_error(g, field_node, buf_sprintf("struct field missing type"));2279 add_node_error(g, field_node, buf_sprintf("struct field missing type"));
...@@ -2257,6 +2281,15 @@ static void resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {...@@ -2257,6 +2281,15 @@ static void resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) {
2257 continue;2281 continue;
2258 }2282 }
22592283
2284 auto field_entry = struct_type->data.structure.fields_by_name.put_unique(type_struct_field->name, type_struct_field);
2285 if (field_entry != nullptr) {
2286 ErrorMsg *msg = add_node_error(g, field_node,
2287 buf_sprintf("duplicate struct field: '%s'", buf_ptr(type_struct_field->name)));
2288 add_error_note(g, msg, field_entry->value->decl_node, buf_sprintf("other field here"));
2289 struct_type->data.structure.is_invalid = true;
2290 continue;
2291 }
2292
2260 TypeTableEntry *field_type = analyze_type_expr(g, scope, field_node->data.struct_field.type);2293 TypeTableEntry *field_type = analyze_type_expr(g, scope, field_node->data.struct_field.type);
2261 type_struct_field->type_entry = field_type;2294 type_struct_field->type_entry = field_type;
2262 type_struct_field->src_index = i;2295 type_struct_field->src_index = i;
...@@ -2344,6 +2377,7 @@ static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {...@@ -2344,6 +2377,7 @@ static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
2344 }2377 }
2345 union_type->data.unionation.src_field_count = field_count;2378 union_type->data.unionation.src_field_count = field_count;
2346 union_type->data.unionation.fields = allocate<TypeUnionField>(field_count);2379 union_type->data.unionation.fields = allocate<TypeUnionField>(field_count);
2380 union_type->data.unionation.fields_by_name.init(field_count);
23472381
2348 uint32_t biggest_align_bytes = 0;2382 uint32_t biggest_align_bytes = 0;
23492383
...@@ -2395,6 +2429,7 @@ static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {...@@ -2395,6 +2429,7 @@ static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
2395 tag_type->data.enumeration.layout = ContainerLayoutAuto;2429 tag_type->data.enumeration.layout = ContainerLayoutAuto;
2396 tag_type->data.enumeration.src_field_count = field_count;2430 tag_type->data.enumeration.src_field_count = field_count;
2397 tag_type->data.enumeration.fields = allocate<TypeEnumField>(field_count);2431 tag_type->data.enumeration.fields = allocate<TypeEnumField>(field_count);
2432 tag_type->data.enumeration.fields_by_name.init(field_count);
2398 tag_type->data.enumeration.decls_scope = union_type->data.unionation.decls_scope;2433 tag_type->data.enumeration.decls_scope = union_type->data.unionation.decls_scope;
2399 tag_type->data.enumeration.complete = true;2434 tag_type->data.enumeration.complete = true;
2400 } else if (enum_type_node != nullptr) {2435 } else if (enum_type_node != nullptr) {
...@@ -2424,6 +2459,16 @@ static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {...@@ -2424,6 +2459,16 @@ static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
2424 Buf *field_name = field_node->data.struct_field.name;2459 Buf *field_name = field_node->data.struct_field.name;
2425 TypeUnionField *union_field = &union_type->data.unionation.fields[i];2460 TypeUnionField *union_field = &union_type->data.unionation.fields[i];
2426 union_field->name = field_node->data.struct_field.name;2461 union_field->name = field_node->data.struct_field.name;
2462 union_field->decl_node = field_node;
2463
2464 auto field_entry = union_type->data.unionation.fields_by_name.put_unique(union_field->name, union_field);
2465 if (field_entry != nullptr) {
2466 ErrorMsg *msg = add_node_error(g, field_node,
2467 buf_sprintf("duplicate union field: '%s'", buf_ptr(union_field->name)));
2468 add_error_note(g, msg, field_entry->value->decl_node, buf_sprintf("other field here"));
2469 union_type->data.unionation.is_invalid = true;
2470 continue;
2471 }
24272472
2428 TypeTableEntry *field_type;2473 TypeTableEntry *field_type;
2429 if (field_node->data.struct_field.type == nullptr) {2474 if (field_node->data.struct_field.type == nullptr) {
...@@ -2456,6 +2501,10 @@ static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {...@@ -2456,6 +2501,10 @@ static void resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) {
2456 union_field->enum_field = &tag_type->data.enumeration.fields[i];2501 union_field->enum_field = &tag_type->data.enumeration.fields[i];
2457 union_field->enum_field->name = field_name;2502 union_field->enum_field->name = field_name;
2458 union_field->enum_field->decl_index = i;2503 union_field->enum_field->decl_index = i;
2504 union_field->enum_field->decl_node = field_node;
2505
2506 auto prev_entry = tag_type->data.enumeration.fields_by_name.put_unique(union_field->enum_field->name, union_field->enum_field);
2507 assert(prev_entry == nullptr); // caught by union de-duplicator above
24592508
2460 AstNode *tag_value = field_node->data.struct_field.value;2509 AstNode *tag_value = field_node->data.struct_field.value;
2461 // In this first pass we resolve explicit tag values.2510 // In this first pass we resolve explicit tag values.
...@@ -3499,37 +3548,35 @@ FnTableEntry *scope_get_fn_if_root(Scope *scope) {...@@ -3499,37 +3548,35 @@ FnTableEntry *scope_get_fn_if_root(Scope *scope) {
3499}3548}
35003549
3501TypeEnumField *find_enum_type_field(TypeTableEntry *enum_type, Buf *name) {3550TypeEnumField *find_enum_type_field(TypeTableEntry *enum_type, Buf *name) {
3502 for (uint32_t i = 0; i < enum_type->data.enumeration.src_field_count; i += 1) {3551 assert(enum_type->id == TypeTableEntryIdEnum);
3503 TypeEnumField *type_enum_field = &enum_type->data.enumeration.fields[i];3552 if (enum_type->data.enumeration.src_field_count == 0)
3504 if (buf_eql_buf(type_enum_field->name, name)) {3553 return nullptr;
3505 return type_enum_field;3554 auto entry = enum_type->data.enumeration.fields_by_name.maybe_get(name);
3506 }3555 if (entry == nullptr)
3507 }3556 return nullptr;
3508 return nullptr;3557 return entry->value;
3509}3558}
35103559
3511TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *name) {3560TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *name) {
3512 assert(type_entry->id == TypeTableEntryIdStruct);3561 assert(type_entry->id == TypeTableEntryIdStruct);
3513 assert(type_entry->data.structure.complete);3562 assert(type_entry->data.structure.complete);
3514 for (uint32_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {3563 if (type_entry->data.structure.src_field_count == 0)
3515 TypeStructField *field = &type_entry->data.structure.fields[i];3564 return nullptr;
3516 if (buf_eql_buf(field->name, name)) {3565 auto entry = type_entry->data.structure.fields_by_name.maybe_get(name);
3517 return field;3566 if (entry == nullptr)
3518 }3567 return nullptr;
3519 }3568 return entry->value;
3520 return nullptr;
3521}3569}
35223570
3523TypeUnionField *find_union_type_field(TypeTableEntry *type_entry, Buf *name) {3571TypeUnionField *find_union_type_field(TypeTableEntry *type_entry, Buf *name) {
3524 assert(type_entry->id == TypeTableEntryIdUnion);3572 assert(type_entry->id == TypeTableEntryIdUnion);
3525 assert(type_entry->data.unionation.zero_bits_known);3573 assert(type_entry->data.unionation.zero_bits_known);
3526 for (uint32_t i = 0; i < type_entry->data.unionation.src_field_count; i += 1) {3574 if (type_entry->data.unionation.src_field_count == 0)
3527 TypeUnionField *field = &type_entry->data.unionation.fields[i];3575 return nullptr;
3528 if (buf_eql_buf(field->enum_field->name, name)) {3576 auto entry = type_entry->data.unionation.fields_by_name.maybe_get(name);
3529 return field;3577 if (entry == nullptr)
3530 }3578 return nullptr;
3531 }3579 return entry->value;
3532 return nullptr;
3533}3580}
35343581
3535TypeUnionField *find_union_field_by_tag(TypeTableEntry *type_entry, const BigInt *tag) {3582TypeUnionField *find_union_field_by_tag(TypeTableEntry *type_entry, const BigInt *tag) {
src/analyze.hpp+1-1
...@@ -60,8 +60,8 @@ bool type_is_complete(TypeTableEntry *type_entry);...@@ -60,8 +60,8 @@ bool type_is_complete(TypeTableEntry *type_entry);
60bool type_is_invalid(TypeTableEntry *type_entry);60bool type_is_invalid(TypeTableEntry *type_entry);
61bool type_has_zero_bits_known(TypeTableEntry *type_entry);61bool type_has_zero_bits_known(TypeTableEntry *type_entry);
62void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry);62void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry);
63TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *name);
64ScopeDecls *get_container_scope(TypeTableEntry *type_entry);63ScopeDecls *get_container_scope(TypeTableEntry *type_entry);
64TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *name);
65TypeEnumField *find_enum_type_field(TypeTableEntry *enum_type, Buf *name);65TypeEnumField *find_enum_type_field(TypeTableEntry *enum_type, Buf *name);
66TypeUnionField *find_union_type_field(TypeTableEntry *type_entry, Buf *name);66TypeUnionField *find_union_type_field(TypeTableEntry *type_entry, Buf *name);
67TypeEnumField *find_enum_field_by_tag(TypeTableEntry *enum_type, const BigInt *tag);67TypeEnumField *find_enum_field_by_tag(TypeTableEntry *enum_type, const BigInt *tag);
test/compile_errors.zig+37-1
...@@ -1,6 +1,43 @@...@@ -1,6 +1,43 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: &tests.CompileErrorContext) void {3pub fn addCases(cases: &tests.CompileErrorContext) void {
4 cases.add("duplicate struct field",
5 \\const Foo = struct {
6 \\ Bar: i32,
7 \\ Bar: usize,
8 \\};
9 \\export fn entry() void {
10 \\ const a: Foo = undefined;
11 \\}
12 ,
13 ".tmp_source.zig:3:5: error: duplicate struct field: 'Bar'",
14 ".tmp_source.zig:2:5: note: other field here");
15
16 cases.add("duplicate union field",
17 \\const Foo = union {
18 \\ Bar: i32,
19 \\ Bar: usize,
20 \\};
21 \\export fn entry() void {
22 \\ const a: Foo = undefined;
23 \\}
24 ,
25 ".tmp_source.zig:3:5: error: duplicate union field: 'Bar'",
26 ".tmp_source.zig:2:5: note: other field here");
27
28 cases.add("duplicate enum field",
29 \\const Foo = enum {
30 \\ Bar,
31 \\ Bar,
32 \\};
33 \\
34 \\export fn entry() void {
35 \\ const a: Foo = undefined;
36 \\}
37 ,
38 ".tmp_source.zig:3:5: error: duplicate enum field: 'Bar'",
39 ".tmp_source.zig:2:5: note: other field here");
40
4 cases.add("calling function with naked calling convention",41 cases.add("calling function with naked calling convention",
5 \\export fn entry() void {42 \\export fn entry() void {
6 \\ foo();43 \\ foo();
...@@ -10,7 +47,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {...@@ -10,7 +47,6 @@ pub fn addCases(cases: &tests.CompileErrorContext) void {
10 ".tmp_source.zig:2:5: error: unable to call function with naked calling convention",47 ".tmp_source.zig:2:5: error: unable to call function with naked calling convention",
11 ".tmp_source.zig:4:9: note: declared here");48 ".tmp_source.zig:4:9: note: declared here");
1249
13
14 cases.add("function with invalid return type",50 cases.add("function with invalid return type",
15 \\export fn foo() boid {}51 \\export fn foo() boid {}
16 , ".tmp_source.zig:1:17: error: use of undeclared identifier 'boid'");52 , ".tmp_source.zig:1:17: error: use of undeclared identifier 'boid'");