authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-09 14:55:51-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-12-09 15:27:27-05:00
loga3f6a58c7785e7958f9d0b96d54356944bf34e32
tree4e7ce7220eaeda3f3ee60cc10e93c4708d688639
parentf205d23e650019dd66120cf122ffb449267f619b
signaturelock-open Commit is signed but in an unrecognized format.

remove var args from the language

closes #208

21 files changed, 2049 insertions(+), 2820 deletions(-)

doc/langref.html.in+1-4
......@@ -5862,7 +5862,7 @@ pub fn main() void {
58625862
58635863 {#code_begin|syntax#}
58645864/// Calls print and then flushes the buffer.
5865pub fn printf(self: *OutStream, comptime format: []const u8, args: ...) anyerror!void {
5865pub fn printf(self: *OutStream, comptime format: []const u8, args: var) anyerror!void {
58665866 const State = enum {
58675867 Start,
58685868 OpenBrace,
......@@ -8277,7 +8277,6 @@ test "integer truncation" {
82778277 <li>{#link|union#}</li>
82788278 <li>{#link|Functions#}</li>
82798279 <li>BoundFn</li>
8280 <li>ArgTuple</li>
82818280 <li>{#link|struct#}</li>
82828281 </ul>
82838282 {#header_close#}
......@@ -8310,7 +8309,6 @@ pub const TypeId = enum {
83108309 Fn,
83118310 Block,
83128311 BoundFn,
8313 ArgTuple,
83148312 Opaque,
83158313};
83168314 {#code_end#}
......@@ -8343,7 +8341,6 @@ pub const TypeInfo = union(TypeId) {
83438341 Union: Union,
83448342 Fn: Fn,
83458343 BoundFn: Fn,
8346 ArgTuple: void,
83478344 Opaque: void,
83488345 Promise: Promise,
83498346 Vector: Vector,
lib/std/builtin.zig-1
......@@ -116,7 +116,6 @@ pub const TypeInfo = union(enum) {
116116 Union: Union,
117117 Fn: Fn,
118118 BoundFn: Fn,
119 ArgTuple: void,
120119 Opaque: void,
121120 Frame: void,
122121 AnyFrame: AnyFrame,
lib/std/fmt.zig+4-6
......@@ -94,9 +94,7 @@ pub fn format(
9494 args: var,
9595) Errors!void {
9696 const ArgSetType = @IntType(false, 32);
97 const args_fields = std.meta.fields(@typeOf(args));
98 const args_len = args_fields.len;
99 if (args_len > ArgSetType.bit_count) {
97 if (args.len > ArgSetType.bit_count) {
10098 @compileError("32 arguments max are supported per format call");
10199 }
102100
......@@ -160,14 +158,14 @@ pub fn format(
160158 maybe_pos_arg.? += c - '0';
161159 specifier_start = i + 1;
162160
163 if (maybe_pos_arg.? >= args_len) {
161 if (maybe_pos_arg.? >= args.len) {
164162 @compileError("Positional value refers to non-existent argument");
165163 }
166164 },
167165 '}' => {
168166 const arg_to_print = comptime nextArg(&used_pos_args, maybe_pos_arg, &next_arg);
169167
170 if (arg_to_print >= args_len) {
168 if (arg_to_print >= args.len) {
171169 @compileError("Too few arguments");
172170 }
173171
......@@ -304,7 +302,7 @@ pub fn format(
304302 used_pos_args |= 1 << i;
305303 }
306304
307 if (@popCount(ArgSetType, used_pos_args) != args_len) {
305 if (@popCount(ArgSetType, used_pos_args) != args.len) {
308306 @compileError("Unused arguments");
309307 }
310308 if (state != State.Start) {
lib/std/hash/auto_hash.zig-1
......@@ -79,7 +79,6 @@ pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void {
7979 .NoReturn,
8080 .Opaque,
8181 .Undefined,
82 .ArgTuple,
8382 .Void,
8483 .Null,
8584 .BoundFn,
lib/std/special/docs/main.js+1-1
......@@ -1194,7 +1194,7 @@
11941194 // This is just for debugging purposes, not needed to function
11951195 var assertList = ["Type","Void","Bool","NoReturn","Int","Float","Pointer","Array","Struct",
11961196 "ComptimeFloat","ComptimeInt","Undefined","Null","Optional","ErrorUnion","ErrorSet","Enum",
1197 "Union","Fn","BoundFn","ArgTuple","Opaque","Frame","AnyFrame","Vector","EnumLiteral"];
1197 "Union","Fn","BoundFn","Opaque","Frame","AnyFrame","Vector","EnumLiteral"];
11981198 for (var i = 0; i < assertList.length; i += 1) {
11991199 if (map[assertList[i]] == null) throw new Error("No type kind '" + assertList[i] + "' found");
12001200 }
lib/std/testing.zig-1
......@@ -33,7 +33,6 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void {
3333 switch (@typeInfo(@typeOf(actual))) {
3434 .NoReturn,
3535 .BoundFn,
36 .ArgTuple,
3736 .Opaque,
3837 .Frame,
3938 .AnyFrame,
src-self-hosted/type.zig-12
......@@ -41,7 +41,6 @@ pub const Type = struct {
4141 .Enum => @fieldParentPtr(Enum, "base", base).destroy(comp),
4242 .Union => @fieldParentPtr(Union, "base", base).destroy(comp),
4343 .BoundFn => @fieldParentPtr(BoundFn, "base", base).destroy(comp),
44 .ArgTuple => @fieldParentPtr(ArgTuple, "base", base).destroy(comp),
4544 .Opaque => @fieldParentPtr(Opaque, "base", base).destroy(comp),
4645 .Frame => @fieldParentPtr(Frame, "base", base).destroy(comp),
4746 .AnyFrame => @fieldParentPtr(AnyFrame, "base", base).destroy(comp),
......@@ -76,7 +75,6 @@ pub const Type = struct {
7675 .Enum => return @fieldParentPtr(Enum, "base", base).getLlvmType(allocator, llvm_context),
7776 .Union => return @fieldParentPtr(Union, "base", base).getLlvmType(allocator, llvm_context),
7877 .BoundFn => return @fieldParentPtr(BoundFn, "base", base).getLlvmType(allocator, llvm_context),
79 .ArgTuple => unreachable,
8078 .Opaque => return @fieldParentPtr(Opaque, "base", base).getLlvmType(allocator, llvm_context),
8179 .Frame => return @fieldParentPtr(Frame, "base", base).getLlvmType(allocator, llvm_context),
8280 .AnyFrame => return @fieldParentPtr(AnyFrame, "base", base).getLlvmType(allocator, llvm_context),
......@@ -93,7 +91,6 @@ pub const Type = struct {
9391 .Undefined,
9492 .Null,
9593 .BoundFn,
96 .ArgTuple,
9794 .Opaque,
9895 => unreachable,
9996
......@@ -128,7 +125,6 @@ pub const Type = struct {
128125 .Undefined,
129126 .Null,
130127 .BoundFn,
131 .ArgTuple,
132128 .Opaque,
133129 => unreachable,
134130
......@@ -1004,14 +1000,6 @@ pub const Type = struct {
10041000 }
10051001 };
10061002
1007 pub const ArgTuple = struct {
1008 base: Type,
1009
1010 pub fn destroy(self: *ArgTuple, comp: *Compilation) void {
1011 comp.gpa().destroy(self);
1012 }
1013 };
1014
10151003 pub const Opaque = struct {
10161004 base: Type,
10171005
src/all_types.hpp-2
......@@ -1471,7 +1471,6 @@ enum ZigTypeId {
14711471 ZigTypeIdUnion,
14721472 ZigTypeIdFn,
14731473 ZigTypeIdBoundFn,
1474 ZigTypeIdArgTuple,
14751474 ZigTypeIdOpaque,
14761475 ZigTypeIdFnFrame,
14771476 ZigTypeIdAnyFrame,
......@@ -2039,7 +2038,6 @@ struct CodeGen {
20392038 ZigType *entry_null;
20402039 ZigType *entry_var;
20412040 ZigType *entry_global_error_set;
2042 ZigType *entry_arg_tuple;
20432041 ZigType *entry_enum_literal;
20442042 ZigType *entry_any_frame;
20452043 } builtin_types;
src/analyze.cpp+6-60
......@@ -323,7 +323,6 @@ AstNode *type_decl_node(ZigType *type_entry) {
323323 case ZigTypeIdErrorSet:
324324 case ZigTypeIdFn:
325325 case ZigTypeIdBoundFn:
326 case ZigTypeIdArgTuple:
327326 case ZigTypeIdVector:
328327 case ZigTypeIdAnyFrame:
329328 return nullptr;
......@@ -392,7 +391,6 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) {
392391 case ZigTypeIdErrorSet:
393392 case ZigTypeIdFn:
394393 case ZigTypeIdBoundFn:
395 case ZigTypeIdArgTuple:
396394 case ZigTypeIdVector:
397395 case ZigTypeIdAnyFrame:
398396 return true;
......@@ -1558,7 +1556,6 @@ static Error emit_error_unless_type_allowed_in_packed_container(CodeGen *g, ZigT
15581556 case ZigTypeIdErrorUnion:
15591557 case ZigTypeIdErrorSet:
15601558 case ZigTypeIdBoundFn:
1561 case ZigTypeIdArgTuple:
15621559 case ZigTypeIdOpaque:
15631560 case ZigTypeIdFnFrame:
15641561 case ZigTypeIdAnyFrame:
......@@ -1661,7 +1658,6 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) {
16611658 case ZigTypeIdErrorUnion:
16621659 case ZigTypeIdErrorSet:
16631660 case ZigTypeIdBoundFn:
1664 case ZigTypeIdArgTuple:
16651661 case ZigTypeIdVoid:
16661662 case ZigTypeIdFnFrame:
16671663 case ZigTypeIdAnyFrame:
......@@ -1786,12 +1782,9 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
17861782 if (fn_type_id.cc == CallingConventionC) {
17871783 fn_type_id.param_count = fn_type_id.next_param_index;
17881784 continue;
1789 } else if (calling_convention_allows_zig_types(fn_type_id.cc)) {
1790 return get_generic_fn_type(g, &fn_type_id);
17911785 } else {
17921786 add_node_error(g, param_node,
1793 buf_sprintf("var args not allowed in function with calling convention '%s'",
1794 calling_convention_name(fn_type_id.cc)));
1787 buf_sprintf("var args only allowed in functions with C calling convention"));
17951788 return g->builtin_types.entry_invalid;
17961789 }
17971790 } else if (param_node->data.param_decl.var_token != nullptr) {
......@@ -1838,7 +1831,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
18381831 case ZigTypeIdUnreachable:
18391832 case ZigTypeIdUndefined:
18401833 case ZigTypeIdNull:
1841 case ZigTypeIdArgTuple:
18421834 case ZigTypeIdOpaque:
18431835 add_node_error(g, param_node->data.param_decl.type,
18441836 buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name)));
......@@ -1913,7 +1905,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
19131905
19141906 case ZigTypeIdUndefined:
19151907 case ZigTypeIdNull:
1916 case ZigTypeIdArgTuple:
19171908 add_node_error(g, fn_proto->return_type,
19181909 buf_sprintf("return type '%s' not allowed", buf_ptr(&specified_return_type->name)));
19191910 return g->builtin_types.entry_invalid;
......@@ -1963,7 +1954,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
19631954 case ZigTypeIdInvalid:
19641955 case ZigTypeIdUndefined:
19651956 case ZigTypeIdNull:
1966 case ZigTypeIdArgTuple:
19671957 case ZigTypeIdOpaque:
19681958 zig_unreachable();
19691959
......@@ -3720,7 +3710,6 @@ ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry
37203710 case ZigTypeIdUnreachable:
37213711 case ZigTypeIdUndefined:
37223712 case ZigTypeIdNull:
3723 case ZigTypeIdArgTuple:
37243713 case ZigTypeIdOpaque:
37253714 add_node_error(g, source_node, buf_sprintf("variable of type '%s' not allowed",
37263715 buf_ptr(&type_entry->name)));
......@@ -4275,7 +4264,6 @@ bool is_container(ZigType *type_entry) {
42754264 case ZigTypeIdErrorSet:
42764265 case ZigTypeIdFn:
42774266 case ZigTypeIdBoundFn:
4278 case ZigTypeIdArgTuple:
42794267 case ZigTypeIdOpaque:
42804268 case ZigTypeIdVector:
42814269 case ZigTypeIdFnFrame:
......@@ -4982,7 +4970,6 @@ bool handle_is_ptr(ZigType *type_entry) {
49824970 case ZigTypeIdUndefined:
49834971 case ZigTypeIdNull:
49844972 case ZigTypeIdBoundFn:
4985 case ZigTypeIdArgTuple:
49864973 case ZigTypeIdOpaque:
49874974 zig_unreachable();
49884975 case ZigTypeIdUnreachable:
......@@ -5201,9 +5188,6 @@ static uint32_t hash_const_val(ZigValue *const_val) {
52015188 memcpy(&ints[0], &f128, 16);
52025189 return ints[0] ^ ints[1] ^ ints[2] ^ ints[3] ^ 0xed8b3dfb;
52035190 }
5204 case ZigTypeIdArgTuple:
5205 return (uint32_t)const_val->data.x_arg_tuple.start_index * (uint32_t)281907309 +
5206 (uint32_t)const_val->data.x_arg_tuple.end_index * (uint32_t)2290442768;
52075191 case ZigTypeIdFn:
52085192 assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst);
52095193 assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction);
......@@ -5357,9 +5341,6 @@ static bool can_mutate_comptime_var_state(ZigValue *value) {
53575341
53585342 case ZigTypeIdUnion:
53595343 return can_mutate_comptime_var_state(value->data.x_union.payload);
5360
5361 case ZigTypeIdArgTuple:
5362 zig_panic("TODO var args at comptime is currently not supported");
53635344 }
53645345 zig_unreachable();
53655346}
......@@ -5400,9 +5381,6 @@ static bool return_type_is_cacheable(ZigType *return_type) {
54005381
54015382 case ZigTypeIdErrorUnion:
54025383 return return_type_is_cacheable(return_type->data.error_union.payload_type);
5403
5404 case ZigTypeIdArgTuple:
5405 zig_panic("TODO var args at comptime is currently not supported");
54065384 }
54075385 zig_unreachable();
54085386}
......@@ -5540,7 +5518,6 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) {
55405518 case ZigTypeIdEnumLiteral:
55415519 case ZigTypeIdMetaType:
55425520 case ZigTypeIdBoundFn:
5543 case ZigTypeIdArgTuple:
55445521 case ZigTypeIdOptional:
55455522 case ZigTypeIdFn:
55465523 case ZigTypeIdBool:
......@@ -5626,7 +5603,6 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty) {
56265603 case ZigTypeIdNull:
56275604 case ZigTypeIdMetaType:
56285605 case ZigTypeIdBoundFn:
5629 case ZigTypeIdArgTuple:
56305606 return ReqCompTimeYes;
56315607 case ZigTypeIdArray:
56325608 return type_requires_comptime(g, ty->data.array.child_type);
......@@ -5918,20 +5894,6 @@ ZigValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type,
59185894 return const_val;
59195895}
59205896
5921void init_const_arg_tuple(CodeGen *g, ZigValue *const_val, size_t arg_index_start, size_t arg_index_end) {
5922 const_val->special = ConstValSpecialStatic;
5923 const_val->type = g->builtin_types.entry_arg_tuple;
5924 const_val->data.x_arg_tuple.start_index = arg_index_start;
5925 const_val->data.x_arg_tuple.end_index = arg_index_end;
5926}
5927
5928ZigValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end) {
5929 ZigValue *const_val = create_const_vals(1);
5930 init_const_arg_tuple(g, const_val, arg_index_start, arg_index_end);
5931 return const_val;
5932}
5933
5934
59355897ZigValue *create_const_vals(size_t count) {
59365898 return allocate<ZigValue>(count, "ZigValue");
59375899}
......@@ -6679,9 +6641,6 @@ bool const_values_equal(CodeGen *g, ZigValue *a, ZigValue *b) {
66796641 }
66806642 case ZigTypeIdErrorUnion:
66816643 zig_panic("TODO");
6682 case ZigTypeIdArgTuple:
6683 return a->data.x_arg_tuple.start_index == b->data.x_arg_tuple.start_index &&
6684 a->data.x_arg_tuple.end_index == b->data.x_arg_tuple.end_index;
66856644 case ZigTypeIdBoundFn:
66866645 case ZigTypeIdInvalid:
66876646 case ZigTypeIdUnreachable:
......@@ -7008,11 +6967,6 @@ void render_const_value(CodeGen *g, Buf *buf, ZigValue *const_val) {
70086967 }
70096968 case ZigTypeIdErrorSet:
70106969 return render_const_val_err_set(g, buf, const_val, type_entry);
7011 case ZigTypeIdArgTuple:
7012 {
7013 buf_appendf(buf, "(args value)");
7014 return;
7015 }
70166970 case ZigTypeIdFnFrame:
70176971 buf_appendf(buf, "(TODO: async function frame value)");
70186972 return;
......@@ -7075,7 +7029,6 @@ uint32_t type_id_hash(TypeId x) {
70757029 case ZigTypeIdUnion:
70767030 case ZigTypeIdFn:
70777031 case ZigTypeIdBoundFn:
7078 case ZigTypeIdArgTuple:
70797032 case ZigTypeIdFnFrame:
70807033 case ZigTypeIdAnyFrame:
70817034 zig_unreachable();
......@@ -7127,7 +7080,6 @@ bool type_id_eql(TypeId a, TypeId b) {
71277080 case ZigTypeIdUnion:
71287081 case ZigTypeIdFn:
71297082 case ZigTypeIdBoundFn:
7130 case ZigTypeIdArgTuple:
71317083 case ZigTypeIdOpaque:
71327084 case ZigTypeIdFnFrame:
71337085 case ZigTypeIdAnyFrame:
......@@ -7350,7 +7302,6 @@ static const ZigTypeId all_type_ids[] = {
73507302 ZigTypeIdUnion,
73517303 ZigTypeIdFn,
73527304 ZigTypeIdBoundFn,
7353 ZigTypeIdArgTuple,
73547305 ZigTypeIdOpaque,
73557306 ZigTypeIdFnFrame,
73567307 ZigTypeIdAnyFrame,
......@@ -7413,18 +7364,16 @@ size_t type_id_index(ZigType *entry) {
74137364 return 18;
74147365 case ZigTypeIdBoundFn:
74157366 return 19;
7416 case ZigTypeIdArgTuple:
7417 return 20;
74187367 case ZigTypeIdOpaque:
7419 return 21;
7368 return 20;
74207369 case ZigTypeIdFnFrame:
7421 return 22;
7370 return 21;
74227371 case ZigTypeIdAnyFrame:
7423 return 23;
7372 return 22;
74247373 case ZigTypeIdVector:
7425 return 24;
7374 return 23;
74267375 case ZigTypeIdEnumLiteral:
7427 return 25;
7376 return 24;
74287377 }
74297378 zig_unreachable();
74307379}
......@@ -7475,8 +7424,6 @@ const char *type_id_name(ZigTypeId id) {
74757424 return "Fn";
74767425 case ZigTypeIdBoundFn:
74777426 return "BoundFn";
7478 case ZigTypeIdArgTuple:
7479 return "ArgTuple";
74807427 case ZigTypeIdOpaque:
74817428 return "Opaque";
74827429 case ZigTypeIdVector:
......@@ -9064,7 +9011,6 @@ static void resolve_llvm_types(CodeGen *g, ZigType *type, ResolveStatus wanted_r
90649011 case ZigTypeIdUndefined:
90659012 case ZigTypeIdNull:
90669013 case ZigTypeIdBoundFn:
9067 case ZigTypeIdArgTuple:
90689014 zig_unreachable();
90699015 case ZigTypeIdFloat:
90709016 case ZigTypeIdOpaque:
src/analyze.hpp-3
......@@ -171,9 +171,6 @@ void init_const_slice(CodeGen *g, ZigValue *const_val, ZigValue *array_val,
171171 size_t start, size_t len, bool is_const);
172172ZigValue *create_const_slice(CodeGen *g, ZigValue *array_val, size_t start, size_t len, bool is_const);
173173
174void init_const_arg_tuple(CodeGen *g, ZigValue *const_val, size_t arg_index_start, size_t arg_index_end);
175ZigValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end);
176
177174void init_const_null(ZigValue *const_val, ZigType *type);
178175ZigValue *create_const_null(ZigType *type);
179176
src/codegen.cpp-10
......@@ -6539,7 +6539,6 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Zig
65396539 case ZigTypeIdErrorUnion:
65406540 case ZigTypeIdErrorSet:
65416541 case ZigTypeIdBoundFn:
6542 case ZigTypeIdArgTuple:
65436542 case ZigTypeIdVoid:
65446543 case ZigTypeIdOpaque:
65456544 zig_unreachable();
......@@ -7182,7 +7181,6 @@ check: switch (const_val->special) {
71827181 case ZigTypeIdUndefined:
71837182 case ZigTypeIdNull:
71847183 case ZigTypeIdBoundFn:
7185 case ZigTypeIdArgTuple:
71867184 case ZigTypeIdOpaque:
71877185 zig_unreachable();
71887186 case ZigTypeIdFnFrame:
......@@ -7887,11 +7885,6 @@ static void define_builtin_types(CodeGen *g) {
78877885 buf_init_from_str(&entry->name, "(var)");
78887886 g->builtin_types.entry_var = entry;
78897887 }
7890 {
7891 ZigType *entry = new_type_table_entry(ZigTypeIdArgTuple);
7892 buf_init_from_str(&entry->name, "(args)");
7893 g->builtin_types.entry_arg_tuple = entry;
7894 }
78957888
78967889 for (size_t i = 0; i < array_length(c_int_type_infos); i += 1) {
78977890 const CIntTypeInfo *info = &c_int_type_infos[i];
......@@ -9532,7 +9525,6 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e
95329525 case ZigTypeIdUndefined:
95339526 case ZigTypeIdNull:
95349527 case ZigTypeIdBoundFn:
9535 case ZigTypeIdArgTuple:
95369528 case ZigTypeIdErrorUnion:
95379529 case ZigTypeIdErrorSet:
95389530 case ZigTypeIdFnFrame:
......@@ -9721,7 +9713,6 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu
97219713 case ZigTypeIdEnumLiteral:
97229714 case ZigTypeIdUndefined:
97239715 case ZigTypeIdNull:
9724 case ZigTypeIdArgTuple:
97259716 case ZigTypeIdFnFrame:
97269717 case ZigTypeIdAnyFrame:
97279718 zig_unreachable();
......@@ -9781,7 +9772,6 @@ static void gen_h_file_types(CodeGen* g, GenH* gen_h, Buf* out_buf) {
97819772 case ZigTypeIdErrorUnion:
97829773 case ZigTypeIdErrorSet:
97839774 case ZigTypeIdBoundFn:
9784 case ZigTypeIdArgTuple:
97859775 case ZigTypeIdOptional:
97869776 case ZigTypeIdFn:
97879777 case ZigTypeIdVector:
src/ir.cpp+22-216
......@@ -780,7 +780,6 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte
780780 case ZigTypeIdErrorUnion:
781781 case ZigTypeIdEnum:
782782 case ZigTypeIdUnion:
783 case ZigTypeIdArgTuple:
784783 case ZigTypeIdVector:
785784 case ZigTypeIdFnFrame:
786785 return false;
......@@ -14791,7 +14790,6 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *
1479114790 case ZigTypeIdFn:
1479214791 case ZigTypeIdOpaque:
1479314792 case ZigTypeIdBoundFn:
14794 case ZigTypeIdArgTuple:
1479514793 case ZigTypeIdEnum:
1479614794 case ZigTypeIdEnumLiteral:
1479714795 case ZigTypeIdAnyFrame:
......@@ -16437,7 +16435,6 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1643716435 case ZigTypeIdErrorUnion:
1643816436 case ZigTypeIdErrorSet:
1643916437 case ZigTypeIdBoundFn:
16440 case ZigTypeIdArgTuple:
1644116438 case ZigTypeIdOpaque:
1644216439 case ZigTypeIdFnFrame:
1644316440 case ZigTypeIdAnyFrame:
......@@ -16462,7 +16459,6 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio
1646216459 case ZigTypeIdVector:
1646316460 zig_panic("TODO export const value of type %s", buf_ptr(&target->value->type->name));
1646416461 case ZigTypeIdBoundFn:
16465 case ZigTypeIdArgTuple:
1646616462 case ZigTypeIdOpaque:
1646716463 case ZigTypeIdEnumLiteral:
1646816464 case ZigTypeIdFnFrame:
......@@ -16609,7 +16605,6 @@ static bool type_can_bit_cast(ZigType *t) {
1660916605 case ZigTypeIdMetaType:
1661016606 case ZigTypeIdOpaque:
1661116607 case ZigTypeIdBoundFn:
16612 case ZigTypeIdArgTuple:
1661316608 case ZigTypeIdUnreachable:
1661416609 case ZigTypeIdComptimeFloat:
1661516610 case ZigTypeIdComptimeInt:
......@@ -17416,23 +17411,6 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
1741617411 return true;
1741717412}
1741817413
17419static ZigVar *get_fn_var_by_index(ZigFn *fn_entry, size_t index) {
17420 FnTypeParamInfo *src_param_info = &fn_entry->type_entry->data.fn.fn_type_id.param_info[index];
17421 if (!type_has_bits(src_param_info->type))
17422 return nullptr;
17423
17424 size_t next_var_i = 0;
17425 for (size_t param_i = 0; param_i < index; param_i += 1) {
17426 FnTypeParamInfo *src_param_info = &fn_entry->type_entry->data.fn.fn_type_id.param_info[param_i];
17427 if (!type_has_bits(src_param_info->type)) {
17428 continue;
17429 }
17430
17431 next_var_i += 1;
17432 }
17433 return fn_entry->variable_list.at(next_var_i);
17434}
17435
1743617414static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var) {
1743717415 while (var->next_var != nullptr) {
1743817416 var = var->next_var;
......@@ -17690,16 +17668,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1769017668 var_args_1_or_0 = fn_type_id->is_var_args ? 1 : 0;
1769117669 }
1769217670 size_t src_param_count = fn_type_id->param_count - var_args_1_or_0;
17693
1769417671 size_t call_param_count = args_len + first_arg_1_or_0;
17695 for (size_t i = 0; i < args_len; i += 1) {
17696 ZigValue *arg_tuple_value = args_ptr[i]->value;
17697 if (arg_tuple_value->type->id == ZigTypeIdArgTuple) {
17698 call_param_count -= 1;
17699 call_param_count += arg_tuple_value->data.x_arg_tuple.end_index -
17700 arg_tuple_value->data.x_arg_tuple.start_index;
17701 }
17702 }
1770317672 AstNode *source_node = source_instr->source_node;
1770417673
1770517674 AstNode *fn_proto_node = fn_entry ? fn_entry->proto_node : nullptr;;
......@@ -17854,16 +17823,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1785417823 return ira->codegen->invalid_instruction;
1785517824 }
1785617825
17857 // Count the arguments of the function type id we are creating
17858 size_t new_fn_arg_count = first_arg_1_or_0;
17859 for (size_t call_i = 0; call_i < args_len; call_i += 1) {
17860 IrInstruction *arg = args_ptr[call_i];
17861 if (arg->value->type->id == ZigTypeIdArgTuple) {
17862 new_fn_arg_count += arg->value->data.x_arg_tuple.end_index - arg->value->data.x_arg_tuple.start_index;
17863 } else {
17864 new_fn_arg_count += 1;
17865 }
17866 }
17826 size_t new_fn_arg_count = first_arg_1_or_0 + args_len;
1786717827
1786817828 IrInstruction **casted_args = allocate<IrInstruction *>(new_fn_arg_count);
1786917829
......@@ -17914,76 +17874,19 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1791417874 }
1791517875 }
1791617876
17917 bool found_first_var_arg = false;
17918 size_t first_var_arg;
17919
1792017877 ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec);
1792117878 assert(parent_fn_entry);
1792217879 for (size_t call_i = 0; call_i < args_len; call_i += 1) {
1792317880 IrInstruction *arg = args_ptr[call_i];
1792417881
17925 if (arg->value->type->id == ZigTypeIdArgTuple) {
17926 for (size_t arg_tuple_i = arg->value->data.x_arg_tuple.start_index;
17927 arg_tuple_i < arg->value->data.x_arg_tuple.end_index; arg_tuple_i += 1)
17928 {
17929 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i);
17930 assert(param_decl_node->type == NodeTypeParamDecl);
17931 bool is_var_args = param_decl_node->data.param_decl.is_var_args;
17932 if (is_var_args && !found_first_var_arg) {
17933 first_var_arg = inst_fn_type_id.param_count;
17934 found_first_var_arg = true;
17935 }
17936
17937 ZigVar *arg_var = get_fn_var_by_index(parent_fn_entry, arg_tuple_i);
17938 if (arg_var == nullptr) {
17939 ir_add_error(ira, arg,
17940 buf_sprintf("compiler bug: var args can't handle void. https://github.com/ziglang/zig/issues/557"));
17941 return ira->codegen->invalid_instruction;
17942 }
17943 IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, arg, arg_var);
17944 if (type_is_invalid(arg_var_ptr_inst->value->type))
17945 return ira->codegen->invalid_instruction;
17946
17947 IrInstruction *arg_tuple_arg = ir_get_deref(ira, arg, arg_var_ptr_inst, nullptr);
17948 if (type_is_invalid(arg_tuple_arg->value->type))
17949 return ira->codegen->invalid_instruction;
17950
17951 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg_tuple_arg, &impl_fn->child_scope,
17952 &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn))
17953 {
17954 return ira->codegen->invalid_instruction;
17955 }
17956 }
17957 } else {
17958 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i);
17959 assert(param_decl_node->type == NodeTypeParamDecl);
17960 bool is_var_args = param_decl_node->data.param_decl.is_var_args;
17961 if (is_var_args && !found_first_var_arg) {
17962 first_var_arg = inst_fn_type_id.param_count;
17963 found_first_var_arg = true;
17964 }
17965
17966 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, &impl_fn->child_scope,
17967 &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn))
17968 {
17969 return ira->codegen->invalid_instruction;
17970 }
17971 }
17972 }
17973
17974 if (fn_proto_node->data.fn_proto.is_var_args) {
1797517882 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i);
17976 Buf *param_name = param_decl_node->data.param_decl.name;
17883 assert(param_decl_node->type == NodeTypeParamDecl);
1797717884
17978 if (!found_first_var_arg) {
17979 first_var_arg = inst_fn_type_id.param_count;
17885 if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, &impl_fn->child_scope,
17886 &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn))
17887 {
17888 return ira->codegen->invalid_instruction;
1798017889 }
17981
17982 ZigValue *var_args_val = create_const_arg_tuple(ira->codegen,
17983 first_var_arg, inst_fn_type_id.param_count);
17984 ZigVar *var = add_variable(ira->codegen, param_decl_node,
17985 impl_fn->child_scope, param_name, true, var_args_val, nullptr, var_args_val->type);
17986 impl_fn->child_scope = var->child_scope;
1798717890 }
1798817891
1798917892 if (fn_proto_node->data.fn_proto.align_expr != nullptr) {
......@@ -18153,55 +18056,20 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i
1815318056 if (type_is_invalid(old_arg->value->type))
1815418057 return ira->codegen->invalid_instruction;
1815518058
18156 if (old_arg->value->type->id == ZigTypeIdArgTuple) {
18157 for (size_t arg_tuple_i = old_arg->value->data.x_arg_tuple.start_index;
18158 arg_tuple_i < old_arg->value->data.x_arg_tuple.end_index; arg_tuple_i += 1)
18159 {
18160 ZigVar *arg_var = get_fn_var_by_index(parent_fn_entry, arg_tuple_i);
18161 if (arg_var == nullptr) {
18162 ir_add_error(ira, old_arg,
18163 buf_sprintf("compiler bug: var args can't handle void. https://github.com/ziglang/zig/issues/557"));
18164 return ira->codegen->invalid_instruction;
18165 }
18166 IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, old_arg, arg_var);
18167 if (type_is_invalid(arg_var_ptr_inst->value->type))
18168 return ira->codegen->invalid_instruction;
18169
18170 IrInstruction *arg_tuple_arg = ir_get_deref(ira, old_arg, arg_var_ptr_inst, nullptr);
18171 if (type_is_invalid(arg_tuple_arg->value->type))
18172 return ira->codegen->invalid_instruction;
18173
18174 IrInstruction *casted_arg;
18175 if (next_arg_index < src_param_count) {
18176 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
18177 if (type_is_invalid(param_type))
18178 return ira->codegen->invalid_instruction;
18179 casted_arg = ir_implicit_cast(ira, arg_tuple_arg, param_type);
18180 if (type_is_invalid(casted_arg->value->type))
18181 return ira->codegen->invalid_instruction;
18182 } else {
18183 casted_arg = arg_tuple_arg;
18184 }
18185
18186 casted_args[next_arg_index] = casted_arg;
18187 next_arg_index += 1;
18188 }
18059 IrInstruction *casted_arg;
18060 if (next_arg_index < src_param_count) {
18061 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
18062 if (type_is_invalid(param_type))
18063 return ira->codegen->invalid_instruction;
18064 casted_arg = ir_implicit_cast(ira, old_arg, param_type);
18065 if (type_is_invalid(casted_arg->value->type))
18066 return ira->codegen->invalid_instruction;
1818918067 } else {
18190 IrInstruction *casted_arg;
18191 if (next_arg_index < src_param_count) {
18192 ZigType *param_type = fn_type_id->param_info[next_arg_index].type;
18193 if (type_is_invalid(param_type))
18194 return ira->codegen->invalid_instruction;
18195 casted_arg = ir_implicit_cast(ira, old_arg, param_type);
18196 if (type_is_invalid(casted_arg->value->type))
18197 return ira->codegen->invalid_instruction;
18198 } else {
18199 casted_arg = old_arg;
18200 }
18201
18202 casted_args[next_arg_index] = casted_arg;
18203 next_arg_index += 1;
18068 casted_arg = old_arg;
1820418069 }
18070
18071 casted_args[next_arg_index] = casted_arg;
18072 next_arg_index += 1;
1820518073 }
1820618074
1820718075 assert(next_arg_index == call_param_count);
......@@ -19186,37 +19054,6 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1918619054 } else if (is_slice(array_type)) {
1918719055 return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index]->type_entry,
1918819056 elem_ptr_instruction->ptr_len);
19189 } else if (array_type->id == ZigTypeIdArgTuple) {
19190 ZigValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad);
19191 if (!ptr_val)
19192 return ira->codegen->invalid_instruction;
19193 ZigValue *args_val = const_ptr_pointee(ira, ira->codegen, ptr_val, elem_ptr_instruction->base.source_node);
19194 if (args_val == nullptr)
19195 return ira->codegen->invalid_instruction;
19196 size_t start = args_val->data.x_arg_tuple.start_index;
19197 size_t end = args_val->data.x_arg_tuple.end_index;
19198 uint64_t elem_index_val;
19199 if (!ir_resolve_usize(ira, elem_index, &elem_index_val))
19200 return ira->codegen->invalid_instruction;
19201 size_t index = elem_index_val;
19202 size_t len = end - start;
19203 if (index >= len) {
19204 ir_add_error(ira, &elem_ptr_instruction->base,
19205 buf_sprintf("index %" ZIG_PRI_usize " outside argument list of size %" ZIG_PRI_usize "", index, len));
19206 return ira->codegen->invalid_instruction;
19207 }
19208 size_t abs_index = start + index;
19209 ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec);
19210 assert(fn_entry);
19211 ZigVar *var = get_fn_var_by_index(fn_entry, abs_index);
19212 bool is_const = true;
19213 bool is_volatile = false;
19214 if (var) {
19215 return ir_get_var_ptr(ira, &elem_ptr_instruction->base, var);
19216 } else {
19217 return ir_get_const_ptr(ira, &elem_ptr_instruction->base, ira->codegen->intern.for_void(),
19218 ira->codegen->builtin_types.entry_void, ConstPtrMutComptimeConst, is_const, is_volatile, 0);
19219 }
1922019057 } else if (array_type->id == ZigTypeIdVector) {
1922119058 // This depends on whether the element index is comptime, so it is computed later.
1922219059 return_type = nullptr;
......@@ -20025,6 +19862,10 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
2002519862
2002619863 if (type_is_invalid(container_type)) {
2002719864 return ira->codegen->invalid_instruction;
19865 } else if (is_tuple(container_type) && !field_ptr_instruction->initializing && buf_eql_str(field_name, "len")) {
19866 IrInstruction *len_inst = ir_const_unsigned(ira, &field_ptr_instruction->base,
19867 container_type->data.structure.src_field_count);
19868 return ir_get_ref(ira, &field_ptr_instruction->base, len_inst, true, false);
2002819869 } else if (is_slice(container_type) || is_container_ref(container_type)) {
2002919870 assert(container_ptr->value->type->id == ZigTypeIdPointer);
2003019871 if (container_type->id == ZigTypeIdPointer) {
......@@ -20045,32 +19886,6 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc
2004519886 init_const_usize(ira->codegen, len_val, container_type->data.array.len);
2004619887 }
2004719888
20048 ZigType *usize = ira->codegen->builtin_types.entry_usize;
20049 bool ptr_is_const = true;
20050 bool ptr_is_volatile = false;
20051 return ir_get_const_ptr(ira, &field_ptr_instruction->base, len_val,
20052 usize, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0);
20053 } else {
20054 ir_add_error_node(ira, source_node,
20055 buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name),
20056 buf_ptr(&container_type->name)));
20057 return ira->codegen->invalid_instruction;
20058 }
20059 } else if (container_type->id == ZigTypeIdArgTuple) {
20060 ZigValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
20061 if (!container_ptr_val)
20062 return ira->codegen->invalid_instruction;
20063
20064 assert(container_ptr->value->type->id == ZigTypeIdPointer);
20065 ZigValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node);
20066 if (child_val == nullptr)
20067 return ira->codegen->invalid_instruction;
20068
20069 if (buf_eql_str(field_name, "len")) {
20070 ZigValue *len_val = create_const_vals(1);
20071 size_t len = child_val->data.x_arg_tuple.end_index - child_val->data.x_arg_tuple.start_index;
20072 init_const_usize(ira->codegen, len_val, len);
20073
2007419889 ZigType *usize = ira->codegen->builtin_types.entry_usize;
2007519890 bool ptr_is_const = true;
2007619891 bool ptr_is_volatile = false;
......@@ -21258,7 +21073,6 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira,
2125821073 case ZigTypeIdNull:
2125921074 case ZigTypeIdOptional:
2126021075 case ZigTypeIdBoundFn:
21261 case ZigTypeIdArgTuple:
2126221076 case ZigTypeIdOpaque:
2126321077 case ZigTypeIdVector:
2126421078 case ZigTypeIdFnFrame:
......@@ -22580,7 +22394,6 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
2258022394 case ZigTypeIdEnumLiteral:
2258122395 case ZigTypeIdUndefined:
2258222396 case ZigTypeIdNull:
22583 case ZigTypeIdArgTuple:
2258422397 case ZigTypeIdOpaque:
2258522398 result = ira->codegen->intern.for_void();
2258622399 break;
......@@ -23357,7 +23170,6 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi
2335723170 case ZigTypeIdUnion:
2335823171 case ZigTypeIdFn:
2335923172 case ZigTypeIdBoundFn:
23360 case ZigTypeIdArgTuple:
2336123173 case ZigTypeIdStruct:
2336223174 ir_add_error(ira, instruction, buf_sprintf(
2336323175 "@Type not availble for 'TypeInfo.%s'", type_id_name(tagTypeId)));
......@@ -26452,7 +26264,6 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ZigValue *val)
2645226264 case ZigTypeIdMetaType:
2645326265 case ZigTypeIdOpaque:
2645426266 case ZigTypeIdBoundFn:
26455 case ZigTypeIdArgTuple:
2645626267 case ZigTypeIdUnreachable:
2645726268 case ZigTypeIdComptimeFloat:
2645826269 case ZigTypeIdComptimeInt:
......@@ -26609,7 +26420,6 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou
2660926420 case ZigTypeIdMetaType:
2661026421 case ZigTypeIdOpaque:
2661126422 case ZigTypeIdBoundFn:
26612 case ZigTypeIdArgTuple:
2661326423 case ZigTypeIdUnreachable:
2661426424 case ZigTypeIdComptimeFloat:
2661526425 case ZigTypeIdComptimeInt:
......@@ -28838,7 +28648,6 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2883828648 case ZigTypeIdUndefined:
2883928649 case ZigTypeIdNull:
2884028650 case ZigTypeIdBoundFn:
28841 case ZigTypeIdArgTuple:
2884228651 case ZigTypeIdVoid:
2884328652 case ZigTypeIdOpaque:
2884428653 ir_add_error(ira, lazy_align_of->target_type,
......@@ -28890,7 +28699,6 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2889028699 case ZigTypeIdUndefined:
2889128700 case ZigTypeIdNull:
2889228701 case ZigTypeIdBoundFn:
28893 case ZigTypeIdArgTuple:
2889428702 case ZigTypeIdOpaque:
2889528703 ir_add_error(ira, lazy_size_of->target_type,
2889628704 buf_sprintf("no size available for type '%s'",
......@@ -28969,7 +28777,6 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2896928777 case ZigTypeIdUnreachable:
2897028778 case ZigTypeIdUndefined:
2897128779 case ZigTypeIdNull:
28972 case ZigTypeIdArgTuple:
2897328780 case ZigTypeIdOpaque:
2897428781 ir_add_error(ira, lazy_slice_type->elem_type,
2897528782 buf_sprintf("slice of type '%s' not allowed", buf_ptr(&elem_type->name)));
......@@ -29102,7 +28909,6 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) {
2910228909 case ZigTypeIdUnreachable:
2910328910 case ZigTypeIdUndefined:
2910428911 case ZigTypeIdNull:
29105 case ZigTypeIdArgTuple:
2910628912 case ZigTypeIdOpaque:
2910728913 ir_add_error(ira, lazy_array_type->elem_type,
2910828914 buf_sprintf("array of type '%s' not allowed",
src/parser.cpp-6
......@@ -802,12 +802,6 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc) {
802802 res->data.fn_proto.auto_err_set = exmark != nullptr;
803803 res->data.fn_proto.return_type = return_type;
804804
805 // It seems that the Zig compiler expects varargs to be the
806 // last parameter in the decl list. This is not encoded in
807 // the grammar, which allows varargs anywhere in the decl.
808 // Since varargs is gonna be removed at some point, I'm not
809 // gonna encode this "varargs is always last" rule in the
810 // grammar, and just enforce it here, until varargs is removed.
811805 for (size_t i = 0; i < params.length; i++) {
812806 AstNode *param_decl = params.at(i);
813807 assert(param_decl->type == NodeTypeParamDecl);
test/compile_errors.zig+1639-2202
......@@ -2,6 +2,15 @@ const tests = @import("tests.zig");
22const builtin = @import("builtin");
33
44pub fn addCases(cases: *tests.CompileErrorContext) void {
5 cases.add("var args without c calling conv",
6 \\fn foo(args: ...) void {}
7 \\comptime {
8 \\ _ = foo;
9 \\}
10 , &[_][]const u8{
11 "tmp.zig:1:8: error: var args only allowed in functions with C calling convention",
12 });
13
514 cases.add("comptime struct field, no init value",
615 \\const Foo = struct {
716 \\ comptime b: i32,
......@@ -9,10 +18,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
918 \\export fn entry() void {
1019 \\ var f: Foo = undefined;
1120 \\}
12 , "tmp.zig:2:5: error: comptime struct field missing initialization value");
21 , &[_][]const u8{
22 "tmp.zig:2:5: error: comptime struct field missing initialization value",
23 });
1324
14 cases.add(
15 "bad usage of @call",
25 cases.add("bad usage of @call",
1626 \\export fn entry1() void {
1727 \\ @call(.{}, foo, {});
1828 \\}
......@@ -33,24 +43,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3343 \\inline fn bar() void {}
3444 \\fn baz1() void {}
3545 \\fn baz2() void {}
36 ,
46 , &[_][]const u8{
3747 "tmp.zig:2:21: error: expected tuple or struct, found 'void'",
3848 "tmp.zig:5:14: error: unable to perform 'never_inline' call at compile-time",
3949 "tmp.zig:8:14: error: unable to perform 'never_tail' call at compile-time",
4050 "tmp.zig:11:5: error: no-inline call of inline function",
4151 "tmp.zig:15:43: error: unable to evaluate constant expression",
42 );
52 });
4353
4454 cases.add("exported async function",
4555 \\export async fn foo() void {}
46 , "tmp.zig:1:1: error: exported function cannot be async");
56 , &[_][]const u8{
57 "tmp.zig:1:1: error: exported function cannot be async",
58 });
4759
48 cases.addExe(
49 "main missing name",
60 cases.addExe("main missing name",
5061 \\pub fn (main) void {}
51 ,
62 , &[_][]const u8{
5263 "tmp.zig:1:5: error: missing function name",
53 );
64 });
5465
5566 cases.addCase(x: {
5667 var tc = cases.create("call with new stack on unsupported target",
......@@ -59,7 +70,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5970 \\ @call(.{.stack = &buf}, foo, .{});
6071 \\}
6172 \\fn foo() void {}
62 , "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack");
73 , &[_][]const u8{
74 "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack",
75 });
6376 tc.target = tests.Target{
6477 .Cross = tests.CrossTarget{
6578 .arch = .wasm32,
......@@ -72,8 +85,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
7285
7386 // Note: One of the error messages here is backwards. It would be nice to fix, but that's not
7487 // going to stop me from merging this branch which fixes a bunch of other stuff.
75 cases.add(
76 "incompatible sentinels",
88 cases.add("incompatible sentinels",
7789 \\export fn entry1(ptr: [*:255]u8) [*:0]u8 {
7890 \\ return ptr;
7991 \\}
......@@ -86,7 +98,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
8698 \\export fn entry4() void {
8799 \\ var array: [2:0]u8 = [_]u8{1, 2};
88100 \\}
89 ,
101 , &[_][]const u8{
90102 "tmp.zig:2:12: error: expected type '[*:0]u8', found '[*:255]u8'",
91103 "tmp.zig:2:12: note: destination pointer requires a terminating '0' sentinel, but source pointer has a terminating '255' sentinel",
92104 "tmp.zig:5:12: error: expected type '[*:0]u8', found '[*]u8'",
......@@ -96,20 +108,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
96108 "tmp.zig:8:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel",
97109 "tmp.zig:11:31: error: expected type '[2:0]u8', found '[2]u8'",
98110 "tmp.zig:11:31: note: destination array requires a terminating '0' sentinel",
99 );
111 });
100112
101 cases.add(
102 "empty switch on an integer",
113 cases.add("empty switch on an integer",
103114 \\export fn entry() void {
104115 \\ var x: u32 = 0;
105116 \\ switch(x) {}
106117 \\}
107 ,
118 , &[_][]const u8{
108119 "tmp.zig:3:5: error: switch must handle all possibilities",
109 );
120 });
110121
111 cases.add(
112 "incorrect return type",
122 cases.add("incorrect return type",
113123 \\ pub export fn entry() void{
114124 \\ _ = foo();
115125 \\ }
......@@ -125,12 +135,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
125135 \\ fn bar() B {
126136 \\ unreachable;
127137 \\ }
128 ,
138 , &[_][]const u8{
129139 "tmp.zig:8:16: error: expected type 'A', found 'B'",
130 );
140 });
131141
132 cases.add(
133 "regression test #2980: base type u32 is not type checked properly when assigning a value within a struct",
142 cases.add("regression test #2980: base type u32 is not type checked properly when assigning a value within a struct",
134143 \\const Foo = struct {
135144 \\ ptr: ?*usize,
136145 \\ uval: u32,
......@@ -144,12 +153,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
144153 \\ .uval = get_uval(42),
145154 \\ };
146155 \\}
147 ,
156 , &[_][]const u8{
148157 "tmp.zig:11:25: error: expected type 'u32', found '@typeOf(get_uval).ReturnType.ErrorSet!u32'",
149 );
158 });
150159
151 cases.add(
152 "asigning to struct or union fields that are not optionals with a function that returns an optional",
160 cases.add("asigning to struct or union fields that are not optionals with a function that returns an optional",
153161 \\fn maybe(is: bool) ?u8 {
154162 \\ if (is) return @as(u8, 10) else return null;
155163 \\}
......@@ -163,24 +171,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
163171 \\ var u = U{ .Ye = maybe(false) };
164172 \\ var s = S{ .num = maybe(false) };
165173 \\}
166 ,
174 , &[_][]const u8{
167175 "tmp.zig:11:27: error: expected type 'u8', found '?u8'",
168 );
176 });
169177
170 cases.add(
171 "missing result type for phi node",
178 cases.add("missing result type for phi node",
172179 \\fn foo() !void {
173180 \\ return anyerror.Foo;
174181 \\}
175182 \\export fn entry() void {
176183 \\ foo() catch 0;
177184 \\}
178 ,
185 , &[_][]const u8{
179186 "tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void'",
180 );
187 });
181188
182 cases.add(
183 "atomicrmw with enum op not .Xchg",
189 cases.add("atomicrmw with enum op not .Xchg",
184190 \\export fn entry() void {
185191 \\ const E = enum(u8) {
186192 \\ a,
......@@ -191,34 +197,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
191197 \\ var x: E = .a;
192198 \\ _ = @atomicRmw(E, &x, .Add, .b, .SeqCst);
193199 \\}
194 ,
200 , &[_][]const u8{
195201 "tmp.zig:9:27: error: @atomicRmw on enum only works with .Xchg",
196 );
202 });
197203
198 cases.add(
199 "disallow coercion from non-null-terminated pointer to null-terminated pointer",
204 cases.add("disallow coercion from non-null-terminated pointer to null-terminated pointer",
200205 \\extern fn puts(s: [*:0]const u8) c_int;
201206 \\pub fn main() void {
202207 \\ const no_zero_array = [_]u8{'h', 'e', 'l', 'l', 'o'};
203208 \\ const no_zero_ptr: [*]const u8 = &no_zero_array;
204209 \\ _ = puts(no_zero_ptr);
205210 \\}
206 ,
211 , &[_][]const u8{
207212 "tmp.zig:5:14: error: expected type '[*:0]const u8', found '[*]const u8'",
208 );
213 });
209214
210 cases.add(
211 "atomic orderings of atomicStore Acquire or AcqRel",
215 cases.add("atomic orderings of atomicStore Acquire or AcqRel",
212216 \\export fn entry() void {
213217 \\ var x: u32 = 0;
214218 \\ @atomicStore(u32, &x, 1, .Acquire);
215219 \\}
216 ,
220 , &[_][]const u8{
217221 "tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel",
218 );
222 });
219223
220 cases.add(
221 "missing const in slice with nested array type",
224 cases.add("missing const in slice with nested array type",
222225 \\const Geo3DTex2D = struct { vertices: [][2]f32 };
223226 \\pub fn getGeo3DTex2D() Geo3DTex2D {
224227 \\ return Geo3DTex2D{
......@@ -230,34 +233,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
230233 \\export fn entry() void {
231234 \\ var geo_data = getGeo3DTex2D();
232235 \\}
233 ,
236 , &[_][]const u8{
234237 "tmp.zig:4:30: error: array literal requires address-of operator to coerce to slice type '[][2]f32'",
235 );
238 });
236239
237 cases.add(
238 "slicing of global undefined pointer",
240 cases.add("slicing of global undefined pointer",
239241 \\var buf: *[1]u8 = undefined;
240242 \\export fn entry() void {
241243 \\ _ = buf[0..1];
242244 \\}
243 ,
245 , &[_][]const u8{
244246 "tmp.zig:3:12: error: non-zero length slice of undefined pointer",
245 );
247 });
246248
247 cases.add(
248 "using invalid types in function call raises an error",
249 cases.add("using invalid types in function call raises an error",
249250 \\const MenuEffect = enum {};
250251 \\fn func(effect: MenuEffect) void {}
251252 \\export fn entry() void {
252253 \\ func(MenuEffect.ThisDoesNotExist);
253254 \\}
254 ,
255 , &[_][]const u8{
255256 "tmp.zig:1:20: error: enums must have 1 or more fields",
256257 "tmp.zig:4:20: note: referenced here",
257 );
258 });
258259
259 cases.add(
260 "store vector pointer with unknown runtime index",
260 cases.add("store vector pointer with unknown runtime index",
261261 \\export fn entry() void {
262262 \\ var v: @Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };
263263 \\
......@@ -268,12 +268,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
268268 \\fn storev(ptr: var, val: i32) void {
269269 \\ ptr.* = val;
270270 \\}
271 ,
271 , &[_][]const u8{
272272 "tmp.zig:9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i32",
273 );
273 });
274274
275 cases.add(
276 "load vector pointer with unknown runtime index",
275 cases.add("load vector pointer with unknown runtime index",
277276 \\export fn entry() void {
278277 \\ var v: @Vector(4, i32) = [_]i32{ 1, 5, 3, undefined };
279278 \\
......@@ -284,12 +283,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
284283 \\fn loadv(ptr: var) i32 {
285284 \\ return ptr.*;
286285 \\}
287 ,
286 , &[_][]const u8{
288287 "tmp.zig:9:12: error: unable to determine vector element index of type '*align(16:0:4:?) i32",
289 );
288 });
290289
291 cases.add(
292 "using an unknown len ptr type instead of array",
290 cases.add("using an unknown len ptr type instead of array",
293291 \\const resolutions = [*][*]const u8{
294292 \\ "[320 240 ]",
295293 \\ null,
......@@ -297,22 +295,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
297295 \\comptime {
298296 \\ _ = resolutions;
299297 \\}
300 ,
298 , &[_][]const u8{
301299 "tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8'",
302 );
300 });
303301
304 cases.add(
305 "comparison with error union and error value",
302 cases.add("comparison with error union and error value",
306303 \\export fn entry() void {
307304 \\ var number_or_error: anyerror!i32 = error.SomethingAwful;
308305 \\ _ = number_or_error == error.SomethingAwful;
309306 \\}
310 ,
307 , &[_][]const u8{
311308 "tmp.zig:3:25: error: operator not allowed for type 'anyerror!i32'",
312 );
309 });
313310
314 cases.add(
315 "switch with overlapping case ranges",
311 cases.add("switch with overlapping case ranges",
316312 \\export fn entry() void {
317313 \\ var q: u8 = 0;
318314 \\ switch (q) {
......@@ -320,22 +316,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
320316 \\ 0...255 => {},
321317 \\ }
322318 \\}
323 ,
319 , &[_][]const u8{
324320 "tmp.zig:5:9: error: duplicate switch value",
325 );
321 });
326322
327 cases.add(
328 "invalid optional type in extern struct",
323 cases.add("invalid optional type in extern struct",
329324 \\const stroo = extern struct {
330325 \\ moo: ?[*c]u8,
331326 \\};
332327 \\export fn testf(fluff: *stroo) void {}
333 ,
328 , &[_][]const u8{
334329 "tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8'",
335 );
330 });
336331
337 cases.add(
338 "attempt to negate a non-integer, non-float or non-vector type",
332 cases.add("attempt to negate a non-integer, non-float or non-vector type",
339333 \\fn foo() anyerror!u32 {
340334 \\ return 1;
341335 \\}
......@@ -343,42 +337,38 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
343337 \\export fn entry() void {
344338 \\ const x = -foo();
345339 \\}
346 ,
340 , &[_][]const u8{
347341 "tmp.zig:6:15: error: negation of type 'anyerror!u32'",
348 );
342 });
349343
350 cases.add(
351 "attempt to create 17 bit float type",
344 cases.add("attempt to create 17 bit float type",
352345 \\const builtin = @import("builtin");
353346 \\comptime {
354347 \\ _ = @Type(builtin.TypeInfo { .Float = builtin.TypeInfo.Float { .bits = 17 } });
355348 \\}
356 ,
349 , &[_][]const u8{
357350 "tmp.zig:3:32: error: 17-bit float unsupported",
358 );
351 });
359352
360 cases.add(
361 "wrong type for @Type",
353 cases.add("wrong type for @Type",
362354 \\export fn entry() void {
363355 \\ _ = @Type(0);
364356 \\}
365 ,
357 , &[_][]const u8{
366358 "tmp.zig:2:15: error: expected type 'std.builtin.TypeInfo', found 'comptime_int'",
367 );
359 });
368360
369 cases.add(
370 "@Type with non-constant expression",
361 cases.add("@Type with non-constant expression",
371362 \\const builtin = @import("builtin");
372363 \\var globalTypeInfo : builtin.TypeInfo = undefined;
373364 \\export fn entry() void {
374365 \\ _ = @Type(globalTypeInfo);
375366 \\}
376 ,
367 , &[_][]const u8{
377368 "tmp.zig:4:15: error: unable to evaluate constant expression",
378 );
369 });
379370
380 cases.add(
381 "@Type with TypeInfo.Int",
371 cases.add("@Type with TypeInfo.Int",
382372 \\const builtin = @import("builtin");
383373 \\export fn entry() void {
384374 \\ _ = @Type(builtin.TypeInfo.Int {
......@@ -386,21 +376,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
386376 \\ .bits = 8,
387377 \\ });
388378 \\}
389 ,
379 , &[_][]const u8{
390380 "tmp.zig:3:36: error: expected type 'std.builtin.TypeInfo', found 'std.builtin.Int'",
391 );
381 });
392382
393 cases.add(
394 "Struct unavailable for @Type",
383 cases.add("Struct unavailable for @Type",
395384 \\export fn entry() void {
396385 \\ _ = @Type(@typeInfo(struct { }));
397386 \\}
398 ,
387 , &[_][]const u8{
399388 "tmp.zig:2:15: error: @Type not availble for 'TypeInfo.Struct'",
400 );
389 });
401390
402 cases.add(
403 "wrong type for result ptr to @asyncCall",
391 cases.add("wrong type for result ptr to @asyncCall",
404392 \\export fn entry() void {
405393 \\ _ = async amain();
406394 \\}
......@@ -411,32 +399,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
411399 \\fn foo() i32 {
412400 \\ return 1234;
413401 \\}
414 ,
402 , &[_][]const u8{
415403 "tmp.zig:6:37: error: expected type '*i32', found 'bool'",
416 );
404 });
417405
418 cases.add(
419 "shift amount has to be an integer type",
406 cases.add("shift amount has to be an integer type",
420407 \\export fn entry() void {
421408 \\ const x = 1 << &@as(u8, 10);
422409 \\}
423 ,
410 , &[_][]const u8{
424411 "tmp.zig:2:21: error: shift amount has to be an integer type, but found '*u8'",
425412 "tmp.zig:2:17: note: referenced here",
426 );
413 });
427414
428 cases.add(
429 "bit shifting only works on integer types",
415 cases.add("bit shifting only works on integer types",
430416 \\export fn entry() void {
431417 \\ const x = &@as(u8, 1) << 10;
432418 \\}
433 ,
419 , &[_][]const u8{
434420 "tmp.zig:2:16: error: bit shifting operation expected integer type, found '*u8'",
435421 "tmp.zig:2:27: note: referenced here",
436 );
422 });
437423
438 cases.add(
439 "struct depends on itself via optional field",
424 cases.add("struct depends on itself via optional field",
440425 \\const LhsExpr = struct {
441426 \\ rhsExpr: ?AstObject,
442427 \\};
......@@ -447,14 +432,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
447432 \\ const lhsExpr = LhsExpr{ .rhsExpr = null };
448433 \\ const obj = AstObject{ .lhsExpr = lhsExpr };
449434 \\}
450 ,
435 , &[_][]const u8{
451436 "tmp.zig:1:17: error: struct 'LhsExpr' depends on itself",
452437 "tmp.zig:5:5: note: while checking this field",
453438 "tmp.zig:2:5: note: while checking this field",
454 );
439 });
455440
456 cases.add(
457 "alignment of enum field specified",
441 cases.add("alignment of enum field specified",
458442 \\const Number = enum {
459443 \\ a,
460444 \\ b align(i32),
......@@ -462,23 +446,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
462446 \\export fn entry1() void {
463447 \\ var x: Number = undefined;
464448 \\}
465 ,
449 , &[_][]const u8{
466450 "tmp.zig:3:13: error: structs and unions, not enums, support field alignment",
467451 "tmp.zig:1:16: note: consider 'union(enum)' here",
468 );
452 });
469453
470 cases.add(
471 "bad alignment type",
454 cases.add("bad alignment type",
472455 \\export fn entry1() void {
473456 \\ var x: []align(true) i32 = undefined;
474457 \\}
475458 \\export fn entry2() void {
476459 \\ var x: *align(@as(f64, 12.34)) i32 = undefined;
477460 \\}
478 ,
461 , &[_][]const u8{
479462 "tmp.zig:2:20: error: expected type 'u29', found 'bool'",
480463 "tmp.zig:5:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'",
481 );
464 });
482465
483466 cases.addCase(x: {
484467 var tc = cases.create("variable in inline assembly template cannot be found",
......@@ -488,7 +471,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
488471 \\ : [bar] "=r" (-> usize)
489472 \\ );
490473 \\}
491 , "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs");
474 , &[_][]const u8{
475 "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs",
476 });
492477 tc.target = tests.Target{
493478 .Cross = tests.CrossTarget{
494479 .arch = .x86_64,
......@@ -499,8 +484,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
499484 break :x tc;
500485 });
501486
502 cases.add(
503 "indirect recursion of async functions detected",
487 cases.add("indirect recursion of async functions detected",
504488 \\var frame: ?anyframe = null;
505489 \\
506490 \\export fn a() void {
......@@ -529,14 +513,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
529513 \\ var child = rangeSum(x - 1);
530514 \\ return child + 1;
531515 \\}
532 ,
516 , &[_][]const u8{
533517 "tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself",
534518 "tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here",
535519 "tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here",
536 );
520 });
537521
538 cases.add(
539 "non-async function pointer eventually is inferred to become async",
522 cases.add("non-async function pointer eventually is inferred to become async",
540523 \\export fn a() void {
541524 \\ var non_async_fn: fn () void = undefined;
542525 \\ non_async_fn = func;
......@@ -544,45 +527,41 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
544527 \\fn func() void {
545528 \\ suspend;
546529 \\}
547 ,
530 , &[_][]const u8{
548531 "tmp.zig:5:1: error: 'func' cannot be async",
549532 "tmp.zig:3:20: note: required to be non-async here",
550533 "tmp.zig:6:5: note: suspends here",
551 );
534 });
552535
553 cases.add(
554 "bad alignment in @asyncCall",
536 cases.add("bad alignment in @asyncCall",
555537 \\export fn entry() void {
556538 \\ var ptr: async fn () void = func;
557539 \\ var bytes: [64]u8 = undefined;
558540 \\ _ = @asyncCall(&bytes, {}, ptr);
559541 \\}
560542 \\async fn func() void {}
561 ,
543 , &[_][]const u8{
562544 "tmp.zig:4:21: error: expected type '[]align(16) u8', found '*[64]u8'",
563 );
545 });
564546
565 cases.add(
566 "atomic orderings of fence Acquire or stricter",
547 cases.add("atomic orderings of fence Acquire or stricter",
567548 \\export fn entry() void {
568549 \\ @fence(.Monotonic);
569550 \\}
570 ,
551 , &[_][]const u8{
571552 "tmp.zig:2:12: error: atomic ordering must be Acquire or stricter",
572 );
553 });
573554
574 cases.add(
575 "bad alignment in implicit cast from array pointer to slice",
555 cases.add("bad alignment in implicit cast from array pointer to slice",
576556 \\export fn a() void {
577557 \\ var x: [10]u8 = undefined;
578558 \\ var y: []align(16) u8 = &x;
579559 \\}
580 ,
560 , &[_][]const u8{
581561 "tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8'",
582 );
562 });
583563
584 cases.add(
585 "result location incompatibility mismatching handle_is_ptr (generic call)",
564 cases.add("result location incompatibility mismatching handle_is_ptr (generic call)",
586565 \\export fn entry() void {
587566 \\ var damn = Container{
588567 \\ .not_optional = getOptional(i32),
......@@ -594,12 +573,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
594573 \\pub const Container = struct {
595574 \\ not_optional: i32,
596575 \\};
597 ,
576 , &[_][]const u8{
598577 "tmp.zig:3:36: error: expected type 'i32', found '?i32'",
599 );
578 });
600579
601 cases.add(
602 "result location incompatibility mismatching handle_is_ptr",
580 cases.add("result location incompatibility mismatching handle_is_ptr",
603581 \\export fn entry() void {
604582 \\ var damn = Container{
605583 \\ .not_optional = getOptional(),
......@@ -611,12 +589,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
611589 \\pub const Container = struct {
612590 \\ not_optional: i32,
613591 \\};
614 ,
592 , &[_][]const u8{
615593 "tmp.zig:3:36: error: expected type 'i32', found '?i32'",
616 );
594 });
617595
618 cases.add(
619 "const frame cast to anyframe",
596 cases.add("const frame cast to anyframe",
620597 \\export fn a() void {
621598 \\ const f = async func();
622599 \\ resume f;
......@@ -628,13 +605,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
628605 \\fn func() void {
629606 \\ suspend;
630607 \\}
631 ,
608 , &[_][]const u8{
632609 "tmp.zig:3:12: error: expected type 'anyframe', found '*const @Frame(func)'",
633610 "tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)'",
634 );
611 });
635612
636 cases.add(
637 "prevent bad implicit casting of anyframe types",
613 cases.add("prevent bad implicit casting of anyframe types",
638614 \\export fn a() void {
639615 \\ var x: anyframe = undefined;
640616 \\ var y: anyframe->i32 = x;
......@@ -648,14 +624,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
648624 \\ var y: anyframe->i32 = &x;
649625 \\}
650626 \\fn func() void {}
651 ,
627 , &[_][]const u8{
652628 "tmp.zig:3:28: error: expected type 'anyframe->i32', found 'anyframe'",
653629 "tmp.zig:7:28: error: expected type 'anyframe->i32', found 'i32'",
654630 "tmp.zig:11:29: error: expected type 'anyframe->i32', found '*@Frame(func)'",
655 );
631 });
656632
657 cases.add(
658 "wrong frame type used for async call",
633 cases.add("wrong frame type used for async call",
659634 \\export fn entry() void {
660635 \\ var frame: @Frame(foo) = undefined;
661636 \\ frame = async bar();
......@@ -666,37 +641,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
666641 \\fn bar() void {
667642 \\ suspend;
668643 \\}
669 ,
644 , &[_][]const u8{
670645 "tmp.zig:3:5: error: expected type '*@Frame(bar)', found '*@Frame(foo)'",
671 );
646 });
672647
673 cases.add(
674 "@Frame() of generic function",
648 cases.add("@Frame() of generic function",
675649 \\export fn entry() void {
676650 \\ var frame: @Frame(func) = undefined;
677651 \\}
678652 \\fn func(comptime T: type) void {
679653 \\ var x: T = undefined;
680654 \\}
681 ,
655 , &[_][]const u8{
682656 "tmp.zig:2:16: error: @Frame() of generic function",
683 );
657 });
684658
685 cases.add(
686 "@frame() causes function to be async",
659 cases.add("@frame() causes function to be async",
687660 \\export fn entry() void {
688661 \\ func();
689662 \\}
690663 \\fn func() void {
691664 \\ _ = @frame();
692665 \\}
693 ,
666 , &[_][]const u8{
694667 "tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async",
695668 "tmp.zig:5:9: note: @frame() causes function to be async",
696 );
669 });
697670
698 cases.add(
699 "invalid suspend in exported function",
671 cases.add("invalid suspend in exported function",
700672 \\export fn entry() void {
701673 \\ var frame = async func();
702674 \\ var result = await frame;
......@@ -704,13 +676,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
704676 \\fn func() void {
705677 \\ suspend;
706678 \\}
707 ,
679 , &[_][]const u8{
708680 "tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async",
709681 "tmp.zig:3:18: note: await here is a suspend point",
710 );
682 });
711683
712 cases.add(
713 "async function indirectly depends on its own frame",
684 cases.add("async function indirectly depends on its own frame",
714685 \\export fn entry() void {
715686 \\ _ = async amain();
716687 \\}
......@@ -720,39 +691,36 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
720691 \\fn other() void {
721692 \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined;
722693 \\}
723 ,
694 , &[_][]const u8{
724695 "tmp.zig:4:1: error: unable to determine async function frame of 'amain'",
725696 "tmp.zig:5:10: note: analysis of function 'other' depends on the frame",
726697 "tmp.zig:8:13: note: referenced here",
727 );
698 });
728699
729 cases.add(
730 "async function depends on its own frame",
700 cases.add("async function depends on its own frame",
731701 \\export fn entry() void {
732702 \\ _ = async amain();
733703 \\}
734704 \\async fn amain() void {
735705 \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined;
736706 \\}
737 ,
707 , &[_][]const u8{
738708 "tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet",
739709 "tmp.zig:5:13: note: referenced here",
740 );
710 });
741711
742 cases.add(
743 "non async function pointer passed to @asyncCall",
712 cases.add("non async function pointer passed to @asyncCall",
744713 \\export fn entry() void {
745714 \\ var ptr = afunc;
746715 \\ var bytes: [100]u8 align(16) = undefined;
747716 \\ _ = @asyncCall(&bytes, {}, ptr);
748717 \\}
749718 \\fn afunc() void { }
750 ,
719 , &[_][]const u8{
751720 "tmp.zig:4:32: error: expected async function, found 'fn() void'",
752 );
721 });
753722
754 cases.add(
755 "runtime-known async function called",
723 cases.add("runtime-known async function called",
756724 \\export fn entry() void {
757725 \\ _ = async amain();
758726 \\}
......@@ -761,24 +729,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
761729 \\ _ = ptr();
762730 \\}
763731 \\async fn afunc() void {}
764 ,
732 , &[_][]const u8{
765733 "tmp.zig:6:12: error: function is not comptime-known; @asyncCall required",
766 );
734 });
767735
768 cases.add(
769 "runtime-known function called with async keyword",
736 cases.add("runtime-known function called with async keyword",
770737 \\export fn entry() void {
771738 \\ var ptr = afunc;
772739 \\ _ = async ptr();
773740 \\}
774741 \\
775742 \\async fn afunc() void { }
776 ,
743 , &[_][]const u8{
777744 "tmp.zig:3:15: error: function is not comptime-known; @asyncCall required",
778 );
745 });
779746
780 cases.add(
781 "function with ccc indirectly calling async function",
747 cases.add("function with ccc indirectly calling async function",
782748 \\export fn entry() void {
783749 \\ foo();
784750 \\}
......@@ -788,15 +754,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
788754 \\fn bar() void {
789755 \\ suspend;
790756 \\}
791 ,
757 , &[_][]const u8{
792758 "tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async",
793759 "tmp.zig:2:8: note: async function call here",
794760 "tmp.zig:5:8: note: async function call here",
795761 "tmp.zig:8:5: note: suspends here",
796 );
762 });
797763
798 cases.add(
799 "capture group on switch prong with incompatible payload types",
764 cases.add("capture group on switch prong with incompatible payload types",
800765 \\const Union = union(enum) {
801766 \\ A: usize,
802767 \\ B: isize,
......@@ -807,59 +772,53 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
807772 \\ .A, .B => |e| unreachable,
808773 \\ }
809774 \\}
810 ,
775 , &[_][]const u8{
811776 "tmp.zig:8:20: error: capture group with incompatible types",
812777 "tmp.zig:8:9: note: type 'usize' here",
813778 "tmp.zig:8:13: note: type 'isize' here",
814 );
779 });
815780
816 cases.add(
817 "wrong type to @hasField",
781 cases.add("wrong type to @hasField",
818782 \\export fn entry() bool {
819783 \\ return @hasField(i32, "hi");
820784 \\}
821 ,
785 , &[_][]const u8{
822786 "tmp.zig:2:22: error: type 'i32' does not support @hasField",
823 );
787 });
824788
825 cases.add(
826 "slice passed as array init type with elems",
789 cases.add("slice passed as array init type with elems",
827790 \\export fn entry() void {
828791 \\ const x = []u8{1, 2};
829792 \\}
830 ,
793 , &[_][]const u8{
831794 "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'",
832 );
795 });
833796
834 cases.add(
835 "slice passed as array init type",
797 cases.add("slice passed as array init type",
836798 \\export fn entry() void {
837799 \\ const x = []u8{};
838800 \\}
839 ,
801 , &[_][]const u8{
840802 "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'",
841 );
803 });
842804
843 cases.add(
844 "inferred array size invalid here",
805 cases.add("inferred array size invalid here",
845806 \\export fn entry() void {
846807 \\ const x = [_]u8;
847808 \\}
848 ,
809 , &[_][]const u8{
849810 "tmp.zig:2:15: error: inferred array size invalid here",
850 );
811 });
851812
852 cases.add(
853 "initializing array with struct syntax",
813 cases.add("initializing array with struct syntax",
854814 \\export fn entry() void {
855815 \\ const x = [_]u8{ .y = 2 };
856816 \\}
857 ,
817 , &[_][]const u8{
858818 "tmp.zig:2:15: error: initializing array with struct syntax",
859 );
819 });
860820
861 cases.add(
862 "compile error in struct init expression",
821 cases.add("compile error in struct init expression",
863822 \\const Foo = struct {
864823 \\ a: i32 = crap,
865824 \\ b: i32,
......@@ -869,54 +828,49 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
869828 \\ .b = 5,
870829 \\ };
871830 \\}
872 ,
831 , &[_][]const u8{
873832 "tmp.zig:2:14: error: use of undeclared identifier 'crap'",
874 );
833 });
875834
876 cases.add(
877 "undefined as field type is rejected",
835 cases.add("undefined as field type is rejected",
878836 \\const Foo = struct {
879837 \\ a: undefined,
880838 \\};
881839 \\export fn entry1() void {
882840 \\ const foo: Foo = undefined;
883841 \\}
884 ,
842 , &[_][]const u8{
885843 "tmp.zig:2:8: error: use of undefined value here causes undefined behavior",
886 );
844 });
887845
888 cases.add(
889 "@hasDecl with non-container",
846 cases.add("@hasDecl with non-container",
890847 \\export fn entry() void {
891848 \\ _ = @hasDecl(i32, "hi");
892849 \\}
893 ,
850 , &[_][]const u8{
894851 "tmp.zig:2:18: error: expected struct, enum, or union; found 'i32'",
895 );
852 });
896853
897 cases.add(
898 "field access of slices",
854 cases.add("field access of slices",
899855 \\export fn entry() void {
900856 \\ var slice: []i32 = undefined;
901857 \\ const info = @typeOf(slice).unknown;
902858 \\}
903 ,
859 , &[_][]const u8{
904860 "tmp.zig:3:32: error: type '[]i32' does not support field access",
905 );
861 });
906862
907 cases.add(
908 "peer cast then implicit cast const pointer to mutable C pointer",
863 cases.add("peer cast then implicit cast const pointer to mutable C pointer",
909864 \\export fn func() void {
910865 \\ var strValue: [*c]u8 = undefined;
911866 \\ strValue = strValue orelse "";
912867 \\}
913 ,
868 , &[_][]const u8{
914869 "tmp.zig:3:32: error: expected type '[*c]u8', found '*const [0:0]u8'",
915870 "tmp.zig:3:32: note: cast discards const qualifier",
916 );
871 });
917872
918 cases.add(
919 "overflow in enum value allocation",
873 cases.add("overflow in enum value allocation",
920874 \\const Moo = enum(u8) {
921875 \\ Last = 255,
922876 \\ Over,
......@@ -924,32 +878,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
924878 \\pub fn main() void {
925879 \\ var y = Moo.Last;
926880 \\}
927 ,
881 , &[_][]const u8{
928882 "tmp.zig:3:5: error: enumeration value 256 too large for type 'u8'",
929 );
883 });
930884
931 cases.add(
932 "attempt to cast enum literal to error",
885 cases.add("attempt to cast enum literal to error",
933886 \\export fn entry() void {
934887 \\ switch (error.Hi) {
935888 \\ .Hi => {},
936889 \\ }
937890 \\}
938 ,
891 , &[_][]const u8{
939892 "tmp.zig:3:9: error: expected type 'error{Hi}', found '(enum literal)'",
940 );
893 });
941894
942 cases.add(
943 "@sizeOf bad type",
895 cases.add("@sizeOf bad type",
944896 \\export fn entry() usize {
945897 \\ return @sizeOf(@typeOf(null));
946898 \\}
947 ,
899 , &[_][]const u8{
948900 "tmp.zig:2:20: error: no size available for type '(null)'",
949 );
901 });
950902
951 cases.add(
952 "generic function where return type is self-referenced",
903 cases.add("generic function where return type is self-referenced",
953904 \\fn Foo(comptime T: type) Foo(T) {
954905 \\ return struct{ x: T };
955906 \\}
......@@ -958,22 +909,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
958909 \\ .x = 1
959910 \\ };
960911 \\}
961 ,
912 , &[_][]const u8{
962913 "tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches",
963914 "tmp.zig:5:18: note: referenced here",
964 );
915 });
965916
966 cases.add(
967 "@ptrToInt 0 to non optional pointer",
917 cases.add("@ptrToInt 0 to non optional pointer",
968918 \\export fn entry() void {
969919 \\ var b = @intToPtr(*i32, 0);
970920 \\}
971 ,
921 , &[_][]const u8{
972922 "tmp.zig:2:13: error: pointer type '*i32' does not allow address zero",
973 );
923 });
974924
975 cases.add(
976 "cast enum literal to enum but it doesn't match",
925 cases.add("cast enum literal to enum but it doesn't match",
977926 \\const Foo = enum {
978927 \\ a,
979928 \\ b,
......@@ -981,34 +930,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
981930 \\export fn entry() void {
982931 \\ const x: Foo = .c;
983932 \\}
984 ,
933 , &[_][]const u8{
985934 "tmp.zig:6:20: error: enum 'Foo' has no field named 'c'",
986935 "tmp.zig:1:13: note: 'Foo' declared here",
987 );
936 });
988937
989 cases.add(
990 "discarding error value",
938 cases.add("discarding error value",
991939 \\export fn entry() void {
992940 \\ _ = foo();
993941 \\}
994942 \\fn foo() !void {
995943 \\ return error.OutOfMemory;
996944 \\}
997 ,
945 , &[_][]const u8{
998946 "tmp.zig:2:12: error: error is discarded",
999 );
947 });
1000948
1001 cases.add(
1002 "volatile on global assembly",
949 cases.add("volatile on global assembly",
1003950 \\comptime {
1004951 \\ asm volatile ("");
1005952 \\}
1006 ,
953 , &[_][]const u8{
1007954 "tmp.zig:2:9: error: volatile is meaningless on global assembly",
1008 );
955 });
1009956
1010 cases.add(
1011 "invalid multiple dereferences",
957 cases.add("invalid multiple dereferences",
1012958 \\export fn a() void {
1013959 \\ var box = Box{ .field = 0 };
1014960 \\ box.*.field = 1;
......@@ -1021,20 +967,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1021967 \\pub const Box = struct {
1022968 \\ field: i32,
1023969 \\};
1024 ,
970 , &[_][]const u8{
1025971 "tmp.zig:3:8: error: attempt to dereference non-pointer type 'Box'",
1026972 "tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box'",
1027 );
973 });
1028974
1029 cases.add(
1030 "usingnamespace with wrong type",
975 cases.add("usingnamespace with wrong type",
1031976 \\usingnamespace void;
1032 ,
977 , &[_][]const u8{
1033978 "tmp.zig:1:1: error: expected struct, enum, or union; found 'void'",
1034 );
979 });
1035980
1036 cases.add(
1037 "ignored expression in while continuation",
981 cases.add("ignored expression in while continuation",
1038982 \\export fn a() void {
1039983 \\ while (true) : (bad()) {}
1040984 \\}
......@@ -1049,96 +993,86 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1049993 \\fn bad() anyerror!void {
1050994 \\ return error.Bad;
1051995 \\}
1052 ,
996 , &[_][]const u8{
1053997 "tmp.zig:2:24: error: expression value is ignored",
1054998 "tmp.zig:6:25: error: expression value is ignored",
1055999 "tmp.zig:10:25: error: expression value is ignored",
1056 );
1000 });
10571001
1058 cases.add(
1059 "empty while loop body",
1002 cases.add("empty while loop body",
10601003 \\export fn a() void {
10611004 \\ while(true);
10621005 \\}
1063 ,
1006 , &[_][]const u8{
10641007 "tmp.zig:2:16: error: expected loop body, found ';'",
1065 );
1008 });
10661009
1067 cases.add(
1068 "empty for loop body",
1010 cases.add("empty for loop body",
10691011 \\export fn a() void {
10701012 \\ for(undefined) |x|;
10711013 \\}
1072 ,
1014 , &[_][]const u8{
10731015 "tmp.zig:2:23: error: expected loop body, found ';'",
1074 );
1016 });
10751017
1076 cases.add(
1077 "empty if body",
1018 cases.add("empty if body",
10781019 \\export fn a() void {
10791020 \\ if(true);
10801021 \\}
1081 ,
1022 , &[_][]const u8{
10821023 "tmp.zig:2:13: error: expected if body, found ';'",
1083 );
1024 });
10841025
1085 cases.add(
1086 "import outside package path",
1026 cases.add("import outside package path",
10871027 \\comptime{
10881028 \\ _ = @import("../a.zig");
10891029 \\}
1090 ,
1030 , &[_][]const u8{
10911031 "tmp.zig:2:9: error: import of file outside package path: '../a.zig'",
1092 );
1032 });
10931033
1094 cases.add(
1095 "bogus compile var",
1034 cases.add("bogus compile var",
10961035 \\const x = @import("builtin").bogus;
10971036 \\export fn entry() usize { return @sizeOf(@typeOf(x)); }
1098 ,
1037 , &[_][]const u8{
10991038 "tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'",
1100 );
1039 });
11011040
1102 cases.add(
1103 "wrong panic signature, runtime function",
1041 cases.add("wrong panic signature, runtime function",
11041042 \\test "" {}
11051043 \\
11061044 \\pub fn panic() void {}
11071045 \\
1108 ,
1046 , &[_][]const u8{
11091047 "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn() void'",
1110 );
1048 });
11111049
1112 cases.add(
1113 "wrong panic signature, generic function",
1050 cases.add("wrong panic signature, generic function",
11141051 \\pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {
11151052 \\ while (true) {}
11161053 \\}
1117 ,
1054 , &[_][]const u8{
11181055 "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn([]const u8,var)var'",
11191056 "note: only one of the functions is generic",
1120 );
1057 });
11211058
1122 cases.add(
1123 "direct struct loop",
1059 cases.add("direct struct loop",
11241060 \\const A = struct { a : A, };
11251061 \\export fn entry() usize { return @sizeOf(A); }
1126 ,
1062 , &[_][]const u8{
11271063 "tmp.zig:1:11: error: struct 'A' depends on itself",
1128 );
1064 });
11291065
1130 cases.add(
1131 "indirect struct loop",
1066 cases.add("indirect struct loop",
11321067 \\const A = struct { b : B, };
11331068 \\const B = struct { c : C, };
11341069 \\const C = struct { a : A, };
11351070 \\export fn entry() usize { return @sizeOf(A); }
1136 ,
1071 , &[_][]const u8{
11371072 "tmp.zig:1:11: error: struct 'A' depends on itself",
1138 );
1073 });
11391074
1140 cases.add(
1141 "instantiating an undefined value for an invalid struct that contains itself",
1075 cases.add("instantiating an undefined value for an invalid struct that contains itself",
11421076 \\const Foo = struct {
11431077 \\ x: Foo,
11441078 \\};
......@@ -1148,13 +1082,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
11481082 \\export fn entry() usize {
11491083 \\ return @sizeOf(@typeOf(foo.x));
11501084 \\}
1151 ,
1085 , &[_][]const u8{
11521086 "tmp.zig:1:13: error: struct 'Foo' depends on itself",
11531087 "tmp.zig:8:28: note: referenced here",
1154 );
1088 });
11551089
1156 cases.add(
1157 "@typeInfo causing depend on itself compile error",
1090 cases.add("@typeInfo causing depend on itself compile error",
11581091 \\const start = struct {
11591092 \\ fn crash() bug() {
11601093 \\ return bug;
......@@ -1166,14 +1099,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
11661099 \\export fn entry() void {
11671100 \\ var boom = start.crash();
11681101 \\}
1169 ,
1102 , &[_][]const u8{
11701103 "tmp.zig:7:9: error: dependency loop detected",
11711104 "tmp.zig:2:19: note: referenced here",
11721105 "tmp.zig:10:21: note: referenced here",
1173 );
1106 });
11741107
1175 cases.add(
1176 "enum field value references enum",
1108 cases.add("enum field value references enum",
11771109 \\pub const Foo = extern enum {
11781110 \\ A = Foo.B,
11791111 \\ C = D,
......@@ -1181,25 +1113,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
11811113 \\export fn entry() void {
11821114 \\ var s: Foo = Foo.E;
11831115 \\}
1184 ,
1116 , &[_][]const u8{
11851117 "tmp.zig:1:17: error: enum 'Foo' depends on itself",
1186 );
1118 });
11871119
1188 cases.add(
1189 "top level decl dependency loop",
1120 cases.add("top level decl dependency loop",
11901121 \\const a : @typeOf(b) = 0;
11911122 \\const b : @typeOf(a) = 0;
11921123 \\export fn entry() void {
11931124 \\ const c = a + b;
11941125 \\}
1195 ,
1126 , &[_][]const u8{
11961127 "tmp.zig:2:19: error: dependency loop detected",
11971128 "tmp.zig:1:19: note: referenced here",
11981129 "tmp.zig:4:15: note: referenced here",
1199 );
1130 });
12001131
1201 cases.addTest(
1202 "not an enum type",
1132 cases.addTest("not an enum type",
12031133 \\export fn entry() void {
12041134 \\ var self: Error = undefined;
12051135 \\ switch (self) {
......@@ -1213,58 +1143,53 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
12131143 \\};
12141144 \\const InvalidToken = struct {};
12151145 \\const ExpectedVarDeclOrFn = struct {};
1216 ,
1146 , &[_][]const u8{
12171147 "tmp.zig:4:9: error: expected type '@TagType(Error)', found 'type'",
1218 );
1148 });
12191149
1220 cases.addTest(
1221 "binary OR operator on error sets",
1150 cases.addTest("binary OR operator on error sets",
12221151 \\pub const A = error.A;
12231152 \\pub const AB = A | error.B;
12241153 \\export fn entry() void {
12251154 \\ var x: AB = undefined;
12261155 \\}
1227 ,
1156 , &[_][]const u8{
12281157 "tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'",
1229 );
1158 });
12301159
12311160 if (builtin.os == builtin.Os.linux) {
1232 cases.addTest(
1233 "implicit dependency on libc",
1161 cases.addTest("implicit dependency on libc",
12341162 \\extern "c" fn exit(u8) void;
12351163 \\export fn entry() void {
12361164 \\ exit(0);
12371165 \\}
1238 ,
1166 , &[_][]const u8{
12391167 "tmp.zig:3:5: error: dependency on library c must be explicitly specified in the build command",
1240 );
1168 });
12411169
1242 cases.addTest(
1243 "libc headers note",
1170 cases.addTest("libc headers note",
12441171 \\const c = @cImport(@cInclude("stdio.h"));
12451172 \\export fn entry() void {
12461173 \\ _ = c.printf("hello, world!\n");
12471174 \\}
1248 ,
1175 , &[_][]const u8{
12491176 "tmp.zig:1:11: error: C import failed",
12501177 "tmp.zig:1:11: note: libc headers not available; compilation does not link against libc",
1251 );
1178 });
12521179 }
12531180
1254 cases.addTest(
1255 "comptime vector overflow shows the index",
1181 cases.addTest("comptime vector overflow shows the index",
12561182 \\comptime {
12571183 \\ var a: @Vector(4, u8) = [_]u8{ 1, 2, 255, 4 };
12581184 \\ var b: @Vector(4, u8) = [_]u8{ 5, 6, 1, 8 };
12591185 \\ var x = a + b;
12601186 \\}
1261 ,
1187 , &[_][]const u8{
12621188 "tmp.zig:4:15: error: operation caused overflow",
12631189 "tmp.zig:4:15: note: when computing vector element at index 2",
1264 );
1190 });
12651191
1266 cases.addTest(
1267 "packed struct with fields of not allowed types",
1192 cases.addTest("packed struct with fields of not allowed types",
12681193 \\const A = packed struct {
12691194 \\ x: anyerror,
12701195 \\};
......@@ -1318,7 +1243,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
13181243 \\ A,
13191244 \\ B,
13201245 \\};
1321 ,
1246 , &[_][]const u8{
13221247 "tmp.zig:2:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation",
13231248 "tmp.zig:5:5: error: array of 'u24' not allowed in packed struct due to padding bits",
13241249 "tmp.zig:8:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation",
......@@ -1327,45 +1252,41 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
13271252 "tmp.zig:17:5: error: type '?anyerror' not allowed in packed struct; no guaranteed in-memory representation",
13281253 "tmp.zig:20:5: error: type 'Enum' not allowed in packed struct; no guaranteed in-memory representation",
13291254 "tmp.zig:50:14: note: enum declaration does not specify an integer tag type",
1330 );
1255 });
13311256
13321257 cases.addCase(x: {
1333 var tc = cases.create(
1334 "deduplicate undeclared identifier",
1258 var tc = cases.create("deduplicate undeclared identifier",
13351259 \\export fn a() void {
13361260 \\ x += 1;
13371261 \\}
13381262 \\export fn b() void {
13391263 \\ x += 1;
13401264 \\}
1341 ,
1265 , &[_][]const u8{
13421266 "tmp.zig:2:5: error: use of undeclared identifier 'x'",
1343 );
1267 });
13441268 tc.expect_exact = true;
13451269 break :x tc;
13461270 });
13471271
1348 cases.add(
1349 "export generic function",
1272 cases.add("export generic function",
13501273 \\export fn foo(num: var) i32 {
13511274 \\ return 0;
13521275 \\}
1353 ,
1276 , &[_][]const u8{
13541277 "tmp.zig:1:15: error: parameter of type 'var' not allowed in function with calling convention 'ccc'",
1355 );
1278 });
13561279
1357 cases.add(
1358 "C pointer to c_void",
1280 cases.add("C pointer to c_void",
13591281 \\export fn a() void {
13601282 \\ var x: *c_void = undefined;
13611283 \\ var y: [*c]c_void = x;
13621284 \\}
1363 ,
1285 , &[_][]const u8{
13641286 "tmp.zig:3:16: error: C pointers cannot point opaque types",
1365 );
1287 });
13661288
1367 cases.add(
1368 "directly embedding opaque type in struct and union",
1289 cases.add("directly embedding opaque type in struct and union",
13691290 \\const O = @OpaqueType();
13701291 \\const Foo = struct {
13711292 \\ o: O,
......@@ -1380,13 +1301,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
13801301 \\export fn b() void {
13811302 \\ var bar: Bar = undefined;
13821303 \\}
1383 ,
1304 , &[_][]const u8{
13841305 "tmp.zig:3:8: error: opaque types have unknown size and therefore cannot be directly embedded in structs",
13851306 "tmp.zig:7:10: error: opaque types have unknown size and therefore cannot be directly embedded in unions",
1386 );
1307 });
13871308
1388 cases.add(
1389 "implicit cast between C pointer and Zig pointer - bad const/align/child",
1309 cases.add("implicit cast between C pointer and Zig pointer - bad const/align/child",
13901310 \\export fn a() void {
13911311 \\ var x: [*c]u8 = undefined;
13921312 \\ var y: *align(4) u8 = x;
......@@ -1411,7 +1331,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
14111331 \\ var y: *u8 = undefined;
14121332 \\ var x: [*c]u32 = y;
14131333 \\}
1414 ,
1334 , &[_][]const u8{
14151335 "tmp.zig:3:27: error: cast increases pointer alignment",
14161336 "tmp.zig:7:18: error: cast discards const qualifier",
14171337 "tmp.zig:11:19: error: expected type '*u32', found '[*c]u8'",
......@@ -1419,30 +1339,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
14191339 "tmp.zig:15:22: error: cast increases pointer alignment",
14201340 "tmp.zig:19:21: error: cast discards const qualifier",
14211341 "tmp.zig:23:22: error: expected type '[*c]u32', found '*u8'",
1422 );
1342 });
14231343
1424 cases.add(
1425 "implicit casting null c pointer to zig pointer",
1344 cases.add("implicit casting null c pointer to zig pointer",
14261345 \\comptime {
14271346 \\ var c_ptr: [*c]u8 = 0;
14281347 \\ var zig_ptr: *u8 = c_ptr;
14291348 \\}
1430 ,
1349 , &[_][]const u8{
14311350 "tmp.zig:3:24: error: null pointer casted to type '*u8'",
1432 );
1351 });
14331352
1434 cases.add(
1435 "implicit casting undefined c pointer to zig pointer",
1353 cases.add("implicit casting undefined c pointer to zig pointer",
14361354 \\comptime {
14371355 \\ var c_ptr: [*c]u8 = undefined;
14381356 \\ var zig_ptr: *u8 = c_ptr;
14391357 \\}
1440 ,
1358 , &[_][]const u8{
14411359 "tmp.zig:3:24: error: use of undefined value here causes undefined behavior",
1442 );
1360 });
14431361
1444 cases.add(
1445 "implicit casting C pointers which would mess up null semantics",
1362 cases.add("implicit casting C pointers which would mess up null semantics",
14461363 \\export fn entry() void {
14471364 \\ var slice: []const u8 = "aoeu";
14481365 \\ const opt_many_ptr: [*]const u8 = slice.ptr;
......@@ -1457,17 +1374,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
14571374 \\ var ptr_opt_many_ptr = &opt_many_ptr;
14581375 \\ var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr;
14591376 \\}
1460 ,
1377 , &[_][]const u8{
14611378 "tmp.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'",
14621379 "tmp.zig:6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8'",
14631380 "tmp.zig:6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8'",
14641381 "tmp.zig:13:35: error: expected type '[*c][*c]const u8', found '*[*]u8'",
14651382 "tmp.zig:13:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8'",
14661383 "tmp.zig:13:35: note: mutable '[*c]const u8' allows illegal null values stored to type '[*]u8'",
1467 );
1384 });
14681385
1469 cases.add(
1470 "implicit casting too big integers to C pointers",
1386 cases.add("implicit casting too big integers to C pointers",
14711387 \\export fn a() void {
14721388 \\ var ptr: [*c]u8 = (1 << 64) + 1;
14731389 \\}
......@@ -1475,25 +1391,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
14751391 \\ var x: @IntType(false, 65) = 0x1234;
14761392 \\ var ptr: [*c]u8 = x;
14771393 \\}
1478 ,
1394 , &[_][]const u8{
14791395 "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'",
14801396 "tmp.zig:6:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'",
1481 );
1397 });
14821398
1483 cases.add(
1484 "C pointer pointing to non C ABI compatible type or has align attr",
1399 cases.add("C pointer pointing to non C ABI compatible type or has align attr",
14851400 \\const Foo = struct {};
14861401 \\export fn a() void {
14871402 \\ const T = [*c]Foo;
14881403 \\ var t: T = undefined;
14891404 \\}
1490 ,
1405 , &[_][]const u8{
14911406 "tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'",
1492 );
1407 });
14931408
14941409 cases.addCase(x: {
1495 var tc = cases.create(
1496 "compile log statement warning deduplication in generic fn",
1410 var tc = cases.create("compile log statement warning deduplication in generic fn",
14971411 \\export fn entry() void {
14981412 \\ inner(1);
14991413 \\ inner(2);
......@@ -1502,111 +1416,100 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
15021416 \\ comptime var i = 0;
15031417 \\ inline while (i < n) : (i += 1) { @compileLog("!@#$"); }
15041418 \\}
1505 ,
1419 , &[_][]const u8{
15061420 "tmp.zig:7:39: error: found compile log statement",
1507 );
1421 });
15081422 tc.expect_exact = true;
15091423 break :x tc;
15101424 });
15111425
1512 cases.add(
1513 "assign to invalid dereference",
1426 cases.add("assign to invalid dereference",
15141427 \\export fn entry() void {
15151428 \\ 'a'.* = 1;
15161429 \\}
1517 ,
1430 , &[_][]const u8{
15181431 "tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'",
1519 );
1432 });
15201433
1521 cases.add(
1522 "take slice of invalid dereference",
1434 cases.add("take slice of invalid dereference",
15231435 \\export fn entry() void {
15241436 \\ const x = 'a'.*[0..];
15251437 \\}
1526 ,
1438 , &[_][]const u8{
15271439 "tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'",
1528 );
1440 });
15291441
1530 cases.add(
1531 "@truncate undefined value",
1442 cases.add("@truncate undefined value",
15321443 \\export fn entry() void {
15331444 \\ var z = @truncate(u8, @as(u16, undefined));
15341445 \\}
1535 ,
1446 , &[_][]const u8{
15361447 "tmp.zig:2:27: error: use of undefined value here causes undefined behavior",
1537 );
1448 });
15381449
1539 cases.addTest(
1540 "return invalid type from test",
1450 cases.addTest("return invalid type from test",
15411451 \\test "example" { return 1; }
1542 ,
1452 , &[_][]const u8{
15431453 "tmp.zig:1:25: error: integer value 1 cannot be coerced to type 'void'",
1544 );
1454 });
15451455
1546 cases.add(
1547 "threadlocal qualifier on const",
1456 cases.add("threadlocal qualifier on const",
15481457 \\threadlocal const x: i32 = 1234;
15491458 \\export fn entry() i32 {
15501459 \\ return x;
15511460 \\}
1552 ,
1461 , &[_][]const u8{
15531462 "tmp.zig:1:13: error: threadlocal variable cannot be constant",
1554 );
1463 });
15551464
1556 cases.add(
1557 "@bitCast same size but bit count mismatch",
1465 cases.add("@bitCast same size but bit count mismatch",
15581466 \\export fn entry(byte: u8) void {
15591467 \\ var oops = @bitCast(u7, byte);
15601468 \\}
1561 ,
1469 , &[_][]const u8{
15621470 "tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits",
1563 );
1471 });
15641472
1565 cases.add(
1566 "@bitCast with different sizes inside an expression",
1473 cases.add("@bitCast with different sizes inside an expression",
15671474 \\export fn entry() void {
15681475 \\ var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf);
15691476 \\}
1570 ,
1477 , &[_][]const u8{
15711478 "tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4",
1572 );
1479 });
15731480
1574 cases.add(
1575 "attempted `&&`",
1481 cases.add("attempted `&&`",
15761482 \\export fn entry(a: bool, b: bool) i32 {
15771483 \\ if (a && b) {
15781484 \\ return 1234;
15791485 \\ }
15801486 \\ return 5678;
15811487 \\}
1582 ,
1488 , &[_][]const u8{
15831489 "tmp.zig:2:12: error: `&&` is invalid. Note that `and` is boolean AND",
1584 );
1490 });
15851491
1586 cases.add(
1587 "attempted `||` on boolean values",
1492 cases.add("attempted `||` on boolean values",
15881493 \\export fn entry(a: bool, b: bool) i32 {
15891494 \\ if (a || b) {
15901495 \\ return 1234;
15911496 \\ }
15921497 \\ return 5678;
15931498 \\}
1594 ,
1499 , &[_][]const u8{
15951500 "tmp.zig:2:9: error: expected error set type, found 'bool'",
15961501 "tmp.zig:2:11: note: `||` merges error sets; `or` performs boolean OR",
1597 );
1502 });
15981503
1599 cases.add(
1600 "compile log a pointer to an opaque value",
1504 cases.add("compile log a pointer to an opaque value",
16011505 \\export fn entry() void {
16021506 \\ @compileLog(@ptrCast(*const c_void, &entry));
16031507 \\}
1604 ,
1508 , &[_][]const u8{
16051509 "tmp.zig:2:5: error: found compile log statement",
1606 );
1510 });
16071511
1608 cases.add(
1609 "duplicate boolean switch value",
1512 cases.add("duplicate boolean switch value",
16101513 \\comptime {
16111514 \\ const x = switch (true) {
16121515 \\ true => false,
......@@ -1621,13 +1524,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
16211524 \\ false => true,
16221525 \\ };
16231526 \\}
1624 ,
1527 , &[_][]const u8{
16251528 "tmp.zig:5:9: error: duplicate switch value",
16261529 "tmp.zig:12:9: error: duplicate switch value",
1627 );
1530 });
16281531
1629 cases.add(
1630 "missing boolean switch value",
1532 cases.add("missing boolean switch value",
16311533 \\comptime {
16321534 \\ const x = switch (true) {
16331535 \\ true => false,
......@@ -1638,37 +1540,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
16381540 \\ false => true,
16391541 \\ };
16401542 \\}
1641 ,
1543 , &[_][]const u8{
16421544 "tmp.zig:2:15: error: switch must handle all possibilities",
16431545 "tmp.zig:7:15: error: switch must handle all possibilities",
1644 );
1546 });
16451547
1646 cases.add(
1647 "reading past end of pointer casted array",
1548 cases.add("reading past end of pointer casted array",
16481549 \\comptime {
16491550 \\ const array: [4]u8 = "aoeu".*;
16501551 \\ const slice = array[1..];
16511552 \\ const int_ptr = @ptrCast(*const u24, slice.ptr);
16521553 \\ const deref = int_ptr.*;
16531554 \\}
1654 ,
1555 , &[_][]const u8{
16551556 "tmp.zig:5:26: error: attempt to read 4 bytes from [4]u8 at index 1 which is 3 bytes",
1656 );
1557 });
16571558
1658 cases.add(
1659 "error note for function parameter incompatibility",
1559 cases.add("error note for function parameter incompatibility",
16601560 \\fn do_the_thing(func: fn (arg: i32) void) void {}
16611561 \\fn bar(arg: bool) void {}
16621562 \\export fn entry() void {
16631563 \\ do_the_thing(bar);
16641564 \\}
1665 ,
1565 , &[_][]const u8{
16661566 "tmp.zig:4:18: error: expected type 'fn(i32) void', found 'fn(bool) void",
16671567 "tmp.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32'",
1668 );
1568 });
16691569
1670 cases.add(
1671 "cast negative value to unsigned integer",
1570 cases.add("cast negative value to unsigned integer",
16721571 \\comptime {
16731572 \\ const value: i32 = -1;
16741573 \\ const unsigned = @intCast(u32, value);
......@@ -1677,13 +1576,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
16771576 \\ const value: i32 = -1;
16781577 \\ const unsigned: u32 = value;
16791578 \\}
1680 ,
1579 , &[_][]const u8{
16811580 "tmp.zig:3:36: error: cannot cast negative value -1 to unsigned integer type 'u32'",
16821581 "tmp.zig:7:27: error: cannot cast negative value -1 to unsigned integer type 'u32'",
1683 );
1582 });
16841583
1685 cases.add(
1686 "integer cast truncates bits",
1584 cases.add("integer cast truncates bits",
16871585 \\export fn entry1() void {
16881586 \\ const spartan_count: u16 = 300;
16891587 \\ const byte = @intCast(u8, spartan_count);
......@@ -1700,50 +1598,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
17001598 \\ var signed: i8 = -1;
17011599 \\ var unsigned: u64 = signed;
17021600 \\}
1703 ,
1601 , &[_][]const u8{
17041602 "tmp.zig:3:31: error: integer value 300 cannot be coerced to type 'u8'",
17051603 "tmp.zig:7:22: error: integer value 300 cannot be coerced to type 'u8'",
17061604 "tmp.zig:11:20: error: expected type 'u8', found 'u16'",
17071605 "tmp.zig:11:20: note: unsigned 8-bit int cannot represent all possible unsigned 16-bit values",
17081606 "tmp.zig:15:25: error: expected type 'u64', found 'i8'",
17091607 "tmp.zig:15:25: note: unsigned 64-bit int cannot represent all possible signed 8-bit values",
1710 );
1608 });
17111609
1712 cases.add(
1713 "comptime implicit cast f64 to f32",
1610 cases.add("comptime implicit cast f64 to f32",
17141611 \\export fn entry() void {
17151612 \\ const x: f64 = 16777217;
17161613 \\ const y: f32 = x;
17171614 \\}
1718 ,
1615 , &[_][]const u8{
17191616 "tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information",
1720 );
1617 });
17211618
1722 cases.add(
1723 "implicit cast from f64 to f32",
1619 cases.add("implicit cast from f64 to f32",
17241620 \\var x: f64 = 1.0;
17251621 \\var y: f32 = x;
17261622 \\
17271623 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
1728 ,
1624 , &[_][]const u8{
17291625 "tmp.zig:2:14: error: expected type 'f32', found 'f64'",
1730 );
1626 });
17311627
1732 cases.add(
1733 "exceeded maximum bit width of integer",
1628 cases.add("exceeded maximum bit width of integer",
17341629 \\export fn entry1() void {
17351630 \\ const T = @IntType(false, 65536);
17361631 \\}
17371632 \\export fn entry2() void {
17381633 \\ var x: i65536 = 1;
17391634 \\}
1740 ,
1635 , &[_][]const u8{
17411636 "tmp.zig:2:31: error: integer value 65536 cannot be coerced to type 'u16'",
17421637 "tmp.zig:5:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535",
1743 );
1638 });
17441639
1745 cases.add(
1746 "compile error when evaluating return type of inferred error set",
1640 cases.add("compile error when evaluating return type of inferred error set",
17471641 \\const Car = struct {
17481642 \\ foo: *SymbolThatDoesNotExist,
17491643 \\ pub fn init() !Car {}
......@@ -1751,24 +1645,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
17511645 \\export fn entry() void {
17521646 \\ const car = Car.init();
17531647 \\}
1754 ,
1648 , &[_][]const u8{
17551649 "tmp.zig:2:11: error: use of undeclared identifier 'SymbolThatDoesNotExist'",
1756 );
1650 });
17571651
1758 cases.add(
1759 "don't implicit cast double pointer to *c_void",
1652 cases.add("don't implicit cast double pointer to *c_void",
17601653 \\export fn entry() void {
17611654 \\ var a: u32 = 1;
17621655 \\ var ptr: *c_void = &a;
17631656 \\ var b: *u32 = @ptrCast(*u32, ptr);
17641657 \\ var ptr2: *c_void = &b;
17651658 \\}
1766 ,
1659 , &[_][]const u8{
17671660 "tmp.zig:5:26: error: expected type '*c_void', found '**u32'",
1768 );
1661 });
17691662
1770 cases.add(
1771 "runtime index into comptime type slice",
1663 cases.add("runtime index into comptime type slice",
17721664 \\const Struct = struct {
17731665 \\ a: u32,
17741666 \\};
......@@ -1779,12 +1671,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
17791671 \\ const index = getIndex();
17801672 \\ const field = @typeInfo(Struct).Struct.fields[index];
17811673 \\}
1782 ,
1674 , &[_][]const u8{
17831675 "tmp.zig:9:51: error: values of type 'std.builtin.StructField' must be comptime known, but index value is runtime known",
1784 );
1676 });
17851677
1786 cases.add(
1787 "compile log statement inside function which must be comptime evaluated",
1678 cases.add("compile log statement inside function which must be comptime evaluated",
17881679 \\fn Foo(comptime T: type) type {
17891680 \\ @compileLog(@typeName(T));
17901681 \\ return T;
......@@ -1793,80 +1684,73 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
17931684 \\ _ = Foo(i32);
17941685 \\ _ = @typeName(Foo(i32));
17951686 \\}
1796 ,
1687 , &[_][]const u8{
17971688 "tmp.zig:2:5: error: found compile log statement",
1798 );
1689 });
17991690
1800 cases.add(
1801 "comptime slice of an undefined slice",
1691 cases.add("comptime slice of an undefined slice",
18021692 \\comptime {
18031693 \\ var a: []u8 = undefined;
18041694 \\ var b = a[0..10];
18051695 \\}
1806 ,
1696 , &[_][]const u8{
18071697 "tmp.zig:3:14: error: slice of undefined",
1808 );
1698 });
18091699
1810 cases.add(
1811 "implicit cast const array to mutable slice",
1700 cases.add("implicit cast const array to mutable slice",
18121701 \\export fn entry() void {
18131702 \\ const buffer: [1]u8 = [_]u8{8};
18141703 \\ const sliceA: []u8 = &buffer;
18151704 \\}
1816 ,
1705 , &[_][]const u8{
18171706 "tmp.zig:3:27: error: expected type '[]u8', found '*const [1]u8'",
1818 );
1707 });
18191708
1820 cases.add(
1821 "deref slice and get len field",
1709 cases.add("deref slice and get len field",
18221710 \\export fn entry() void {
18231711 \\ var a: []u8 = undefined;
18241712 \\ _ = a.*.len;
18251713 \\}
1826 ,
1714 , &[_][]const u8{
18271715 "tmp.zig:3:10: error: attempt to dereference non-pointer type '[]u8'",
1828 );
1716 });
18291717
1830 cases.add(
1831 "@ptrCast a 0 bit type to a non- 0 bit type",
1718 cases.add("@ptrCast a 0 bit type to a non- 0 bit type",
18321719 \\export fn entry() bool {
18331720 \\ var x: u0 = 0;
18341721 \\ const p = @ptrCast(?*u0, &x);
18351722 \\ return p == null;
18361723 \\}
1837 ,
1724 , &[_][]const u8{
18381725 "tmp.zig:3:15: error: '*u0' and '?*u0' do not have the same in-memory representation",
18391726 "tmp.zig:3:31: note: '*u0' has no in-memory bits",
18401727 "tmp.zig:3:24: note: '?*u0' has in-memory bits",
1841 );
1728 });
18421729
1843 cases.add(
1844 "comparing a non-optional pointer against null",
1730 cases.add("comparing a non-optional pointer against null",
18451731 \\export fn entry() void {
18461732 \\ var x: i32 = 1;
18471733 \\ _ = &x == null;
18481734 \\}
1849 ,
1735 , &[_][]const u8{
18501736 "tmp.zig:3:12: error: comparison of '*i32' with null",
1851 );
1737 });
18521738
1853 cases.add(
1854 "non error sets used in merge error sets operator",
1739 cases.add("non error sets used in merge error sets operator",
18551740 \\export fn foo() void {
18561741 \\ const Errors = u8 || u16;
18571742 \\}
18581743 \\export fn bar() void {
18591744 \\ const Errors = error{} || u16;
18601745 \\}
1861 ,
1746 , &[_][]const u8{
18621747 "tmp.zig:2:20: error: expected error set type, found type 'u8'",
18631748 "tmp.zig:2:23: note: `||` merges error sets; `or` performs boolean OR",
18641749 "tmp.zig:5:31: error: expected error set type, found type 'u16'",
18651750 "tmp.zig:5:28: note: `||` merges error sets; `or` performs boolean OR",
1866 );
1751 });
18671752
1868 cases.add(
1869 "variable initialization compile error then referenced",
1753 cases.add("variable initialization compile error then referenced",
18701754 \\fn Undeclared() type {
18711755 \\ return T;
18721756 \\}
......@@ -1879,23 +1763,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
18791763 \\export fn entry() void {
18801764 \\ const S = Gen();
18811765 \\}
1882 ,
1766 , &[_][]const u8{
18831767 "tmp.zig:2:12: error: use of undeclared identifier 'T'",
1884 );
1768 });
18851769
1886 cases.add(
1887 "refer to the type of a generic function",
1770 cases.add("refer to the type of a generic function",
18881771 \\export fn entry() void {
18891772 \\ const Func = fn (type) void;
18901773 \\ const f: Func = undefined;
18911774 \\ f(i32);
18921775 \\}
1893 ,
1776 , &[_][]const u8{
18941777 "tmp.zig:4:5: error: use of undefined value here causes undefined behavior",
1895 );
1778 });
18961779
1897 cases.add(
1898 "accessing runtime parameter from outer function",
1780 cases.add("accessing runtime parameter from outer function",
18991781 \\fn outer(y: u32) fn (u32) u32 {
19001782 \\ const st = struct {
19011783 \\ fn get(z: u32) u32 {
......@@ -1908,53 +1790,48 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
19081790 \\ var func = outer(10);
19091791 \\ var x = func(3);
19101792 \\}
1911 ,
1793 , &[_][]const u8{
19121794 "tmp.zig:4:24: error: 'y' not accessible from inner function",
19131795 "tmp.zig:3:28: note: crossed function definition here",
19141796 "tmp.zig:1:10: note: declared here",
1915 );
1797 });
19161798
1917 cases.add(
1918 "non int passed to @intToFloat",
1799 cases.add("non int passed to @intToFloat",
19191800 \\export fn entry() void {
19201801 \\ const x = @intToFloat(f32, 1.1);
19211802 \\}
1922 ,
1803 , &[_][]const u8{
19231804 "tmp.zig:2:32: error: expected int type, found 'comptime_float'",
1924 );
1805 });
19251806
1926 cases.add(
1927 "non float passed to @floatToInt",
1807 cases.add("non float passed to @floatToInt",
19281808 \\export fn entry() void {
19291809 \\ const x = @floatToInt(i32, @as(i32, 54));
19301810 \\}
1931 ,
1811 , &[_][]const u8{
19321812 "tmp.zig:2:32: error: expected float type, found 'i32'",
1933 );
1813 });
19341814
1935 cases.add(
1936 "out of range comptime_int passed to @floatToInt",
1815 cases.add("out of range comptime_int passed to @floatToInt",
19371816 \\export fn entry() void {
19381817 \\ const x = @floatToInt(i8, 200);
19391818 \\}
1940 ,
1819 , &[_][]const u8{
19411820 "tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'",
1942 );
1821 });
19431822
1944 cases.add(
1945 "load too many bytes from comptime reinterpreted pointer",
1823 cases.add("load too many bytes from comptime reinterpreted pointer",
19461824 \\export fn entry() void {
19471825 \\ const float: f32 = 5.99999999999994648725e-01;
19481826 \\ const float_ptr = &float;
19491827 \\ const int_ptr = @ptrCast(*const i64, float_ptr);
19501828 \\ const int_val = int_ptr.*;
19511829 \\}
1952 ,
1830 , &[_][]const u8{
19531831 "tmp.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes",
1954 );
1832 });
19551833
1956 cases.add(
1957 "invalid type used in array type",
1834 cases.add("invalid type used in array type",
19581835 \\const Item = struct {
19591836 \\ field: SomeNonexistentType,
19601837 \\};
......@@ -1962,12 +1839,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
19621839 \\export fn entry() void {
19631840 \\ const a = items[0];
19641841 \\}
1965 ,
1842 , &[_][]const u8{
19661843 "tmp.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'",
1967 );
1844 });
19681845
1969 cases.add(
1970 "comptime continue inside runtime catch",
1846 cases.add("comptime continue inside runtime catch",
19711847 \\export fn entry(c: bool) void {
19721848 \\ const ints = [_]u8{ 1, 2 };
19731849 \\ inline for (ints) |_| {
......@@ -1977,13 +1853,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
19771853 \\fn bad() !void {
19781854 \\ return error.Bad;
19791855 \\}
1980 ,
1856 , &[_][]const u8{
19811857 "tmp.zig:4:25: error: comptime control flow inside runtime block",
19821858 "tmp.zig:4:15: note: runtime block created here",
1983 );
1859 });
19841860
1985 cases.add(
1986 "comptime continue inside runtime switch",
1861 cases.add("comptime continue inside runtime switch",
19871862 \\export fn entry() void {
19881863 \\ var p: i32 = undefined;
19891864 \\ comptime var q = true;
......@@ -1995,13 +1870,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
19951870 \\ q = false;
19961871 \\ }
19971872 \\}
1998 ,
1873 , &[_][]const u8{
19991874 "tmp.zig:6:19: error: comptime control flow inside runtime block",
20001875 "tmp.zig:5:9: note: runtime block created here",
2001 );
1876 });
20021877
2003 cases.add(
2004 "comptime continue inside runtime while error",
1878 cases.add("comptime continue inside runtime while error",
20051879 \\export fn entry() void {
20061880 \\ var p: anyerror!usize = undefined;
20071881 \\ comptime var q = true;
......@@ -2012,13 +1886,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
20121886 \\ q = false;
20131887 \\ }
20141888 \\}
2015 ,
1889 , &[_][]const u8{
20161890 "tmp.zig:6:13: error: comptime control flow inside runtime block",
20171891 "tmp.zig:5:9: note: runtime block created here",
2018 );
1892 });
20191893
2020 cases.add(
2021 "comptime continue inside runtime while optional",
1894 cases.add("comptime continue inside runtime while optional",
20221895 \\export fn entry() void {
20231896 \\ var p: ?usize = undefined;
20241897 \\ comptime var q = true;
......@@ -2027,13 +1900,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
20271900 \\ q = false;
20281901 \\ }
20291902 \\}
2030 ,
1903 , &[_][]const u8{
20311904 "tmp.zig:5:23: error: comptime control flow inside runtime block",
20321905 "tmp.zig:5:9: note: runtime block created here",
2033 );
1906 });
20341907
2035 cases.add(
2036 "comptime continue inside runtime while bool",
1908 cases.add("comptime continue inside runtime while bool",
20371909 \\export fn entry() void {
20381910 \\ var p: usize = undefined;
20391911 \\ comptime var q = true;
......@@ -2042,13 +1914,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
20421914 \\ q = false;
20431915 \\ }
20441916 \\}
2045 ,
1917 , &[_][]const u8{
20461918 "tmp.zig:5:25: error: comptime control flow inside runtime block",
20471919 "tmp.zig:5:9: note: runtime block created here",
2048 );
1920 });
20491921
2050 cases.add(
2051 "comptime continue inside runtime if error",
1922 cases.add("comptime continue inside runtime if error",
20521923 \\export fn entry() void {
20531924 \\ var p: anyerror!i32 = undefined;
20541925 \\ comptime var q = true;
......@@ -2057,13 +1928,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
20571928 \\ q = false;
20581929 \\ }
20591930 \\}
2060 ,
1931 , &[_][]const u8{
20611932 "tmp.zig:5:20: error: comptime control flow inside runtime block",
20621933 "tmp.zig:5:9: note: runtime block created here",
2063 );
1934 });
20641935
2065 cases.add(
2066 "comptime continue inside runtime if optional",
1936 cases.add("comptime continue inside runtime if optional",
20671937 \\export fn entry() void {
20681938 \\ var p: ?i32 = undefined;
20691939 \\ comptime var q = true;
......@@ -2072,13 +1942,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
20721942 \\ q = false;
20731943 \\ }
20741944 \\}
2075 ,
1945 , &[_][]const u8{
20761946 "tmp.zig:5:20: error: comptime control flow inside runtime block",
20771947 "tmp.zig:5:9: note: runtime block created here",
2078 );
1948 });
20791949
2080 cases.add(
2081 "comptime continue inside runtime if bool",
1950 cases.add("comptime continue inside runtime if bool",
20821951 \\export fn entry() void {
20831952 \\ var p: usize = undefined;
20841953 \\ comptime var q = true;
......@@ -2087,13 +1956,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
20871956 \\ q = false;
20881957 \\ }
20891958 \\}
2090 ,
1959 , &[_][]const u8{
20911960 "tmp.zig:5:22: error: comptime control flow inside runtime block",
20921961 "tmp.zig:5:9: note: runtime block created here",
2093 );
1962 });
20941963
2095 cases.add(
2096 "switch with invalid expression parameter",
1964 cases.add("switch with invalid expression parameter",
20971965 \\export fn entry() void {
20981966 \\ Test(i32);
20991967 \\}
......@@ -2104,43 +1972,39 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
21041972 \\ else => unreachable,
21051973 \\ };
21061974 \\}
2107 ,
1975 , &[_][]const u8{
21081976 "tmp.zig:7:17: error: switch on type 'type' provides no expression parameter",
2109 );
1977 });
21101978
2111 cases.add(
2112 "function protoype with no body",
1979 cases.add("function protoype with no body",
21131980 \\fn foo() void;
21141981 \\export fn entry() void {
21151982 \\ foo();
21161983 \\}
2117 ,
1984 , &[_][]const u8{
21181985 "tmp.zig:1:1: error: non-extern function has no body",
2119 );
1986 });
21201987
2121 cases.add(
2122 "@frame() called outside of function definition",
1988 cases.add("@frame() called outside of function definition",
21231989 \\var handle_undef: anyframe = undefined;
21241990 \\var handle_dummy: anyframe = @frame();
21251991 \\export fn entry() bool {
21261992 \\ return handle_undef == handle_dummy;
21271993 \\}
2128 ,
1994 , &[_][]const u8{
21291995 "tmp.zig:2:30: error: @frame() called outside of function definition",
2130 );
1996 });
21311997
2132 cases.add(
2133 "`_` is not a declarable symbol",
1998 cases.add("`_` is not a declarable symbol",
21341999 \\export fn f1() usize {
21352000 \\ var _: usize = 2;
21362001 \\ return _;
21372002 \\}
2138 ,
2003 , &[_][]const u8{
21392004 "tmp.zig:2:5: error: `_` is not a declarable symbol",
2140 );
2005 });
21412006
2142 cases.add(
2143 "`_` should not be usable inside for",
2007 cases.add("`_` should not be usable inside for",
21442008 \\export fn returns() void {
21452009 \\ for ([_]void{}) |_, i| {
21462010 \\ for ([_]void{}) |_, j| {
......@@ -2148,12 +2012,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
21482012 \\ }
21492013 \\ }
21502014 \\}
2151 ,
2015 , &[_][]const u8{
21522016 "tmp.zig:4:20: error: `_` may only be used to assign things to",
2153 );
2017 });
21542018
2155 cases.add(
2156 "`_` should not be usable inside while",
2019 cases.add("`_` should not be usable inside while",
21572020 \\export fn returns() void {
21582021 \\ while (optionalReturn()) |_| {
21592022 \\ while (optionalReturn()) |_| {
......@@ -2164,12 +2027,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
21642027 \\fn optionalReturn() ?u32 {
21652028 \\ return 1;
21662029 \\}
2167 ,
2030 , &[_][]const u8{
21682031 "tmp.zig:4:20: error: `_` may only be used to assign things to",
2169 );
2032 });
21702033
2171 cases.add(
2172 "`_` should not be usable inside while else",
2034 cases.add("`_` should not be usable inside while else",
21732035 \\export fn returns() void {
21742036 \\ while (optionalReturnError()) |_| {
21752037 \\ while (optionalReturnError()) |_| {
......@@ -2182,12 +2044,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
21822044 \\fn optionalReturnError() !?u32 {
21832045 \\ return error.optionalReturnError;
21842046 \\}
2185 ,
2047 , &[_][]const u8{
21862048 "tmp.zig:6:17: error: `_` may only be used to assign things to",
2187 );
2049 });
21882050
2189 cases.add(
2190 "while loop body expression ignored",
2051 cases.add("while loop body expression ignored",
21912052 \\fn returns() usize {
21922053 \\ return 2;
21932054 \\}
......@@ -2202,25 +2063,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
22022063 \\ var x: anyerror!i32 = error.Bad;
22032064 \\ while (x) |_| returns() else |_| unreachable;
22042065 \\}
2205 ,
2066 , &[_][]const u8{
22062067 "tmp.zig:5:25: error: expression value is ignored",
22072068 "tmp.zig:9:26: error: expression value is ignored",
22082069 "tmp.zig:13:26: error: expression value is ignored",
2209 );
2070 });
22102071
2211 cases.add(
2212 "missing parameter name of generic function",
2072 cases.add("missing parameter name of generic function",
22132073 \\fn dump(var) void {}
22142074 \\export fn entry() void {
22152075 \\ var a: u8 = 9;
22162076 \\ dump(a);
22172077 \\}
2218 ,
2078 , &[_][]const u8{
22192079 "tmp.zig:1:9: error: missing parameter name",
2220 );
2080 });
22212081
2222 cases.add(
2223 "non-inline for loop on a type that requires comptime",
2082 cases.add("non-inline for loop on a type that requires comptime",
22242083 \\const Foo = struct {
22252084 \\ name: []const u8,
22262085 \\ T: type,
......@@ -2229,23 +2088,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
22292088 \\ const xx: [2]Foo = undefined;
22302089 \\ for (xx) |f| {}
22312090 \\}
2232 ,
2091 , &[_][]const u8{
22332092 "tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known",
2234 );
2093 });
22352094
2236 cases.add(
2237 "generic fn as parameter without comptime keyword",
2095 cases.add("generic fn as parameter without comptime keyword",
22382096 \\fn f(_: fn (var) void) void {}
22392097 \\fn g(_: var) void {}
22402098 \\export fn entry() void {
22412099 \\ f(g);
22422100 \\}
2243 ,
2101 , &[_][]const u8{
22442102 "tmp.zig:1:9: error: parameter of type 'fn(var)var' must be declared comptime",
2245 );
2103 });
22462104
2247 cases.add(
2248 "optional pointer to void in extern struct",
2105 cases.add("optional pointer to void in extern struct",
22492106 \\const Foo = extern struct {
22502107 \\ x: ?*const void,
22512108 \\};
......@@ -2254,12 +2111,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
22542111 \\ y: i32,
22552112 \\};
22562113 \\export fn entry(bar: *Bar) void {}
2257 ,
2114 , &[_][]const u8{
22582115 "tmp.zig:2:5: error: extern structs cannot contain fields of type '?*const void'",
2259 );
2116 });
22602117
2261 cases.add(
2262 "use of comptime-known undefined function value",
2118 cases.add("use of comptime-known undefined function value",
22632119 \\const Cmd = struct {
22642120 \\ exec: fn () void,
22652121 \\};
......@@ -2267,12 +2123,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
22672123 \\ const command = Cmd{ .exec = undefined };
22682124 \\ command.exec();
22692125 \\}
2270 ,
2126 , &[_][]const u8{
22712127 "tmp.zig:6:12: error: use of undefined value here causes undefined behavior",
2272 );
2128 });
22732129
2274 cases.add(
2275 "use of comptime-known undefined function value",
2130 cases.add("use of comptime-known undefined function value",
22762131 \\const Cmd = struct {
22772132 \\ exec: fn () void,
22782133 \\};
......@@ -2280,41 +2135,37 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
22802135 \\ const command = Cmd{ .exec = undefined };
22812136 \\ command.exec();
22822137 \\}
2283 ,
2138 , &[_][]const u8{
22842139 "tmp.zig:6:12: error: use of undefined value here causes undefined behavior",
2285 );
2140 });
22862141
2287 cases.add(
2288 "bad @alignCast at comptime",
2142 cases.add("bad @alignCast at comptime",
22892143 \\comptime {
22902144 \\ const ptr = @intToPtr(*i32, 0x1);
22912145 \\ const aligned = @alignCast(4, ptr);
22922146 \\}
2293 ,
2147 , &[_][]const u8{
22942148 "tmp.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes",
2295 );
2149 });
22962150
2297 cases.add(
2298 "@ptrToInt on *void",
2151 cases.add("@ptrToInt on *void",
22992152 \\export fn entry() bool {
23002153 \\ return @ptrToInt(&{}) == @ptrToInt(&{});
23012154 \\}
2302 ,
2155 , &[_][]const u8{
23032156 "tmp.zig:2:23: error: pointer to size 0 type has no address",
2304 );
2157 });
23052158
2306 cases.add(
2307 "@popCount - non-integer",
2159 cases.add("@popCount - non-integer",
23082160 \\export fn entry(x: f32) u32 {
23092161 \\ return @popCount(f32, x);
23102162 \\}
2311 ,
2163 , &[_][]const u8{
23122164 "tmp.zig:2:22: error: expected integer type, found 'f32'",
2313 );
2165 });
23142166
23152167 cases.addCase(x: {
2316 const tc = cases.create(
2317 "wrong same named struct",
2168 const tc = cases.create("wrong same named struct",
23182169 \\const a = @import("a.zig");
23192170 \\const b = @import("b.zig");
23202171 \\
......@@ -2324,12 +2175,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
23242175 \\}
23252176 \\
23262177 \\fn bar(x: *b.Foo) void {}
2327 ,
2178 , &[_][]const u8{
23282179 "tmp.zig:6:10: error: expected type '*b.Foo', found '*a.Foo'",
23292180 "tmp.zig:6:10: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'",
23302181 "a.zig:1:17: note: a.Foo declared here",
23312182 "b.zig:1:17: note: b.Foo declared here",
2332 );
2183 });
23332184
23342185 tc.addSourceFile("a.zig",
23352186 \\pub const Foo = struct {
......@@ -2346,8 +2197,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
23462197 break :x tc;
23472198 });
23482199
2349 cases.add(
2350 "@floatToInt comptime safety",
2200 cases.add("@floatToInt comptime safety",
23512201 \\comptime {
23522202 \\ _ = @floatToInt(i8, @as(f32, -129.1));
23532203 \\}
......@@ -2357,23 +2207,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
23572207 \\comptime {
23582208 \\ _ = @floatToInt(u8, @as(f32, 256.1));
23592209 \\}
2360 ,
2210 , &[_][]const u8{
23612211 "tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'",
23622212 "tmp.zig:5:9: error: integer value '-1' cannot be stored in type 'u8'",
23632213 "tmp.zig:8:9: error: integer value '256' cannot be stored in type 'u8'",
2364 );
2214 });
23652215
2366 cases.add(
2367 "use c_void as return type of fn ptr",
2216 cases.add("use c_void as return type of fn ptr",
23682217 \\export fn entry() void {
23692218 \\ const a: fn () c_void = undefined;
23702219 \\}
2371 ,
2220 , &[_][]const u8{
23722221 "tmp.zig:2:20: error: return type cannot be opaque",
2373 );
2222 });
23742223
2375 cases.add(
2376 "use implicit casts to assign null to non-nullable pointer",
2224 cases.add("use implicit casts to assign null to non-nullable pointer",
23772225 \\export fn entry() void {
23782226 \\ var x: i32 = 1234;
23792227 \\ var p: *i32 = &x;
......@@ -2381,30 +2229,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
23812229 \\ pp.* = null;
23822230 \\ var y = p.*;
23832231 \\}
2384 ,
2232 , &[_][]const u8{
23852233 "tmp.zig:4:23: error: expected type '*?*i32', found '**i32'",
2386 );
2234 });
23872235
2388 cases.add(
2389 "attempted implicit cast from T to [*]const T",
2236 cases.add("attempted implicit cast from T to [*]const T",
23902237 \\export fn entry() void {
23912238 \\ const x: [*]const bool = true;
23922239 \\}
2393 ,
2240 , &[_][]const u8{
23942241 "tmp.zig:2:30: error: expected type '[*]const bool', found 'bool'",
2395 );
2242 });
23962243
2397 cases.add(
2398 "dereference unknown length pointer",
2244 cases.add("dereference unknown length pointer",
23992245 \\export fn entry(x: [*]i32) i32 {
24002246 \\ return x.*;
24012247 \\}
2402 ,
2248 , &[_][]const u8{
24032249 "tmp.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32'",
2404 );
2250 });
24052251
2406 cases.add(
2407 "field access of unknown length pointer",
2252 cases.add("field access of unknown length pointer",
24082253 \\const Foo = extern struct {
24092254 \\ a: i32,
24102255 \\};
......@@ -2412,19 +2257,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
24122257 \\export fn entry(foo: [*]Foo) void {
24132258 \\ foo.a += 1;
24142259 \\}
2415 ,
2260 , &[_][]const u8{
24162261 "tmp.zig:6:8: error: type '[*]Foo' does not support field access",
2417 );
2262 });
24182263
2419 cases.add(
2420 "unknown length pointer to opaque",
2264 cases.add("unknown length pointer to opaque",
24212265 \\export const T = [*]@OpaqueType();
2422 ,
2266 , &[_][]const u8{
24232267 "tmp.zig:1:21: error: unknown-length pointer to opaque",
2424 );
2268 });
24252269
2426 cases.add(
2427 "error when evaluating return type",
2270 cases.add("error when evaluating return type",
24282271 \\const Foo = struct {
24292272 \\ map: @as(i32, i32),
24302273 \\
......@@ -2435,30 +2278,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
24352278 \\export fn entry() void {
24362279 \\ var rule_set = try Foo.init();
24372280 \\}
2438 ,
2281 , &[_][]const u8{
24392282 "tmp.zig:2:10: error: expected type 'i32', found 'type'",
2440 );
2283 });
24412284
2442 cases.add(
2443 "slicing single-item pointer",
2285 cases.add("slicing single-item pointer",
24442286 \\export fn entry(ptr: *i32) void {
24452287 \\ const slice = ptr[0..2];
24462288 \\}
2447 ,
2289 , &[_][]const u8{
24482290 "tmp.zig:2:22: error: slice of single-item pointer",
2449 );
2291 });
24502292
2451 cases.add(
2452 "indexing single-item pointer",
2293 cases.add("indexing single-item pointer",
24532294 \\export fn entry(ptr: *i32) i32 {
24542295 \\ return ptr[1];
24552296 \\}
2456 ,
2297 , &[_][]const u8{
24572298 "tmp.zig:2:15: error: index of single-item pointer",
2458 );
2299 });
24592300
2460 cases.add(
2461 "nested error set mismatch",
2301 cases.add("nested error set mismatch",
24622302 \\const NextError = error{NextError};
24632303 \\const OtherError = error{OutOfMemory};
24642304 \\
......@@ -2469,15 +2309,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
24692309 \\fn foo() ?OtherError!i32 {
24702310 \\ return null;
24712311 \\}
2472 ,
2312 , &[_][]const u8{
24732313 "tmp.zig:5:34: error: expected type '?NextError!i32', found '?OtherError!i32'",
24742314 "tmp.zig:5:34: note: optional type child 'OtherError!i32' cannot cast into optional type child 'NextError!i32'",
24752315 "tmp.zig:5:34: note: error set 'OtherError' cannot cast into error set 'NextError'",
24762316 "tmp.zig:2:26: note: 'error.OutOfMemory' not a member of destination error set",
2477 );
2317 });
24782318
2479 cases.add(
2480 "invalid deref on switch target",
2319 cases.add("invalid deref on switch target",
24812320 \\comptime {
24822321 \\ var tile = Tile.Empty;
24832322 \\ switch (tile.*) {
......@@ -2489,19 +2328,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
24892328 \\ Empty,
24902329 \\ Filled,
24912330 \\};
2492 ,
2331 , &[_][]const u8{
24932332 "tmp.zig:3:17: error: attempt to dereference non-pointer type 'Tile'",
2494 );
2333 });
24952334
2496 cases.add(
2497 "invalid field access in comptime",
2335 cases.add("invalid field access in comptime",
24982336 \\comptime { var x = doesnt_exist.whatever; }
2499 ,
2337 , &[_][]const u8{
25002338 "tmp.zig:1:20: error: use of undeclared identifier 'doesnt_exist'",
2501 );
2339 });
25022340
2503 cases.add(
2504 "suspend inside suspend block",
2341 cases.add("suspend inside suspend block",
25052342 \\export fn entry() void {
25062343 \\ _ = async foo();
25072344 \\}
......@@ -2511,34 +2348,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
25112348 \\ }
25122349 \\ }
25132350 \\}
2514 ,
2351 , &[_][]const u8{
25152352 "tmp.zig:6:9: error: cannot suspend inside suspend block",
25162353 "tmp.zig:5:5: note: other suspend block here",
2517 );
2354 });
25182355
2519 cases.add(
2520 "assign inline fn to non-comptime var",
2356 cases.add("assign inline fn to non-comptime var",
25212357 \\export fn entry() void {
25222358 \\ var a = b;
25232359 \\}
25242360 \\inline fn b() void { }
2525 ,
2361 , &[_][]const u8{
25262362 "tmp.zig:2:5: error: functions marked inline must be stored in const or comptime var",
25272363 "tmp.zig:4:1: note: declared here",
2528 );
2364 });
25292365
2530 cases.add(
2531 "wrong type passed to @panic",
2366 cases.add("wrong type passed to @panic",
25322367 \\export fn entry() void {
25332368 \\ var e = error.Foo;
25342369 \\ @panic(e);
25352370 \\}
2536 ,
2371 , &[_][]const u8{
25372372 "tmp.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'",
2538 );
2373 });
25392374
2540 cases.add(
2541 "@tagName used on union with no associated enum tag",
2375 cases.add("@tagName used on union with no associated enum tag",
25422376 \\const FloatInt = extern union {
25432377 \\ Float: f32,
25442378 \\ Int: i32,
......@@ -2547,54 +2381,49 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
25472381 \\ var fi = FloatInt{.Float = 123.45};
25482382 \\ var tagName = @tagName(fi);
25492383 \\}
2550 ,
2384 , &[_][]const u8{
25512385 "tmp.zig:7:19: error: union has no associated enum",
25522386 "tmp.zig:1:18: note: declared here",
2553 );
2387 });
25542388
2555 cases.add(
2556 "returning error from void async function",
2389 cases.add("returning error from void async function",
25572390 \\export fn entry() void {
25582391 \\ _ = async amain();
25592392 \\}
25602393 \\async fn amain() void {
25612394 \\ return error.ShouldBeCompileError;
25622395 \\}
2563 ,
2396 , &[_][]const u8{
25642397 "tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'",
2565 );
2398 });
25662399
2567 cases.add(
2568 "var makes structs required to be comptime known",
2400 cases.add("var makes structs required to be comptime known",
25692401 \\export fn entry() void {
25702402 \\ const S = struct{v: var};
25712403 \\ var s = S{.v=@as(i32, 10)};
25722404 \\}
2573 ,
2405 , &[_][]const u8{
25742406 "tmp.zig:3:4: error: variable of type 'S' must be const or comptime",
2575 );
2407 });
25762408
2577 cases.add(
2578 "@ptrCast discards const qualifier",
2409 cases.add("@ptrCast discards const qualifier",
25792410 \\export fn entry() void {
25802411 \\ const x: i32 = 1234;
25812412 \\ const y = @ptrCast(*i32, &x);
25822413 \\}
2583 ,
2414 , &[_][]const u8{
25842415 "tmp.zig:3:15: error: cast discards const qualifier",
2585 );
2416 });
25862417
2587 cases.add(
2588 "comptime slice of undefined pointer non-zero len",
2418 cases.add("comptime slice of undefined pointer non-zero len",
25892419 \\export fn entry() void {
25902420 \\ const slice = @as([*]i32, undefined)[0..1];
25912421 \\}
2592 ,
2422 , &[_][]const u8{
25932423 "tmp.zig:2:41: error: non-zero length slice of undefined pointer",
2594 );
2424 });
25952425
2596 cases.add(
2597 "type checking function pointers",
2426 cases.add("type checking function pointers",
25982427 \\fn a(b: fn (*const u8) void) void {
25992428 \\ b('a');
26002429 \\}
......@@ -2602,12 +2431,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
26022431 \\export fn entry() void {
26032432 \\ a(c);
26042433 \\}
2605 ,
2434 , &[_][]const u8{
26062435 "tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'",
2607 );
2436 });
26082437
2609 cases.add(
2610 "no else prong on switch on global error set",
2438 cases.add("no else prong on switch on global error set",
26112439 \\export fn entry() void {
26122440 \\ foo(error.A);
26132441 \\}
......@@ -2616,23 +2444,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
26162444 \\ error.A => {},
26172445 \\ }
26182446 \\}
2619 ,
2447 , &[_][]const u8{
26202448 "tmp.zig:5:5: error: else prong required when switching on type 'anyerror'",
2621 );
2449 });
26222450
2623 cases.add(
2624 "inferred error set with no returned error",
2451 cases.add("inferred error set with no returned error",
26252452 \\export fn entry() void {
26262453 \\ foo() catch unreachable;
26272454 \\}
26282455 \\fn foo() !void {
26292456 \\}
2630 ,
2457 , &[_][]const u8{
26312458 "tmp.zig:4:11: error: function with inferred error set must return at least one possible error",
2632 );
2459 });
26332460
2634 cases.add(
2635 "error not handled in switch",
2461 cases.add("error not handled in switch",
26362462 \\export fn entry() void {
26372463 \\ foo(452) catch |err| switch (err) {
26382464 \\ error.Foo => {},
......@@ -2646,13 +2472,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
26462472 \\ else => {},
26472473 \\ }
26482474 \\}
2649 ,
2475 , &[_][]const u8{
26502476 "tmp.zig:2:26: error: error.Baz not handled in switch",
26512477 "tmp.zig:2:26: error: error.Bar not handled in switch",
2652 );
2478 });
26532479
2654 cases.add(
2655 "duplicate error in switch",
2480 cases.add("duplicate error in switch",
26562481 \\export fn entry() void {
26572482 \\ foo(452) catch |err| switch (err) {
26582483 \\ error.Foo => {},
......@@ -2668,10 +2493,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
26682493 \\ else => {},
26692494 \\ }
26702495 \\}
2671 ,
2496 , &[_][]const u8{
26722497 "tmp.zig:5:14: error: duplicate switch value: '@typeOf(foo).ReturnType.ErrorSet.Foo'",
26732498 "tmp.zig:3:14: note: other value is here",
2674 );
2499 });
26752500
26762501 cases.add("invalid cast from integral type to enum",
26772502 \\const E = enum(usize) { One, Two };
......@@ -2685,10 +2510,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
26852510 \\ E.One => {},
26862511 \\ }
26872512 \\}
2688 , "tmp.zig:9:10: error: expected type 'usize', found 'E'");
2513 , &[_][]const u8{
2514 "tmp.zig:9:10: error: expected type 'usize', found 'E'",
2515 });
26892516
2690 cases.add(
2691 "range operator in switch used on error set",
2517 cases.add("range operator in switch used on error set",
26922518 \\export fn entry() void {
26932519 \\ try foo(452) catch |err| switch (err) {
26942520 \\ error.A ... error.B => {},
......@@ -2702,41 +2528,37 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
27022528 \\ else => {},
27032529 \\ }
27042530 \\}
2705 ,
2531 , &[_][]const u8{
27062532 "tmp.zig:3:17: error: operator not allowed for errors",
2707 );
2533 });
27082534
2709 cases.add(
2710 "inferring error set of function pointer",
2535 cases.add("inferring error set of function pointer",
27112536 \\comptime {
27122537 \\ const z: ?fn()!void = null;
27132538 \\}
2714 ,
2539 , &[_][]const u8{
27152540 "tmp.zig:2:15: error: inferring error set of return type valid only for function definitions",
2716 );
2541 });
27172542
2718 cases.add(
2719 "access non-existent member of error set",
2543 cases.add("access non-existent member of error set",
27202544 \\const Foo = error{A};
27212545 \\comptime {
27222546 \\ const z = Foo.Bar;
27232547 \\}
2724 ,
2548 , &[_][]const u8{
27252549 "tmp.zig:3:18: error: no error named 'Bar' in 'Foo'",
2726 );
2550 });
27272551
2728 cases.add(
2729 "error union operator with non error set LHS",
2552 cases.add("error union operator with non error set LHS",
27302553 \\comptime {
27312554 \\ const z = i32!i32;
27322555 \\ var x: z = undefined;
27332556 \\}
2734 ,
2557 , &[_][]const u8{
27352558 "tmp.zig:2:15: error: expected error set type, found type 'i32'",
2736 );
2559 });
27372560
2738 cases.add(
2739 "error equality but sets have no common members",
2561 cases.add("error equality but sets have no common members",
27402562 \\const Set1 = error{A, C};
27412563 \\const Set2 = error{B, D};
27422564 \\export fn entry() void {
......@@ -2747,33 +2569,30 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
27472569 \\
27482570 \\ }
27492571 \\}
2750 ,
2572 , &[_][]const u8{
27512573 "tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors",
2752 );
2574 });
27532575
2754 cases.add(
2755 "only equality binary operator allowed for error sets",
2576 cases.add("only equality binary operator allowed for error sets",
27562577 \\comptime {
27572578 \\ const z = error.A > error.B;
27582579 \\}
2759 ,
2580 , &[_][]const u8{
27602581 "tmp.zig:2:23: error: operator not allowed for errors",
2761 );
2582 });
27622583
2763 cases.add(
2764 "explicit error set cast known at comptime violates error sets",
2584 cases.add("explicit error set cast known at comptime violates error sets",
27652585 \\const Set1 = error {A, B};
27662586 \\const Set2 = error {A, C};
27672587 \\comptime {
27682588 \\ var x = Set1.B;
27692589 \\ var y = @errSetCast(Set2, x);
27702590 \\}
2771 ,
2591 , &[_][]const u8{
27722592 "tmp.zig:5:13: error: error.B not a member of error set 'Set2'",
2773 );
2593 });
27742594
2775 cases.add(
2776 "cast error union of global error set to error union of smaller error set",
2595 cases.add("cast error union of global error set to error union of smaller error set",
27772596 \\const SmallErrorSet = error{A};
27782597 \\export fn entry() void {
27792598 \\ var x: SmallErrorSet!i32 = foo();
......@@ -2781,14 +2600,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
27812600 \\fn foo() anyerror!i32 {
27822601 \\ return error.B;
27832602 \\}
2784 ,
2603 , &[_][]const u8{
27852604 "tmp.zig:3:35: error: expected type 'SmallErrorSet!i32', found 'anyerror!i32'",
27862605 "tmp.zig:3:35: note: error set 'anyerror' cannot cast into error set 'SmallErrorSet'",
27872606 "tmp.zig:3:35: note: cannot cast global error set into smaller set",
2788 );
2607 });
27892608
2790 cases.add(
2791 "cast global error set to error set",
2609 cases.add("cast global error set to error set",
27922610 \\const SmallErrorSet = error{A};
27932611 \\export fn entry() void {
27942612 \\ var x: SmallErrorSet = foo();
......@@ -2796,24 +2614,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
27962614 \\fn foo() anyerror {
27972615 \\ return error.B;
27982616 \\}
2799 ,
2617 , &[_][]const u8{
28002618 "tmp.zig:3:31: error: expected type 'SmallErrorSet', found 'anyerror'",
28012619 "tmp.zig:3:31: note: cannot cast global error set into smaller set",
2802 );
2803 cases.add(
2804 "recursive inferred error set",
2620 });
2621 cases.add("recursive inferred error set",
28052622 \\export fn entry() void {
28062623 \\ foo() catch unreachable;
28072624 \\}
28082625 \\fn foo() !void {
28092626 \\ try foo();
28102627 \\}
2811 ,
2628 , &[_][]const u8{
28122629 "tmp.zig:5:5: error: cannot resolve inferred error set '@typeOf(foo).ReturnType.ErrorSet': function 'foo' not fully analyzed yet",
2813 );
2630 });
28142631
2815 cases.add(
2816 "implicit cast of error set not a subset",
2632 cases.add("implicit cast of error set not a subset",
28172633 \\const Set1 = error{A, B};
28182634 \\const Set2 = error{A, C};
28192635 \\export fn entry() void {
......@@ -2822,13 +2638,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
28222638 \\fn foo(set1: Set1) void {
28232639 \\ var x: Set2 = set1;
28242640 \\}
2825 ,
2641 , &[_][]const u8{
28262642 "tmp.zig:7:19: error: expected type 'Set2', found 'Set1'",
28272643 "tmp.zig:1:23: note: 'error.B' not a member of destination error set",
2828 );
2644 });
28292645
2830 cases.add(
2831 "int to err global invalid number",
2646 cases.add("int to err global invalid number",
28322647 \\const Set1 = error{
28332648 \\ A,
28342649 \\ B,
......@@ -2837,12 +2652,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
28372652 \\ var x: u16 = 3;
28382653 \\ var y = @intToError(x);
28392654 \\}
2840 ,
2655 , &[_][]const u8{
28412656 "tmp.zig:7:13: error: integer value 3 represents no error",
2842 );
2657 });
28432658
2844 cases.add(
2845 "int to err non global invalid number",
2659 cases.add("int to err non global invalid number",
28462660 \\const Set1 = error{
28472661 \\ A,
28482662 \\ B,
......@@ -2855,21 +2669,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
28552669 \\ var x = @errorToInt(Set1.B);
28562670 \\ var y = @errSetCast(Set2, @intToError(x));
28572671 \\}
2858 ,
2672 , &[_][]const u8{
28592673 "tmp.zig:11:13: error: error.B not a member of error set 'Set2'",
2860 );
2674 });
28612675
2862 cases.add(
2863 "@memberCount of error",
2676 cases.add("@memberCount of error",
28642677 \\comptime {
28652678 \\ _ = @memberCount(anyerror);
28662679 \\}
2867 ,
2680 , &[_][]const u8{
28682681 "tmp.zig:2:9: error: global error set member count not available at comptime",
2869 );
2682 });
28702683
2871 cases.add(
2872 "duplicate error value in error set",
2684 cases.add("duplicate error value in error set",
28732685 \\const Foo = error {
28742686 \\ Bar,
28752687 \\ Bar,
......@@ -2877,32 +2689,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
28772689 \\export fn entry() void {
28782690 \\ const a: Foo = undefined;
28792691 \\}
2880 ,
2692 , &[_][]const u8{
28812693 "tmp.zig:3:5: error: duplicate error: 'Bar'",
28822694 "tmp.zig:2:5: note: other error here",
2883 );
2695 });
28842696
2885 cases.add(
2886 "cast negative integer literal to usize",
2697 cases.add("cast negative integer literal to usize",
28872698 \\export fn entry() void {
28882699 \\ const x = @as(usize, -10);
28892700 \\}
2890 ,
2701 , &[_][]const u8{
28912702 "tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'",
2892 );
2703 });
28932704
2894 cases.add(
2895 "use invalid number literal as array index",
2705 cases.add("use invalid number literal as array index",
28962706 \\var v = 25;
28972707 \\export fn entry() void {
28982708 \\ var arr: [v]u8 = undefined;
28992709 \\}
2900 ,
2710 , &[_][]const u8{
29012711 "tmp.zig:1:1: error: unable to infer variable type",
2902 );
2712 });
29032713
2904 cases.add(
2905 "duplicate struct field",
2714 cases.add("duplicate struct field",
29062715 \\const Foo = struct {
29072716 \\ Bar: i32,
29082717 \\ Bar: usize,
......@@ -2910,13 +2719,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
29102719 \\export fn entry() void {
29112720 \\ const a: Foo = undefined;
29122721 \\}
2913 ,
2722 , &[_][]const u8{
29142723 "tmp.zig:3:5: error: duplicate struct field: 'Bar'",
29152724 "tmp.zig:2:5: note: other field here",
2916 );
2725 });
29172726
2918 cases.add(
2919 "duplicate union field",
2727 cases.add("duplicate union field",
29202728 \\const Foo = union {
29212729 \\ Bar: i32,
29222730 \\ Bar: usize,
......@@ -2924,13 +2732,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
29242732 \\export fn entry() void {
29252733 \\ const a: Foo = undefined;
29262734 \\}
2927 ,
2735 , &[_][]const u8{
29282736 "tmp.zig:3:5: error: duplicate union field: 'Bar'",
29292737 "tmp.zig:2:5: note: other field here",
2930 );
2738 });
29312739
2932 cases.add(
2933 "duplicate enum field",
2740 cases.add("duplicate enum field",
29342741 \\const Foo = enum {
29352742 \\ Bar,
29362743 \\ Bar,
......@@ -2939,110 +2746,99 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
29392746 \\export fn entry() void {
29402747 \\ const a: Foo = undefined;
29412748 \\}
2942 ,
2749 , &[_][]const u8{
29432750 "tmp.zig:3:5: error: duplicate enum field: 'Bar'",
29442751 "tmp.zig:2:5: note: other field here",
2945 );
2752 });
29462753
2947 cases.add(
2948 "calling function with naked calling convention",
2754 cases.add("calling function with naked calling convention",
29492755 \\export fn entry() void {
29502756 \\ foo();
29512757 \\}
29522758 \\nakedcc fn foo() void { }
2953 ,
2759 , &[_][]const u8{
29542760 "tmp.zig:2:5: error: unable to call function with naked calling convention",
29552761 "tmp.zig:4:1: note: declared here",
2956 );
2762 });
29572763
2958 cases.add(
2959 "function with invalid return type",
2764 cases.add("function with invalid return type",
29602765 \\export fn foo() boid {}
2961 ,
2766 , &[_][]const u8{
29622767 "tmp.zig:1:17: error: use of undeclared identifier 'boid'",
2963 );
2768 });
29642769
2965 cases.add(
2966 "function with non-extern non-packed enum parameter",
2770 cases.add("function with non-extern non-packed enum parameter",
29672771 \\const Foo = enum { A, B, C };
29682772 \\export fn entry(foo: Foo) void { }
2969 ,
2773 , &[_][]const u8{
29702774 "tmp.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'",
2971 );
2775 });
29722776
2973 cases.add(
2974 "function with non-extern non-packed struct parameter",
2777 cases.add("function with non-extern non-packed struct parameter",
29752778 \\const Foo = struct {
29762779 \\ A: i32,
29772780 \\ B: f32,
29782781 \\ C: bool,
29792782 \\};
29802783 \\export fn entry(foo: Foo) void { }
2981 ,
2784 , &[_][]const u8{
29822785 "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'",
2983 );
2786 });
29842787
2985 cases.add(
2986 "function with non-extern non-packed union parameter",
2788 cases.add("function with non-extern non-packed union parameter",
29872789 \\const Foo = union {
29882790 \\ A: i32,
29892791 \\ B: f32,
29902792 \\ C: bool,
29912793 \\};
29922794 \\export fn entry(foo: Foo) void { }
2993 ,
2795 , &[_][]const u8{
29942796 "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'",
2995 );
2797 });
29962798
2997 cases.add(
2998 "switch on enum with 1 field with no prongs",
2799 cases.add("switch on enum with 1 field with no prongs",
29992800 \\const Foo = enum { M };
30002801 \\
30012802 \\export fn entry() void {
30022803 \\ var f = Foo.M;
30032804 \\ switch (f) {}
30042805 \\}
3005 ,
2806 , &[_][]const u8{
30062807 "tmp.zig:5:5: error: enumeration value 'Foo.M' not handled in switch",
3007 );
2808 });
30082809
3009 cases.add(
3010 "shift by negative comptime integer",
2810 cases.add("shift by negative comptime integer",
30112811 \\comptime {
30122812 \\ var a = 1 >> -1;
30132813 \\}
3014 ,
2814 , &[_][]const u8{
30152815 "tmp.zig:2:18: error: shift by negative value -1",
3016 );
2816 });
30172817
3018 cases.add(
3019 "@panic called at compile time",
2818 cases.add("@panic called at compile time",
30202819 \\export fn entry() void {
30212820 \\ comptime {
30222821 \\ @panic("aoeu",);
30232822 \\ }
30242823 \\}
3025 ,
2824 , &[_][]const u8{
30262825 "tmp.zig:3:9: error: encountered @panic at compile-time",
3027 );
2826 });
30282827
3029 cases.add(
3030 "wrong return type for main",
2828 cases.add("wrong return type for main",
30312829 \\pub fn main() f32 { }
3032 ,
2830 , &[_][]const u8{
30332831 "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'",
3034 );
2832 });
30352833
3036 cases.add(
3037 "double ?? on main return value",
2834 cases.add("double ?? on main return value",
30382835 \\pub fn main() ??void {
30392836 \\}
3040 ,
2837 , &[_][]const u8{
30412838 "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'",
3042 );
2839 });
30432840
3044 cases.add(
3045 "bad identifier in function with struct defined inside function which references local const",
2841 cases.add("bad identifier in function with struct defined inside function which references local const",
30462842 \\export fn entry() void {
30472843 \\ const BlockKind = u32;
30482844 \\
......@@ -3052,12 +2848,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
30522848 \\
30532849 \\ bogus;
30542850 \\}
3055 ,
2851 , &[_][]const u8{
30562852 "tmp.zig:8:5: error: use of undeclared identifier 'bogus'",
3057 );
2853 });
30582854
3059 cases.add(
3060 "labeled break not found",
2855 cases.add("labeled break not found",
30612856 \\export fn entry() void {
30622857 \\ blah: while (true) {
30632858 \\ while (true) {
......@@ -3065,12 +2860,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
30652860 \\ }
30662861 \\ }
30672862 \\}
3068 ,
2863 , &[_][]const u8{
30692864 "tmp.zig:4:13: error: label not found: 'outer'",
3070 );
2865 });
30712866
3072 cases.add(
3073 "labeled continue not found",
2867 cases.add("labeled continue not found",
30742868 \\export fn entry() void {
30752869 \\ var i: usize = 0;
30762870 \\ blah: while (i < 10) : (i += 1) {
......@@ -3079,12 +2873,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
30792873 \\ }
30802874 \\ }
30812875 \\}
3082 ,
2876 , &[_][]const u8{
30832877 "tmp.zig:5:13: error: labeled loop not found: 'outer'",
3084 );
2878 });
30852879
3086 cases.add(
3087 "attempt to use 0 bit type in extern fn",
2880 cases.add("attempt to use 0 bit type in extern fn",
30882881 \\extern fn foo(ptr: extern fn(*void) void) void;
30892882 \\
30902883 \\export fn entry() void {
......@@ -3095,476 +2888,431 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
30952888 \\export fn entry2() void {
30962889 \\ bar(&{});
30972890 \\}
3098 ,
2891 , &[_][]const u8{
30992892 "tmp.zig:1:30: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'",
31002893 "tmp.zig:7:18: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'",
3101 );
2894 });
31022895
3103 cases.add(
3104 "implicit semicolon - block statement",
2896 cases.add("implicit semicolon - block statement",
31052897 \\export fn entry() void {
31062898 \\ {}
31072899 \\ var good = {};
31082900 \\ ({})
31092901 \\ var bad = {};
31102902 \\}
3111 ,
2903 , &[_][]const u8{
31122904 "tmp.zig:5:5: error: expected token ';', found 'var'",
3113 );
2905 });
31142906
3115 cases.add(
3116 "implicit semicolon - block expr",
2907 cases.add("implicit semicolon - block expr",
31172908 \\export fn entry() void {
31182909 \\ _ = {};
31192910 \\ var good = {};
31202911 \\ _ = {}
31212912 \\ var bad = {};
31222913 \\}
3123 ,
2914 , &[_][]const u8{
31242915 "tmp.zig:5:5: error: expected token ';', found 'var'",
3125 );
2916 });
31262917
3127 cases.add(
3128 "implicit semicolon - comptime statement",
2918 cases.add("implicit semicolon - comptime statement",
31292919 \\export fn entry() void {
31302920 \\ comptime {}
31312921 \\ var good = {};
31322922 \\ comptime ({})
31332923 \\ var bad = {};
31342924 \\}
3135 ,
2925 , &[_][]const u8{
31362926 "tmp.zig:5:5: error: expected token ';', found 'var'",
3137 );
2927 });
31382928
3139 cases.add(
3140 "implicit semicolon - comptime expression",
2929 cases.add("implicit semicolon - comptime expression",
31412930 \\export fn entry() void {
31422931 \\ _ = comptime {};
31432932 \\ var good = {};
31442933 \\ _ = comptime {}
31452934 \\ var bad = {};
31462935 \\}
3147 ,
2936 , &[_][]const u8{
31482937 "tmp.zig:5:5: error: expected token ';', found 'var'",
3149 );
2938 });
31502939
3151 cases.add(
3152 "implicit semicolon - defer",
2940 cases.add("implicit semicolon - defer",
31532941 \\export fn entry() void {
31542942 \\ defer {}
31552943 \\ var good = {};
31562944 \\ defer ({})
31572945 \\ var bad = {};
31582946 \\}
3159 ,
2947 , &[_][]const u8{
31602948 "tmp.zig:5:5: error: expected token ';', found 'var'",
3161 );
2949 });
31622950
3163 cases.add(
3164 "implicit semicolon - if statement",
2951 cases.add("implicit semicolon - if statement",
31652952 \\export fn entry() void {
31662953 \\ if(true) {}
31672954 \\ var good = {};
31682955 \\ if(true) ({})
31692956 \\ var bad = {};
31702957 \\}
3171 ,
2958 , &[_][]const u8{
31722959 "tmp.zig:5:5: error: expected token ';', found 'var'",
3173 );
2960 });
31742961
3175 cases.add(
3176 "implicit semicolon - if expression",
2962 cases.add("implicit semicolon - if expression",
31772963 \\export fn entry() void {
31782964 \\ _ = if(true) {};
31792965 \\ var good = {};
31802966 \\ _ = if(true) {}
31812967 \\ var bad = {};
31822968 \\}
3183 ,
2969 , &[_][]const u8{
31842970 "tmp.zig:5:5: error: expected token ';', found 'var'",
3185 );
2971 });
31862972
3187 cases.add(
3188 "implicit semicolon - if-else statement",
2973 cases.add("implicit semicolon - if-else statement",
31892974 \\export fn entry() void {
31902975 \\ if(true) {} else {}
31912976 \\ var good = {};
31922977 \\ if(true) ({}) else ({})
31932978 \\ var bad = {};
31942979 \\}
3195 ,
2980 , &[_][]const u8{
31962981 "tmp.zig:5:5: error: expected token ';', found 'var'",
3197 );
2982 });
31982983
3199 cases.add(
3200 "implicit semicolon - if-else expression",
2984 cases.add("implicit semicolon - if-else expression",
32012985 \\export fn entry() void {
32022986 \\ _ = if(true) {} else {};
32032987 \\ var good = {};
32042988 \\ _ = if(true) {} else {}
32052989 \\ var bad = {};
32062990 \\}
3207 ,
2991 , &[_][]const u8{
32082992 "tmp.zig:5:5: error: expected token ';', found 'var'",
3209 );
2993 });
32102994
3211 cases.add(
3212 "implicit semicolon - if-else-if statement",
2995 cases.add("implicit semicolon - if-else-if statement",
32132996 \\export fn entry() void {
32142997 \\ if(true) {} else if(true) {}
32152998 \\ var good = {};
32162999 \\ if(true) ({}) else if(true) ({})
32173000 \\ var bad = {};
32183001 \\}
3219 ,
3002 , &[_][]const u8{
32203003 "tmp.zig:5:5: error: expected token ';', found 'var'",
3221 );
3004 });
32223005
3223 cases.add(
3224 "implicit semicolon - if-else-if expression",
3006 cases.add("implicit semicolon - if-else-if expression",
32253007 \\export fn entry() void {
32263008 \\ _ = if(true) {} else if(true) {};
32273009 \\ var good = {};
32283010 \\ _ = if(true) {} else if(true) {}
32293011 \\ var bad = {};
32303012 \\}
3231 ,
3013 , &[_][]const u8{
32323014 "tmp.zig:5:5: error: expected token ';', found 'var'",
3233 );
3015 });
32343016
3235 cases.add(
3236 "implicit semicolon - if-else-if-else statement",
3017 cases.add("implicit semicolon - if-else-if-else statement",
32373018 \\export fn entry() void {
32383019 \\ if(true) {} else if(true) {} else {}
32393020 \\ var good = {};
32403021 \\ if(true) ({}) else if(true) ({}) else ({})
32413022 \\ var bad = {};
32423023 \\}
3243 ,
3024 , &[_][]const u8{
32443025 "tmp.zig:5:5: error: expected token ';', found 'var'",
3245 );
3026 });
32463027
3247 cases.add(
3248 "implicit semicolon - if-else-if-else expression",
3028 cases.add("implicit semicolon - if-else-if-else expression",
32493029 \\export fn entry() void {
32503030 \\ _ = if(true) {} else if(true) {} else {};
32513031 \\ var good = {};
32523032 \\ _ = if(true) {} else if(true) {} else {}
32533033 \\ var bad = {};
32543034 \\}
3255 ,
3035 , &[_][]const u8{
32563036 "tmp.zig:5:5: error: expected token ';', found 'var'",
3257 );
3037 });
32583038
3259 cases.add(
3260 "implicit semicolon - test statement",
3039 cases.add("implicit semicolon - test statement",
32613040 \\export fn entry() void {
32623041 \\ if (foo()) |_| {}
32633042 \\ var good = {};
32643043 \\ if (foo()) |_| ({})
32653044 \\ var bad = {};
32663045 \\}
3267 ,
3046 , &[_][]const u8{
32683047 "tmp.zig:5:5: error: expected token ';', found 'var'",
3269 );
3048 });
32703049
3271 cases.add(
3272 "implicit semicolon - test expression",
3050 cases.add("implicit semicolon - test expression",
32733051 \\export fn entry() void {
32743052 \\ _ = if (foo()) |_| {};
32753053 \\ var good = {};
32763054 \\ _ = if (foo()) |_| {}
32773055 \\ var bad = {};
32783056 \\}
3279 ,
3057 , &[_][]const u8{
32803058 "tmp.zig:5:5: error: expected token ';', found 'var'",
3281 );
3059 });
32823060
3283 cases.add(
3284 "implicit semicolon - while statement",
3061 cases.add("implicit semicolon - while statement",
32853062 \\export fn entry() void {
32863063 \\ while(true) {}
32873064 \\ var good = {};
32883065 \\ while(true) ({})
32893066 \\ var bad = {};
32903067 \\}
3291 ,
3068 , &[_][]const u8{
32923069 "tmp.zig:5:5: error: expected token ';', found 'var'",
3293 );
3070 });
32943071
3295 cases.add(
3296 "implicit semicolon - while expression",
3072 cases.add("implicit semicolon - while expression",
32973073 \\export fn entry() void {
32983074 \\ _ = while(true) {};
32993075 \\ var good = {};
33003076 \\ _ = while(true) {}
33013077 \\ var bad = {};
33023078 \\}
3303 ,
3079 , &[_][]const u8{
33043080 "tmp.zig:5:5: error: expected token ';', found 'var'",
3305 );
3081 });
33063082
3307 cases.add(
3308 "implicit semicolon - while-continue statement",
3083 cases.add("implicit semicolon - while-continue statement",
33093084 \\export fn entry() void {
33103085 \\ while(true):({}) {}
33113086 \\ var good = {};
33123087 \\ while(true):({}) ({})
33133088 \\ var bad = {};
33143089 \\}
3315 ,
3090 , &[_][]const u8{
33163091 "tmp.zig:5:5: error: expected token ';', found 'var'",
3317 );
3092 });
33183093
3319 cases.add(
3320 "implicit semicolon - while-continue expression",
3094 cases.add("implicit semicolon - while-continue expression",
33213095 \\export fn entry() void {
33223096 \\ _ = while(true):({}) {};
33233097 \\ var good = {};
33243098 \\ _ = while(true):({}) {}
33253099 \\ var bad = {};
33263100 \\}
3327 ,
3101 , &[_][]const u8{
33283102 "tmp.zig:5:5: error: expected token ';', found 'var'",
3329 );
3103 });
33303104
3331 cases.add(
3332 "implicit semicolon - for statement",
3105 cases.add("implicit semicolon - for statement",
33333106 \\export fn entry() void {
33343107 \\ for(foo()) |_| {}
33353108 \\ var good = {};
33363109 \\ for(foo()) |_| ({})
33373110 \\ var bad = {};
33383111 \\}
3339 ,
3112 , &[_][]const u8{
33403113 "tmp.zig:5:5: error: expected token ';', found 'var'",
3341 );
3114 });
33423115
3343 cases.add(
3344 "implicit semicolon - for expression",
3116 cases.add("implicit semicolon - for expression",
33453117 \\export fn entry() void {
33463118 \\ _ = for(foo()) |_| {};
33473119 \\ var good = {};
33483120 \\ _ = for(foo()) |_| {}
33493121 \\ var bad = {};
33503122 \\}
3351 ,
3123 , &[_][]const u8{
33523124 "tmp.zig:5:5: error: expected token ';', found 'var'",
3353 );
3125 });
33543126
3355 cases.add(
3356 "multiple function definitions",
3127 cases.add("multiple function definitions",
33573128 \\fn a() void {}
33583129 \\fn a() void {}
33593130 \\export fn entry() void { a(); }
3360 ,
3131 , &[_][]const u8{
33613132 "tmp.zig:2:1: error: redefinition of 'a'",
3362 );
3133 });
33633134
3364 cases.add(
3365 "unreachable with return",
3135 cases.add("unreachable with return",
33663136 \\fn a() noreturn {return;}
33673137 \\export fn entry() void { a(); }
3368 ,
3138 , &[_][]const u8{
33693139 "tmp.zig:1:18: error: expected type 'noreturn', found 'void'",
3370 );
3140 });
33713141
3372 cases.add(
3373 "control reaches end of non-void function",
3142 cases.add("control reaches end of non-void function",
33743143 \\fn a() i32 {}
33753144 \\export fn entry() void { _ = a(); }
3376 ,
3145 , &[_][]const u8{
33773146 "tmp.zig:1:12: error: expected type 'i32', found 'void'",
3378 );
3147 });
33793148
3380 cases.add(
3381 "undefined function call",
3149 cases.add("undefined function call",
33823150 \\export fn a() void {
33833151 \\ b();
33843152 \\}
3385 ,
3153 , &[_][]const u8{
33863154 "tmp.zig:2:5: error: use of undeclared identifier 'b'",
3387 );
3155 });
33883156
3389 cases.add(
3390 "wrong number of arguments",
3157 cases.add("wrong number of arguments",
33913158 \\export fn a() void {
33923159 \\ b(1);
33933160 \\}
33943161 \\fn b(a: i32, b: i32, c: i32) void { }
3395 ,
3162 , &[_][]const u8{
33963163 "tmp.zig:2:6: error: expected 3 arguments, found 1",
3397 );
3164 });
33983165
3399 cases.add(
3400 "invalid type",
3166 cases.add("invalid type",
34013167 \\fn a() bogus {}
34023168 \\export fn entry() void { _ = a(); }
3403 ,
3169 , &[_][]const u8{
34043170 "tmp.zig:1:8: error: use of undeclared identifier 'bogus'",
3405 );
3171 });
34063172
3407 cases.add(
3408 "pointer to noreturn",
3173 cases.add("pointer to noreturn",
34093174 \\fn a() *noreturn {}
34103175 \\export fn entry() void { _ = a(); }
3411 ,
3176 , &[_][]const u8{
34123177 "tmp.zig:1:9: error: pointer to noreturn not allowed",
3413 );
3178 });
34143179
3415 cases.add(
3416 "unreachable code",
3180 cases.add("unreachable code",
34173181 \\export fn a() void {
34183182 \\ return;
34193183 \\ b();
34203184 \\}
34213185 \\
34223186 \\fn b() void {}
3423 ,
3187 , &[_][]const u8{
34243188 "tmp.zig:3:6: error: unreachable code",
3425 );
3189 });
34263190
3427 cases.add(
3428 "bad import",
3191 cases.add("bad import",
34293192 \\const bogus = @import("bogus-does-not-exist.zig",);
34303193 \\export fn entry() void { bogus.bogo(); }
3431 ,
3194 , &[_][]const u8{
34323195 "tmp.zig:1:15: error: unable to find 'bogus-does-not-exist.zig'",
3433 );
3196 });
34343197
3435 cases.add(
3436 "undeclared identifier",
3198 cases.add("undeclared identifier",
34373199 \\export fn a() void {
34383200 \\ return
34393201 \\ b +
34403202 \\ c;
34413203 \\}
3442 ,
3204 , &[_][]const u8{
34433205 "tmp.zig:3:5: error: use of undeclared identifier 'b'",
3444 );
3206 });
34453207
3446 cases.add(
3447 "parameter redeclaration",
3208 cases.add("parameter redeclaration",
34483209 \\fn f(a : i32, a : i32) void {
34493210 \\}
34503211 \\export fn entry() void { f(1, 2); }
3451 ,
3212 , &[_][]const u8{
34523213 "tmp.zig:1:15: error: redeclaration of variable 'a'",
3453 );
3214 });
34543215
3455 cases.add(
3456 "local variable redeclaration",
3216 cases.add("local variable redeclaration",
34573217 \\export fn f() void {
34583218 \\ const a : i32 = 0;
34593219 \\ const a = 0;
34603220 \\}
3461 ,
3221 , &[_][]const u8{
34623222 "tmp.zig:3:5: error: redeclaration of variable 'a'",
3463 );
3223 });
34643224
3465 cases.add(
3466 "local variable redeclares parameter",
3225 cases.add("local variable redeclares parameter",
34673226 \\fn f(a : i32) void {
34683227 \\ const a = 0;
34693228 \\}
34703229 \\export fn entry() void { f(1); }
3471 ,
3230 , &[_][]const u8{
34723231 "tmp.zig:2:5: error: redeclaration of variable 'a'",
3473 );
3232 });
34743233
3475 cases.add(
3476 "variable has wrong type",
3234 cases.add("variable has wrong type",
34773235 \\export fn f() i32 {
34783236 \\ const a = "a";
34793237 \\ return a;
34803238 \\}
3481 ,
3239 , &[_][]const u8{
34823240 "tmp.zig:3:12: error: expected type 'i32', found '*const [1:0]u8'",
3483 );
3241 });
34843242
3485 cases.add(
3486 "if condition is bool, not int",
3243 cases.add("if condition is bool, not int",
34873244 \\export fn f() void {
34883245 \\ if (0) {}
34893246 \\}
3490 ,
3247 , &[_][]const u8{
34913248 "tmp.zig:2:9: error: expected type 'bool', found 'comptime_int'",
3492 );
3249 });
34933250
3494 cases.add(
3495 "assign unreachable",
3251 cases.add("assign unreachable",
34963252 \\export fn f() void {
34973253 \\ const a = return;
34983254 \\}
3499 ,
3255 , &[_][]const u8{
35003256 "tmp.zig:2:5: error: unreachable code",
3501 );
3257 });
35023258
3503 cases.add(
3504 "unreachable variable",
3259 cases.add("unreachable variable",
35053260 \\export fn f() void {
35063261 \\ const a: noreturn = {};
35073262 \\}
3508 ,
3263 , &[_][]const u8{
35093264 "tmp.zig:2:25: error: expected type 'noreturn', found 'void'",
3510 );
3265 });
35113266
3512 cases.add(
3513 "unreachable parameter",
3267 cases.add("unreachable parameter",
35143268 \\fn f(a: noreturn) void {}
35153269 \\export fn entry() void { f(); }
3516 ,
3270 , &[_][]const u8{
35173271 "tmp.zig:1:9: error: parameter of type 'noreturn' not allowed",
3518 );
3272 });
35193273
3520 cases.add(
3521 "bad assignment target",
3274 cases.add("bad assignment target",
35223275 \\export fn f() void {
35233276 \\ 3 = 3;
35243277 \\}
3525 ,
3278 , &[_][]const u8{
35263279 "tmp.zig:2:9: error: cannot assign to constant",
3527 );
3280 });
35283281
3529 cases.add(
3530 "assign to constant variable",
3282 cases.add("assign to constant variable",
35313283 \\export fn f() void {
35323284 \\ const a = 3;
35333285 \\ a = 4;
35343286 \\}
3535 ,
3287 , &[_][]const u8{
35363288 "tmp.zig:3:9: error: cannot assign to constant",
3537 );
3289 });
35383290
3539 cases.add(
3540 "use of undeclared identifier",
3291 cases.add("use of undeclared identifier",
35413292 \\export fn f() void {
35423293 \\ b = 3;
35433294 \\}
3544 ,
3295 , &[_][]const u8{
35453296 "tmp.zig:2:5: error: use of undeclared identifier 'b'",
3546 );
3297 });
35473298
3548 cases.add(
3549 "const is a statement, not an expression",
3299 cases.add("const is a statement, not an expression",
35503300 \\export fn f() void {
35513301 \\ (const a = 0);
35523302 \\}
3553 ,
3303 , &[_][]const u8{
35543304 "tmp.zig:2:6: error: invalid token: 'const'",
3555 );
3305 });
35563306
3557 cases.add(
3558 "array access of undeclared identifier",
3307 cases.add("array access of undeclared identifier",
35593308 \\export fn f() void {
35603309 \\ i[i] = i[i];
35613310 \\}
3562 ,
3311 , &[_][]const u8{
35633312 "tmp.zig:2:5: error: use of undeclared identifier 'i'",
3564 );
3313 });
35653314
3566 cases.add(
3567 "array access of non array",
3315 cases.add("array access of non array",
35683316 \\export fn f() void {
35693317 \\ var bad : bool = undefined;
35703318 \\ bad[bad] = bad[bad];
......@@ -3573,13 +3321,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
35733321 \\ var bad : bool = undefined;
35743322 \\ _ = bad[bad];
35753323 \\}
3576 ,
3324 , &[_][]const u8{
35773325 "tmp.zig:3:8: error: array access of non-array type 'bool'",
35783326 "tmp.zig:7:12: error: array access of non-array type 'bool'",
3579 );
3327 });
35803328
3581 cases.add(
3582 "array access with non integer index",
3329 cases.add("array access with non integer index",
35833330 \\export fn f() void {
35843331 \\ var array = "aoeu";
35853332 \\ var bad = false;
......@@ -3590,24 +3337,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
35903337 \\ var bad = false;
35913338 \\ _ = array[bad];
35923339 \\}
3593 ,
3340 , &[_][]const u8{
35943341 "tmp.zig:4:11: error: expected type 'usize', found 'bool'",
35953342 "tmp.zig:9:15: error: expected type 'usize', found 'bool'",
3596 );
3343 });
35973344
3598 cases.add(
3599 "write to const global variable",
3345 cases.add("write to const global variable",
36003346 \\const x : i32 = 99;
36013347 \\fn f() void {
36023348 \\ x = 1;
36033349 \\}
36043350 \\export fn entry() void { f(); }
3605 ,
3351 , &[_][]const u8{
36063352 "tmp.zig:3:9: error: cannot assign to constant",
3607 );
3353 });
36083354
3609 cases.add(
3610 "missing else clause",
3355 cases.add("missing else clause",
36113356 \\fn f(b: bool) void {
36123357 \\ const x : i32 = if (b) h: { break :h 1; };
36133358 \\}
......@@ -3615,13 +3360,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
36153360 \\ const y = if (b) h: { break :h @as(i32, 1); };
36163361 \\}
36173362 \\export fn entry() void { f(true); g(true); }
3618 ,
3363 , &[_][]const u8{
36193364 "tmp.zig:2:21: error: expected type 'i32', found 'void'",
36203365 "tmp.zig:5:15: error: incompatible types: 'i32' and 'void'",
3621 );
3366 });
36223367
3623 cases.add(
3624 "invalid struct field",
3368 cases.add("invalid struct field",
36253369 \\const A = struct { x : i32, };
36263370 \\export fn f() void {
36273371 \\ var a : A = undefined;
......@@ -3632,38 +3376,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
36323376 \\ var a : A = undefined;
36333377 \\ const y = a.bar;
36343378 \\}
3635 ,
3379 , &[_][]const u8{
36363380 "tmp.zig:4:6: error: no member named 'foo' in struct 'A'",
36373381 "tmp.zig:9:16: error: no member named 'bar' in struct 'A'",
3638 );
3382 });
36393383
3640 cases.add(
3641 "redefinition of struct",
3384 cases.add("redefinition of struct",
36423385 \\const A = struct { x : i32, };
36433386 \\const A = struct { y : i32, };
3644 ,
3387 , &[_][]const u8{
36453388 "tmp.zig:2:1: error: redefinition of 'A'",
3646 );
3389 });
36473390
3648 cases.add(
3649 "redefinition of enums",
3391 cases.add("redefinition of enums",
36503392 \\const A = enum {};
36513393 \\const A = enum {};
3652 ,
3394 , &[_][]const u8{
36533395 "tmp.zig:2:1: error: redefinition of 'A'",
3654 );
3396 });
36553397
3656 cases.add(
3657 "redefinition of global variables",
3398 cases.add("redefinition of global variables",
36583399 \\var a : i32 = 1;
36593400 \\var a : i32 = 2;
3660 ,
3401 , &[_][]const u8{
36613402 "tmp.zig:2:1: error: redefinition of 'a'",
36623403 "tmp.zig:1:1: note: previous definition is here",
3663 );
3404 });
36643405
3665 cases.add(
3666 "duplicate field in struct value expression",
3406 cases.add("duplicate field in struct value expression",
36673407 \\const A = struct {
36683408 \\ x : i32,
36693409 \\ y : i32,
......@@ -3677,12 +3417,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
36773417 \\ .z = 4,
36783418 \\ };
36793419 \\}
3680 ,
3420 , &[_][]const u8{
36813421 "tmp.zig:11:9: error: duplicate field",
3682 );
3422 });
36833423
3684 cases.add(
3685 "missing field in struct value expression",
3424 cases.add("missing field in struct value expression",
36863425 \\const A = struct {
36873426 \\ x : i32,
36883427 \\ y : i32,
......@@ -3696,12 +3435,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
36963435 \\ .y = 2,
36973436 \\ };
36983437 \\}
3699 ,
3438 , &[_][]const u8{
37003439 "tmp.zig:9:17: error: missing field: 'x'",
3701 );
3440 });
37023441
3703 cases.add(
3704 "invalid field in struct value expression",
3442 cases.add("invalid field in struct value expression",
37053443 \\const A = struct {
37063444 \\ x : i32,
37073445 \\ y : i32,
......@@ -3714,86 +3452,77 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
37143452 \\ .foo = 42,
37153453 \\ };
37163454 \\}
3717 ,
3455 , &[_][]const u8{
37183456 "tmp.zig:10:9: error: no member named 'foo' in struct 'A'",
3719 );
3457 });
37203458
3721 cases.add(
3722 "invalid break expression",
3459 cases.add("invalid break expression",
37233460 \\export fn f() void {
37243461 \\ break;
37253462 \\}
3726 ,
3463 , &[_][]const u8{
37273464 "tmp.zig:2:5: error: break expression outside loop",
3728 );
3465 });
37293466
3730 cases.add(
3731 "invalid continue expression",
3467 cases.add("invalid continue expression",
37323468 \\export fn f() void {
37333469 \\ continue;
37343470 \\}
3735 ,
3471 , &[_][]const u8{
37363472 "tmp.zig:2:5: error: continue expression outside loop",
3737 );
3473 });
37383474
3739 cases.add(
3740 "invalid maybe type",
3475 cases.add("invalid maybe type",
37413476 \\export fn f() void {
37423477 \\ if (true) |x| { }
37433478 \\}
3744 ,
3479 , &[_][]const u8{
37453480 "tmp.zig:2:9: error: expected optional type, found 'bool'",
3746 );
3481 });
37473482
3748 cases.add(
3749 "cast unreachable",
3483 cases.add("cast unreachable",
37503484 \\fn f() i32 {
37513485 \\ return @as(i32, return 1);
37523486 \\}
37533487 \\export fn entry() void { _ = f(); }
3754 ,
3488 , &[_][]const u8{
37553489 "tmp.zig:2:12: error: unreachable code",
3756 );
3490 });
37573491
3758 cases.add(
3759 "invalid builtin fn",
3492 cases.add("invalid builtin fn",
37603493 \\fn f() @bogus(foo) {
37613494 \\}
37623495 \\export fn entry() void { _ = f(); }
3763 ,
3496 , &[_][]const u8{
37643497 "tmp.zig:1:8: error: invalid builtin function: 'bogus'",
3765 );
3498 });
37663499
3767 cases.add(
3768 "noalias on non pointer param",
3500 cases.add("noalias on non pointer param",
37693501 \\fn f(noalias x: i32) void {}
37703502 \\export fn entry() void { f(1234); }
3771 ,
3503 , &[_][]const u8{
37723504 "tmp.zig:1:6: error: noalias on non-pointer parameter",
3773 );
3505 });
37743506
3775 cases.add(
3776 "struct init syntax for array",
3507 cases.add("struct init syntax for array",
37773508 \\const foo = [3]u16{ .x = 1024 };
37783509 \\comptime {
37793510 \\ _ = foo;
37803511 \\}
3781 ,
3512 , &[_][]const u8{
37823513 "tmp.zig:1:21: error: type '[3]u16' does not support struct initialization syntax",
3783 );
3514 });
37843515
3785 cases.add(
3786 "type variables must be constant",
3516 cases.add("type variables must be constant",
37873517 \\var foo = u8;
37883518 \\export fn entry() foo {
37893519 \\ return 1;
37903520 \\}
3791 ,
3521 , &[_][]const u8{
37923522 "tmp.zig:1:1: error: variable of type 'type' must be constant",
3793 );
3523 });
37943524
3795 cases.add(
3796 "variables shadowing types",
3525 cases.add("variables shadowing types",
37973526 \\const Foo = struct {};
37983527 \\const Bar = struct {};
37993528 \\
......@@ -3804,15 +3533,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
38043533 \\export fn entry() void {
38053534 \\ f(1234);
38063535 \\}
3807 ,
3536 , &[_][]const u8{
38083537 "tmp.zig:4:6: error: redefinition of 'Foo'",
38093538 "tmp.zig:1:1: note: previous definition is here",
38103539 "tmp.zig:5:5: error: redefinition of 'Bar'",
38113540 "tmp.zig:2:1: note: previous definition is here",
3812 );
3541 });
38133542
3814 cases.add(
3815 "switch expression - missing enumeration prong",
3543 cases.add("switch expression - missing enumeration prong",
38163544 \\const Number = enum {
38173545 \\ One,
38183546 \\ Two,
......@@ -3828,12 +3556,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
38283556 \\}
38293557 \\
38303558 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
3831 ,
3559 , &[_][]const u8{
38323560 "tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch",
3833 );
3561 });
38343562
3835 cases.add(
3836 "switch expression - duplicate enumeration prong",
3563 cases.add("switch expression - duplicate enumeration prong",
38373564 \\const Number = enum {
38383565 \\ One,
38393566 \\ Two,
......@@ -3851,13 +3578,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
38513578 \\}
38523579 \\
38533580 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
3854 ,
3581 , &[_][]const u8{
38553582 "tmp.zig:13:15: error: duplicate switch value",
38563583 "tmp.zig:10:15: note: other value is here",
3857 );
3584 });
38583585
3859 cases.add(
3860 "switch expression - duplicate enumeration prong when else present",
3586 cases.add("switch expression - duplicate enumeration prong when else present",
38613587 \\const Number = enum {
38623588 \\ One,
38633589 \\ Two,
......@@ -3876,13 +3602,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
38763602 \\}
38773603 \\
38783604 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
3879 ,
3605 , &[_][]const u8{
38803606 "tmp.zig:13:15: error: duplicate switch value",
38813607 "tmp.zig:10:15: note: other value is here",
3882 );
3608 });
38833609
3884 cases.add(
3885 "switch expression - multiple else prongs",
3610 cases.add("switch expression - multiple else prongs",
38863611 \\fn f(x: u32) void {
38873612 \\ const value: bool = switch (x) {
38883613 \\ 1234 => false,
......@@ -3893,24 +3618,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
38933618 \\export fn entry() void {
38943619 \\ f(1234);
38953620 \\}
3896 ,
3621 , &[_][]const u8{
38973622 "tmp.zig:5:9: error: multiple else prongs in switch expression",
3898 );
3623 });
38993624
3900 cases.add(
3901 "switch expression - non exhaustive integer prongs",
3625 cases.add("switch expression - non exhaustive integer prongs",
39023626 \\fn foo(x: u8) void {
39033627 \\ switch (x) {
39043628 \\ 0 => {},
39053629 \\ }
39063630 \\}
39073631 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
3908 ,
3632 , &[_][]const u8{
39093633 "tmp.zig:2:5: error: switch must handle all possibilities",
3910 );
3634 });
39113635
3912 cases.add(
3913 "switch expression - duplicate or overlapping integer value",
3636 cases.add("switch expression - duplicate or overlapping integer value",
39143637 \\fn foo(x: u8) u8 {
39153638 \\ return switch (x) {
39163639 \\ 0 ... 100 => @as(u8, 0),
......@@ -3920,13 +3643,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
39203643 \\ };
39213644 \\}
39223645 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
3923 ,
3646 , &[_][]const u8{
39243647 "tmp.zig:6:9: error: duplicate switch value",
39253648 "tmp.zig:5:14: note: previous value is here",
3926 );
3649 });
39273650
3928 cases.add(
3929 "switch expression - switch on pointer type with no else",
3651 cases.add("switch expression - switch on pointer type with no else",
39303652 \\fn foo(x: *u8) void {
39313653 \\ switch (x) {
39323654 \\ &y => {},
......@@ -3934,82 +3656,74 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
39343656 \\}
39353657 \\const y: u8 = 100;
39363658 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
3937 ,
3659 , &[_][]const u8{
39383660 "tmp.zig:2:5: error: else prong required when switching on type '*u8'",
3939 );
3661 });
39403662
3941 cases.add(
3942 "global variable initializer must be constant expression",
3663 cases.add("global variable initializer must be constant expression",
39433664 \\extern fn foo() i32;
39443665 \\const x = foo();
39453666 \\export fn entry() i32 { return x; }
3946 ,
3667 , &[_][]const u8{
39473668 "tmp.zig:2:11: error: unable to evaluate constant expression",
3948 );
3669 });
39493670
3950 cases.add(
3951 "array concatenation with wrong type",
3671 cases.add("array concatenation with wrong type",
39523672 \\const src = "aoeu";
39533673 \\const derp: usize = 1234;
39543674 \\const a = derp ++ "foo";
39553675 \\
39563676 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
3957 ,
3677 , &[_][]const u8{
39583678 "tmp.zig:3:11: error: expected array, found 'usize'",
3959 );
3679 });
39603680
3961 cases.add(
3962 "non compile time array concatenation",
3681 cases.add("non compile time array concatenation",
39633682 \\fn f() []u8 {
39643683 \\ return s ++ "foo";
39653684 \\}
39663685 \\var s: [10]u8 = undefined;
39673686 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
3968 ,
3687 , &[_][]const u8{
39693688 "tmp.zig:2:12: error: unable to evaluate constant expression",
3970 );
3689 });
39713690
3972 cases.add(
3973 "@cImport with bogus include",
3691 cases.add("@cImport with bogus include",
39743692 \\const c = @cImport(@cInclude("bogus.h"));
39753693 \\export fn entry() usize { return @sizeOf(@typeOf(c.bogo)); }
3976 ,
3694 , &[_][]const u8{
39773695 "tmp.zig:1:11: error: C import failed",
39783696 ".h:1:10: note: 'bogus.h' file not found",
3979 );
3697 });
39803698
3981 cases.add(
3982 "address of number literal",
3699 cases.add("address of number literal",
39833700 \\const x = 3;
39843701 \\const y = &x;
39853702 \\fn foo() *const i32 { return y; }
39863703 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
3987 ,
3704 , &[_][]const u8{
39883705 "tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'",
3989 );
3706 });
39903707
3991 cases.add(
3992 "integer overflow error",
3708 cases.add("integer overflow error",
39933709 \\const x : u8 = 300;
39943710 \\export fn entry() usize { return @sizeOf(@typeOf(x)); }
3995 ,
3711 , &[_][]const u8{
39963712 "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'",
3997 );
3713 });
39983714
3999 cases.add(
4000 "invalid shift amount error",
3715 cases.add("invalid shift amount error",
40013716 \\const x : u8 = 2;
40023717 \\fn f() u16 {
40033718 \\ return x << 8;
40043719 \\}
40053720 \\export fn entry() u16 { return f(); }
4006 ,
3721 , &[_][]const u8{
40073722 "tmp.zig:3:14: error: RHS of shift is too large for LHS type",
40083723 "tmp.zig:3:17: note: value 8 cannot fit into type u3",
4009 );
3724 });
40103725
4011 cases.add(
4012 "missing function call param",
3726 cases.add("missing function call param",
40133727 \\const Foo = struct {
40143728 \\ a: i32,
40153729 \\ b: i32,
......@@ -4033,60 +3747,54 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
40333747 \\}
40343748 \\
40353749 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
4036 ,
3750 , &[_][]const u8{
40373751 "tmp.zig:20:34: error: expected 1 arguments, found 0",
4038 );
3752 });
40393753
4040 cases.add(
4041 "missing function name",
3754 cases.add("missing function name",
40423755 \\fn () void {}
40433756 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
4044 ,
3757 , &[_][]const u8{
40453758 "tmp.zig:1:1: error: missing function name",
4046 );
3759 });
40473760
4048 cases.add(
4049 "missing param name",
3761 cases.add("missing param name",
40503762 \\fn f(i32) void {}
40513763 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
4052 ,
3764 , &[_][]const u8{
40533765 "tmp.zig:1:6: error: missing parameter name",
4054 );
3766 });
40553767
4056 cases.add(
4057 "wrong function type",
3768 cases.add("wrong function type",
40583769 \\const fns = [_]fn() void { a, b, c };
40593770 \\fn a() i32 {return 0;}
40603771 \\fn b() i32 {return 1;}
40613772 \\fn c() i32 {return 2;}
40623773 \\export fn entry() usize { return @sizeOf(@typeOf(fns)); }
4063 ,
3774 , &[_][]const u8{
40643775 "tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'",
4065 );
3776 });
40663777
4067 cases.add(
4068 "extern function pointer mismatch",
3778 cases.add("extern function pointer mismatch",
40693779 \\const fns = [_](fn(i32)i32) { a, b, c };
40703780 \\pub fn a(x: i32) i32 {return x + 0;}
40713781 \\pub fn b(x: i32) i32 {return x + 1;}
40723782 \\export fn c(x: i32) i32 {return x + 2;}
40733783 \\
40743784 \\export fn entry() usize { return @sizeOf(@typeOf(fns)); }
4075 ,
3785 , &[_][]const u8{
40763786 "tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'extern fn(i32) i32'",
4077 );
3787 });
40783788
4079 cases.add(
4080 "colliding invalid top level functions",
3789 cases.add("colliding invalid top level functions",
40813790 \\fn func() bogus {}
40823791 \\fn func() bogus {}
40833792 \\export fn entry() usize { return @sizeOf(@typeOf(func)); }
4084 ,
3793 , &[_][]const u8{
40853794 "tmp.zig:2:1: error: redefinition of 'func'",
4086 );
3795 });
40873796
4088 cases.add(
4089 "non constant expression in array size",
3797 cases.add("non constant expression in array size",
40903798 \\const Foo = struct {
40913799 \\ y: [get()]u8,
40923800 \\};
......@@ -4094,25 +3802,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
40943802 \\fn get() usize { return global_var; }
40953803 \\
40963804 \\export fn entry() usize { return @sizeOf(@typeOf(Foo)); }
4097 ,
3805 , &[_][]const u8{
40983806 "tmp.zig:5:25: error: unable to evaluate constant expression",
40993807 "tmp.zig:2:12: note: referenced here",
4100 );
3808 });
41013809
4102 cases.add(
4103 "addition with non numbers",
3810 cases.add("addition with non numbers",
41043811 \\const Foo = struct {
41053812 \\ field: i32,
41063813 \\};
41073814 \\const x = Foo {.field = 1} + Foo {.field = 2};
41083815 \\
41093816 \\export fn entry() usize { return @sizeOf(@typeOf(x)); }
4110 ,
3817 , &[_][]const u8{
41113818 "tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'",
4112 );
3819 });
41133820
4114 cases.add(
4115 "division by zero",
3821 cases.add("division by zero",
41163822 \\const lit_int_x = 1 / 0;
41173823 \\const lit_float_x = 1.0 / 0.0;
41183824 \\const int_x = @as(u32, 1) / @as(u32, 0);
......@@ -4122,522 +3828,471 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
41223828 \\export fn entry2() usize { return @sizeOf(@typeOf(lit_float_x)); }
41233829 \\export fn entry3() usize { return @sizeOf(@typeOf(int_x)); }
41243830 \\export fn entry4() usize { return @sizeOf(@typeOf(float_x)); }
4125 ,
3831 , &[_][]const u8{
41263832 "tmp.zig:1:21: error: division by zero",
41273833 "tmp.zig:2:25: error: division by zero",
41283834 "tmp.zig:3:27: error: division by zero",
41293835 "tmp.zig:4:31: error: division by zero",
4130 );
3836 });
41313837
4132 cases.add(
4133 "normal string with newline",
3838 cases.add("normal string with newline",
41343839 \\const foo = "a
41353840 \\b";
41363841 \\
41373842 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
4138 ,
3843 , &[_][]const u8{
41393844 "tmp.zig:1:15: error: newline not allowed in string literal",
4140 );
3845 });
41413846
4142 cases.add(
4143 "invalid comparison for function pointers",
3847 cases.add("invalid comparison for function pointers",
41443848 \\fn foo() void {}
41453849 \\const invalid = foo > foo;
41463850 \\
41473851 \\export fn entry() usize { return @sizeOf(@typeOf(invalid)); }
4148 ,
3852 , &[_][]const u8{
41493853 "tmp.zig:2:21: error: operator not allowed for type 'fn() void'",
4150 );
3854 });
41513855
4152 cases.add(
4153 "generic function instance with non-constant expression",
3856 cases.add("generic function instance with non-constant expression",
41543857 \\fn foo(comptime x: i32, y: i32) i32 { return x + y; }
41553858 \\fn test1(a: i32, b: i32) i32 {
41563859 \\ return foo(a, b);
41573860 \\}
41583861 \\
41593862 \\export fn entry() usize { return @sizeOf(@typeOf(test1)); }
4160 ,
3863 , &[_][]const u8{
41613864 "tmp.zig:3:16: error: unable to evaluate constant expression",
4162 );
3865 });
41633866
4164 cases.add(
4165 "assign null to non-optional pointer",
3867 cases.add("assign null to non-optional pointer",
41663868 \\const a: *u8 = null;
41673869 \\
41683870 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
4169 ,
3871 , &[_][]const u8{
41703872 "tmp.zig:1:16: error: expected type '*u8', found '(null)'",
4171 );
3873 });
41723874
4173 cases.add(
4174 "indexing an array of size zero",
3875 cases.add("indexing an array of size zero",
41753876 \\const array = [_]u8{};
41763877 \\export fn foo() void {
41773878 \\ const pointer = &array[0];
41783879 \\}
4179 ,
3880 , &[_][]const u8{
41803881 "tmp.zig:3:27: error: index 0 outside array of size 0",
4181 );
3882 });
41823883
4183 cases.add(
4184 "compile time division by zero",
3884 cases.add("compile time division by zero",
41853885 \\const y = foo(0);
41863886 \\fn foo(x: u32) u32 {
41873887 \\ return 1 / x;
41883888 \\}
41893889 \\
41903890 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
4191 ,
3891 , &[_][]const u8{
41923892 "tmp.zig:3:14: error: division by zero",
41933893 "tmp.zig:1:14: note: referenced here",
4194 );
3894 });
41953895
4196 cases.add(
4197 "branch on undefined value",
3896 cases.add("branch on undefined value",
41983897 \\const x = if (undefined) true else false;
41993898 \\
42003899 \\export fn entry() usize { return @sizeOf(@typeOf(x)); }
4201 ,
3900 , &[_][]const u8{
42023901 "tmp.zig:1:15: error: use of undefined value here causes undefined behavior",
4203 );
3902 });
42043903
4205 cases.add(
4206 "div on undefined value",
3904 cases.add("div on undefined value",
42073905 \\comptime {
42083906 \\ var a: i64 = undefined;
42093907 \\ _ = a / a;
42103908 \\}
4211 ,
3909 , &[_][]const u8{
42123910 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
4213 );
3911 });
42143912
4215 cases.add(
4216 "div assign on undefined value",
3913 cases.add("div assign on undefined value",
42173914 \\comptime {
42183915 \\ var a: i64 = undefined;
42193916 \\ a /= a;
42203917 \\}
4221 ,
3918 , &[_][]const u8{
42223919 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
4223 );
3920 });
42243921
4225 cases.add(
4226 "mod on undefined value",
3922 cases.add("mod on undefined value",
42273923 \\comptime {
42283924 \\ var a: i64 = undefined;
42293925 \\ _ = a % a;
42303926 \\}
4231 ,
3927 , &[_][]const u8{
42323928 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
4233 );
3929 });
42343930
4235 cases.add(
4236 "mod assign on undefined value",
3931 cases.add("mod assign on undefined value",
42373932 \\comptime {
42383933 \\ var a: i64 = undefined;
42393934 \\ a %= a;
42403935 \\}
4241 ,
3936 , &[_][]const u8{
42423937 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
4243 );
3938 });
42443939
4245 cases.add(
4246 "add on undefined value",
3940 cases.add("add on undefined value",
42473941 \\comptime {
42483942 \\ var a: i64 = undefined;
42493943 \\ _ = a + a;
42503944 \\}
4251 ,
3945 , &[_][]const u8{
42523946 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
4253 );
3947 });
42543948
4255 cases.add(
4256 "add assign on undefined value",
3949 cases.add("add assign on undefined value",
42573950 \\comptime {
42583951 \\ var a: i64 = undefined;
42593952 \\ a += a;
42603953 \\}
4261 ,
3954 , &[_][]const u8{
42623955 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
4263 );
3956 });
42643957
4265 cases.add(
4266 "add wrap on undefined value",
3958 cases.add("add wrap on undefined value",
42673959 \\comptime {
42683960 \\ var a: i64 = undefined;
42693961 \\ _ = a +% a;
42703962 \\}
4271 ,
3963 , &[_][]const u8{
42723964 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
4273 );
3965 });
42743966
4275 cases.add(
4276 "add wrap assign on undefined value",
3967 cases.add("add wrap assign on undefined value",
42773968 \\comptime {
42783969 \\ var a: i64 = undefined;
42793970 \\ a +%= a;
42803971 \\}
4281 ,
3972 , &[_][]const u8{
42823973 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
4283 );
3974 });
42843975
4285 cases.add(
4286 "sub on undefined value",
3976 cases.add("sub on undefined value",
42873977 \\comptime {
42883978 \\ var a: i64 = undefined;
42893979 \\ _ = a - a;
42903980 \\}
4291 ,
3981 , &[_][]const u8{
42923982 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
4293 );
3983 });
42943984
4295 cases.add(
4296 "sub assign on undefined value",
3985 cases.add("sub assign on undefined value",
42973986 \\comptime {
42983987 \\ var a: i64 = undefined;
42993988 \\ a -= a;
43003989 \\}
4301 ,
3990 , &[_][]const u8{
43023991 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
4303 );
3992 });
43043993
4305 cases.add(
4306 "sub wrap on undefined value",
3994 cases.add("sub wrap on undefined value",
43073995 \\comptime {
43083996 \\ var a: i64 = undefined;
43093997 \\ _ = a -% a;
43103998 \\}
4311 ,
3999 , &[_][]const u8{
43124000 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
4313 );
4001 });
43144002
4315 cases.add(
4316 "sub wrap assign on undefined value",
4003 cases.add("sub wrap assign on undefined value",
43174004 \\comptime {
43184005 \\ var a: i64 = undefined;
43194006 \\ a -%= a;
43204007 \\}
4321 ,
4008 , &[_][]const u8{
43224009 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
4323 );
4010 });
43244011
4325 cases.add(
4326 "mult on undefined value",
4012 cases.add("mult on undefined value",
43274013 \\comptime {
43284014 \\ var a: i64 = undefined;
43294015 \\ _ = a * a;
43304016 \\}
4331 ,
4017 , &[_][]const u8{
43324018 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
4333 );
4019 });
43344020
4335 cases.add(
4336 "mult assign on undefined value",
4021 cases.add("mult assign on undefined value",
43374022 \\comptime {
43384023 \\ var a: i64 = undefined;
43394024 \\ a *= a;
43404025 \\}
4341 ,
4026 , &[_][]const u8{
43424027 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
4343 );
4028 });
43444029
4345 cases.add(
4346 "mult wrap on undefined value",
4030 cases.add("mult wrap on undefined value",
43474031 \\comptime {
43484032 \\ var a: i64 = undefined;
43494033 \\ _ = a *% a;
43504034 \\}
4351 ,
4035 , &[_][]const u8{
43524036 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
4353 );
4037 });
43544038
4355 cases.add(
4356 "mult wrap assign on undefined value",
4039 cases.add("mult wrap assign on undefined value",
43574040 \\comptime {
43584041 \\ var a: i64 = undefined;
43594042 \\ a *%= a;
43604043 \\}
4361 ,
4044 , &[_][]const u8{
43624045 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
4363 );
4046 });
43644047
4365 cases.add(
4366 "shift left on undefined value",
4048 cases.add("shift left on undefined value",
43674049 \\comptime {
43684050 \\ var a: i64 = undefined;
43694051 \\ _ = a << 2;
43704052 \\}
4371 ,
4053 , &[_][]const u8{
43724054 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
4373 );
4055 });
43744056
4375 cases.add(
4376 "shift left assign on undefined value",
4057 cases.add("shift left assign on undefined value",
43774058 \\comptime {
43784059 \\ var a: i64 = undefined;
43794060 \\ a <<= 2;
43804061 \\}
4381 ,
4062 , &[_][]const u8{
43824063 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
4383 );
4064 });
43844065
4385 cases.add(
4386 "shift right on undefined value",
4066 cases.add("shift right on undefined value",
43874067 \\comptime {
43884068 \\ var a: i64 = undefined;
43894069 \\ _ = a >> 2;
43904070 \\}
4391 ,
4071 , &[_][]const u8{
43924072 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
4393 );
4073 });
43944074
4395 cases.add(
4396 "shift left assign on undefined value",
4075 cases.add("shift left assign on undefined value",
43974076 \\comptime {
43984077 \\ var a: i64 = undefined;
43994078 \\ a >>= 2;
44004079 \\}
4401 ,
4080 , &[_][]const u8{
44024081 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
4403 );
4082 });
44044083
4405 cases.add(
4406 "bin and on undefined value",
4084 cases.add("bin and on undefined value",
44074085 \\comptime {
44084086 \\ var a: i64 = undefined;
44094087 \\ _ = a & a;
44104088 \\}
4411 ,
4089 , &[_][]const u8{
44124090 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
4413 );
4091 });
44144092
4415 cases.add(
4416 "bin and assign on undefined value",
4093 cases.add("bin and assign on undefined value",
44174094 \\comptime {
44184095 \\ var a: i64 = undefined;
44194096 \\ a &= a;
44204097 \\}
4421 ,
4098 , &[_][]const u8{
44224099 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
4423 );
4100 });
44244101
4425 cases.add(
4426 "bin or on undefined value",
4102 cases.add("bin or on undefined value",
44274103 \\comptime {
44284104 \\ var a: i64 = undefined;
44294105 \\ _ = a | a;
44304106 \\}
4431 ,
4107 , &[_][]const u8{
44324108 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
4433 );
4109 });
44344110
4435 cases.add(
4436 "bin or assign on undefined value",
4111 cases.add("bin or assign on undefined value",
44374112 \\comptime {
44384113 \\ var a: i64 = undefined;
44394114 \\ a |= a;
44404115 \\}
4441 ,
4116 , &[_][]const u8{
44424117 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
4443 );
4118 });
44444119
4445 cases.add(
4446 "bin xor on undefined value",
4120 cases.add("bin xor on undefined value",
44474121 \\comptime {
44484122 \\ var a: i64 = undefined;
44494123 \\ _ = a ^ a;
44504124 \\}
4451 ,
4125 , &[_][]const u8{
44524126 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
4453 );
4127 });
44544128
4455 cases.add(
4456 "bin xor assign on undefined value",
4129 cases.add("bin xor assign on undefined value",
44574130 \\comptime {
44584131 \\ var a: i64 = undefined;
44594132 \\ a ^= a;
44604133 \\}
4461 ,
4134 , &[_][]const u8{
44624135 "tmp.zig:3:5: error: use of undefined value here causes undefined behavior",
4463 );
4136 });
44644137
4465 cases.add(
4466 "equal on undefined value",
4138 cases.add("equal on undefined value",
44674139 \\comptime {
44684140 \\ var a: i64 = undefined;
44694141 \\ _ = a == a;
44704142 \\}
4471 ,
4143 , &[_][]const u8{
44724144 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
4473 );
4145 });
44744146
4475 cases.add(
4476 "not equal on undefined value",
4147 cases.add("not equal on undefined value",
44774148 \\comptime {
44784149 \\ var a: i64 = undefined;
44794150 \\ _ = a != a;
44804151 \\}
4481 ,
4152 , &[_][]const u8{
44824153 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
4483 );
4154 });
44844155
4485 cases.add(
4486 "greater than on undefined value",
4156 cases.add("greater than on undefined value",
44874157 \\comptime {
44884158 \\ var a: i64 = undefined;
44894159 \\ _ = a > a;
44904160 \\}
4491 ,
4161 , &[_][]const u8{
44924162 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
4493 );
4163 });
44944164
4495 cases.add(
4496 "greater than equal on undefined value",
4165 cases.add("greater than equal on undefined value",
44974166 \\comptime {
44984167 \\ var a: i64 = undefined;
44994168 \\ _ = a >= a;
45004169 \\}
4501 ,
4170 , &[_][]const u8{
45024171 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
4503 );
4172 });
45044173
4505 cases.add(
4506 "less than on undefined value",
4174 cases.add("less than on undefined value",
45074175 \\comptime {
45084176 \\ var a: i64 = undefined;
45094177 \\ _ = a < a;
45104178 \\}
4511 ,
4179 , &[_][]const u8{
45124180 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
4513 );
4181 });
45144182
4515 cases.add(
4516 "less than equal on undefined value",
4183 cases.add("less than equal on undefined value",
45174184 \\comptime {
45184185 \\ var a: i64 = undefined;
45194186 \\ _ = a <= a;
45204187 \\}
4521 ,
4188 , &[_][]const u8{
45224189 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
4523 );
4190 });
45244191
4525 cases.add(
4526 "and on undefined value",
4192 cases.add("and on undefined value",
45274193 \\comptime {
45284194 \\ var a: bool = undefined;
45294195 \\ _ = a and a;
45304196 \\}
4531 ,
4197 , &[_][]const u8{
45324198 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
4533 );
4199 });
45344200
4535 cases.add(
4536 "or on undefined value",
4201 cases.add("or on undefined value",
45374202 \\comptime {
45384203 \\ var a: bool = undefined;
45394204 \\ _ = a or a;
45404205 \\}
4541 ,
4206 , &[_][]const u8{
45424207 "tmp.zig:3:9: error: use of undefined value here causes undefined behavior",
4543 );
4208 });
45444209
4545 cases.add(
4546 "negate on undefined value",
4210 cases.add("negate on undefined value",
45474211 \\comptime {
45484212 \\ var a: i64 = undefined;
45494213 \\ _ = -a;
45504214 \\}
4551 ,
4215 , &[_][]const u8{
45524216 "tmp.zig:3:10: error: use of undefined value here causes undefined behavior",
4553 );
4217 });
45544218
4555 cases.add(
4556 "negate wrap on undefined value",
4219 cases.add("negate wrap on undefined value",
45574220 \\comptime {
45584221 \\ var a: i64 = undefined;
45594222 \\ _ = -%a;
45604223 \\}
4561 ,
4224 , &[_][]const u8{
45624225 "tmp.zig:3:11: error: use of undefined value here causes undefined behavior",
4563 );
4226 });
45644227
4565 cases.add(
4566 "bin not on undefined value",
4228 cases.add("bin not on undefined value",
45674229 \\comptime {
45684230 \\ var a: i64 = undefined;
45694231 \\ _ = ~a;
45704232 \\}
4571 ,
4233 , &[_][]const u8{
45724234 "tmp.zig:3:10: error: use of undefined value here causes undefined behavior",
4573 );
4235 });
45744236
4575 cases.add(
4576 "bool not on undefined value",
4237 cases.add("bool not on undefined value",
45774238 \\comptime {
45784239 \\ var a: bool = undefined;
45794240 \\ _ = !a;
45804241 \\}
4581 ,
4242 , &[_][]const u8{
45824243 "tmp.zig:3:10: error: use of undefined value here causes undefined behavior",
4583 );
4244 });
45844245
4585 cases.add(
4586 "orelse on undefined value",
4246 cases.add("orelse on undefined value",
45874247 \\comptime {
45884248 \\ var a: ?bool = undefined;
45894249 \\ _ = a orelse false;
45904250 \\}
4591 ,
4251 , &[_][]const u8{
45924252 "tmp.zig:3:11: error: use of undefined value here causes undefined behavior",
4593 );
4253 });
45944254
4595 cases.add(
4596 "catch on undefined value",
4255 cases.add("catch on undefined value",
45974256 \\comptime {
45984257 \\ var a: anyerror!bool = undefined;
45994258 \\ _ = a catch |err| false;
46004259 \\}
4601 ,
4260 , &[_][]const u8{
46024261 "tmp.zig:3:11: error: use of undefined value here causes undefined behavior",
4603 );
4262 });
46044263
4605 cases.add(
4606 "deref on undefined value",
4264 cases.add("deref on undefined value",
46074265 \\comptime {
46084266 \\ var a: *u8 = undefined;
46094267 \\ _ = a.*;
46104268 \\}
4611 ,
4269 , &[_][]const u8{
46124270 "tmp.zig:3:9: error: attempt to dereference undefined value",
4613 );
4271 });
46144272
4615 cases.add(
4616 "endless loop in function evaluation",
4273 cases.add("endless loop in function evaluation",
46174274 \\const seventh_fib_number = fibbonaci(7);
46184275 \\fn fibbonaci(x: i32) i32 {
46194276 \\ return fibbonaci(x - 1) + fibbonaci(x - 2);
46204277 \\}
46214278 \\
46224279 \\export fn entry() usize { return @sizeOf(@typeOf(seventh_fib_number)); }
4623 ,
4280 , &[_][]const u8{
46244281 "tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches",
46254282 "tmp.zig:1:37: note: referenced here",
46264283 "tmp.zig:6:50: note: referenced here",
4627 );
4284 });
46284285
4629 cases.add(
4630 "@embedFile with bogus file",
4286 cases.add("@embedFile with bogus file",
46314287 \\const resource = @embedFile("bogus.txt",);
46324288 \\
46334289 \\export fn entry() usize { return @sizeOf(@typeOf(resource)); }
4634 ,
4290 , &[_][]const u8{
46354291 "tmp.zig:1:29: error: unable to find '",
46364292 "bogus.txt'",
4637 );
4293 });
46384294
4639 cases.add(
4640 "non-const expression in struct literal outside function",
4295 cases.add("non-const expression in struct literal outside function",
46414296 \\const Foo = struct {
46424297 \\ x: i32,
46434298 \\};
......@@ -4645,12 +4300,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
46454300 \\extern fn get_it() i32;
46464301 \\
46474302 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
4648 ,
4303 , &[_][]const u8{
46494304 "tmp.zig:4:21: error: unable to evaluate constant expression",
4650 );
4305 });
46514306
4652 cases.add(
4653 "non-const expression function call with struct return value outside function",
4307 cases.add("non-const expression function call with struct return value outside function",
46544308 \\const Foo = struct {
46554309 \\ x: i32,
46564310 \\};
......@@ -4662,25 +4316,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
46624316 \\var global_side_effect = false;
46634317 \\
46644318 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
4665 ,
4319 , &[_][]const u8{
46664320 "tmp.zig:6:26: error: unable to evaluate constant expression",
46674321 "tmp.zig:4:17: note: referenced here",
4668 );
4322 });
46694323
4670 cases.add(
4671 "undeclared identifier error should mark fn as impure",
4324 cases.add("undeclared identifier error should mark fn as impure",
46724325 \\export fn foo() void {
46734326 \\ test_a_thing();
46744327 \\}
46754328 \\fn test_a_thing() void {
46764329 \\ bad_fn_call();
46774330 \\}
4678 ,
4331 , &[_][]const u8{
46794332 "tmp.zig:5:5: error: use of undeclared identifier 'bad_fn_call'",
4680 );
4333 });
46814334
4682 cases.add(
4683 "illegal comparison of types",
4335 cases.add("illegal comparison of types",
46844336 \\fn bad_eql_1(a: []u8, b: []u8) bool {
46854337 \\ return a == b;
46864338 \\}
......@@ -4694,13 +4346,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
46944346 \\
46954347 \\export fn entry1() usize { return @sizeOf(@typeOf(bad_eql_1)); }
46964348 \\export fn entry2() usize { return @sizeOf(@typeOf(bad_eql_2)); }
4697 ,
4349 , &[_][]const u8{
46984350 "tmp.zig:2:14: error: operator not allowed for type '[]u8'",
46994351 "tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'",
4700 );
4352 });
47014353
4702 cases.add(
4703 "non-const switch number literal",
4354 cases.add("non-const switch number literal",
47044355 \\export fn foo() void {
47054356 \\ const x = switch (bar()) {
47064357 \\ 1, 2 => 1,
......@@ -4711,109 +4362,100 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
47114362 \\fn bar() i32 {
47124363 \\ return 2;
47134364 \\}
4714 ,
4365 , &[_][]const u8{
47154366 "tmp.zig:5:17: error: cannot store runtime value in type 'comptime_int'",
4716 );
4367 });
47174368
4718 cases.add(
4719 "atomic orderings of cmpxchg - failure stricter than success",
4369 cases.add("atomic orderings of cmpxchg - failure stricter than success",
47204370 \\const AtomicOrder = @import("builtin").AtomicOrder;
47214371 \\export fn f() void {
47224372 \\ var x: i32 = 1234;
47234373 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {}
47244374 \\}
4725 ,
4375 , &[_][]const u8{
47264376 "tmp.zig:4:81: error: failure atomic ordering must be no stricter than success",
4727 );
4377 });
47284378
4729 cases.add(
4730 "atomic orderings of cmpxchg - success Monotonic or stricter",
4379 cases.add("atomic orderings of cmpxchg - success Monotonic or stricter",
47314380 \\const AtomicOrder = @import("builtin").AtomicOrder;
47324381 \\export fn f() void {
47334382 \\ var x: i32 = 1234;
47344383 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {}
47354384 \\}
4736 ,
4385 , &[_][]const u8{
47374386 "tmp.zig:4:58: error: success atomic ordering must be Monotonic or stricter",
4738 );
4387 });
47394388
4740 cases.add(
4741 "negation overflow in function evaluation",
4389 cases.add("negation overflow in function evaluation",
47424390 \\const y = neg(-128);
47434391 \\fn neg(x: i8) i8 {
47444392 \\ return -x;
47454393 \\}
47464394 \\
47474395 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
4748 ,
4396 , &[_][]const u8{
47494397 "tmp.zig:3:12: error: negation caused overflow",
47504398 "tmp.zig:1:14: note: referenced here",
4751 );
4399 });
47524400
4753 cases.add(
4754 "add overflow in function evaluation",
4401 cases.add("add overflow in function evaluation",
47554402 \\const y = add(65530, 10);
47564403 \\fn add(a: u16, b: u16) u16 {
47574404 \\ return a + b;
47584405 \\}
47594406 \\
47604407 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
4761 ,
4408 , &[_][]const u8{
47624409 "tmp.zig:3:14: error: operation caused overflow",
47634410 "tmp.zig:1:14: note: referenced here",
4764 );
4411 });
47654412
4766 cases.add(
4767 "sub overflow in function evaluation",
4413 cases.add("sub overflow in function evaluation",
47684414 \\const y = sub(10, 20);
47694415 \\fn sub(a: u16, b: u16) u16 {
47704416 \\ return a - b;
47714417 \\}
47724418 \\
47734419 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
4774 ,
4420 , &[_][]const u8{
47754421 "tmp.zig:3:14: error: operation caused overflow",
47764422 "tmp.zig:1:14: note: referenced here",
4777 );
4423 });
47784424
4779 cases.add(
4780 "mul overflow in function evaluation",
4425 cases.add("mul overflow in function evaluation",
47814426 \\const y = mul(300, 6000);
47824427 \\fn mul(a: u16, b: u16) u16 {
47834428 \\ return a * b;
47844429 \\}
47854430 \\
47864431 \\export fn entry() usize { return @sizeOf(@typeOf(y)); }
4787 ,
4432 , &[_][]const u8{
47884433 "tmp.zig:3:14: error: operation caused overflow",
47894434 "tmp.zig:1:14: note: referenced here",
4790 );
4435 });
47914436
4792 cases.add(
4793 "truncate sign mismatch",
4437 cases.add("truncate sign mismatch",
47944438 \\fn f() i8 {
47954439 \\ var x: u32 = 10;
47964440 \\ return @truncate(i8, x);
47974441 \\}
47984442 \\
47994443 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
4800 ,
4444 , &[_][]const u8{
48014445 "tmp.zig:3:26: error: expected signed integer type, found 'u32'",
4802 );
4446 });
48034447
4804 cases.add(
4805 "try in function with non error return type",
4448 cases.add("try in function with non error return type",
48064449 \\export fn f() void {
48074450 \\ try something();
48084451 \\}
48094452 \\fn something() anyerror!void { }
4810 ,
4453 , &[_][]const u8{
48114454 "tmp.zig:2:5: error: expected type 'void', found 'anyerror'",
48124455 "tmp.zig:1:15: note: return type declared here",
4813 );
4456 });
48144457
4815 cases.add(
4816 "invalid pointer for var type",
4458 cases.add("invalid pointer for var type",
48174459 \\extern fn ext() usize;
48184460 \\var bytes: [ext()]u8 = undefined;
48194461 \\export fn f() void {
......@@ -4821,43 +4463,39 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
48214463 \\ b.* = @as(u8, i);
48224464 \\ }
48234465 \\}
4824 ,
4466 , &[_][]const u8{
48254467 "tmp.zig:2:13: error: unable to evaluate constant expression",
4826 );
4468 });
48274469
4828 cases.add(
4829 "export function with comptime parameter",
4470 cases.add("export function with comptime parameter",
48304471 \\export fn foo(comptime x: i32, y: i32) i32{
48314472 \\ return x + y;
48324473 \\}
4833 ,
4474 , &[_][]const u8{
48344475 "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'",
4835 );
4476 });
48364477
4837 cases.add(
4838 "extern function with comptime parameter",
4478 cases.add("extern function with comptime parameter",
48394479 \\extern fn foo(comptime x: i32, y: i32) i32;
48404480 \\fn f() i32 {
48414481 \\ return foo(1, 2);
48424482 \\}
48434483 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
4844 ,
4484 , &[_][]const u8{
48454485 "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'",
4846 );
4486 });
48474487
4848 cases.add(
4849 "convert fixed size array to slice with invalid size",
4488 cases.add("convert fixed size array to slice with invalid size",
48504489 \\export fn f() void {
48514490 \\ var array: [5]u8 = undefined;
48524491 \\ var foo = @bytesToSlice(u32, &array)[0];
48534492 \\}
4854 ,
4493 , &[_][]const u8{
48554494 "tmp.zig:3:15: error: unable to convert [5]u8 to []align(1) u32: size mismatch",
48564495 "tmp.zig:3:29: note: u32 has size 4; remaining bytes: 1",
4857 );
4496 });
48584497
4859 cases.add(
4860 "non-pure function returns type",
4498 cases.add("non-pure function returns type",
48614499 \\var a: u32 = 0;
48624500 \\pub fn List(comptime T: type) type {
48634501 \\ a += 1;
......@@ -4876,24 +4514,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
48764514 \\ var list: List(i32) = undefined;
48774515 \\ list.length = 10;
48784516 \\}
4879 ,
4517 , &[_][]const u8{
48804518 "tmp.zig:3:7: error: unable to evaluate constant expression",
48814519 "tmp.zig:16:19: note: referenced here",
4882 );
4520 });
48834521
4884 cases.add(
4885 "bogus method call on slice",
4522 cases.add("bogus method call on slice",
48864523 \\var self = "aoeu";
48874524 \\fn f(m: []const u8) void {
48884525 \\ m.copy(u8, self[0..], m);
48894526 \\}
48904527 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
4891 ,
4528 , &[_][]const u8{
48924529 "tmp.zig:3:6: error: no member named 'copy' in '[]const u8'",
4893 );
4530 });
48944531
4895 cases.add(
4896 "wrong number of arguments for method fn call",
4532 cases.add("wrong number of arguments for method fn call",
48974533 \\const Foo = struct {
48984534 \\ fn method(self: *const Foo, a: i32) void {}
48994535 \\};
......@@ -4902,39 +4538,35 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
49024538 \\ foo.method(1, 2);
49034539 \\}
49044540 \\export fn entry() usize { return @sizeOf(@typeOf(f)); }
4905 ,
4541 , &[_][]const u8{
49064542 "tmp.zig:6:15: error: expected 2 arguments, found 3",
4907 );
4543 });
49084544
4909 cases.add(
4910 "assign through constant pointer",
4545 cases.add("assign through constant pointer",
49114546 \\export fn f() void {
49124547 \\ var cstr = "Hat";
49134548 \\ cstr[0] = 'W';
49144549 \\}
4915 ,
4550 , &[_][]const u8{
49164551 "tmp.zig:3:13: error: cannot assign to constant",
4917 );
4552 });
49184553
4919 cases.add(
4920 "assign through constant slice",
4554 cases.add("assign through constant slice",
49214555 \\export fn f() void {
49224556 \\ var cstr: []const u8 = "Hat";
49234557 \\ cstr[0] = 'W';
49244558 \\}
4925 ,
4559 , &[_][]const u8{
49264560 "tmp.zig:3:13: error: cannot assign to constant",
4927 );
4561 });
49284562
4929 cases.add(
4930 "main function with bogus args type",
4563 cases.add("main function with bogus args type",
49314564 \\pub fn main(args: [][]bogus) !void {}
4932 ,
4565 , &[_][]const u8{
49334566 "tmp.zig:1:23: error: use of undeclared identifier 'bogus'",
4934 );
4567 });
49354568
4936 cases.add(
4937 "misspelled type with pointer only reference",
4569 cases.add("misspelled type with pointer only reference",
49384570 \\const JasonHM = u8;
49394571 \\const JasonList = *JsonNode;
49404572 \\
......@@ -4965,12 +4597,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
49654597 \\}
49664598 \\
49674599 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
4968 ,
4600 , &[_][]const u8{
49694601 "tmp.zig:5:16: error: use of undeclared identifier 'JsonList'",
4970 );
4602 });
49714603
4972 cases.add(
4973 "method call with first arg type primitive",
4604 cases.add("method call with first arg type primitive",
49744605 \\const Foo = struct {
49754606 \\ x: i32,
49764607 \\
......@@ -4986,12 +4617,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
49864617 \\
49874618 \\ derp.init();
49884619 \\}
4989 ,
4620 , &[_][]const u8{
49904621 "tmp.zig:14:5: error: expected type 'i32', found 'Foo'",
4991 );
4622 });
49924623
4993 cases.add(
4994 "method call with first arg type wrong container",
4624 cases.add("method call with first arg type wrong container",
49954625 \\pub const List = struct {
49964626 \\ len: usize,
49974627 \\ allocator: *Allocator,
......@@ -5016,33 +4646,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
50164646 \\ var x = List.init(&global_allocator);
50174647 \\ x.init();
50184648 \\}
5019 ,
4649 , &[_][]const u8{
50204650 "tmp.zig:23:5: error: expected type '*Allocator', found '*List'",
5021 );
4651 });
50224652
5023 cases.add(
5024 "binary not on number literal",
4653 cases.add("binary not on number literal",
50254654 \\const TINY_QUANTUM_SHIFT = 4;
50264655 \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT;
50274656 \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1);
50284657 \\
50294658 \\export fn entry() usize { return @sizeOf(@typeOf(block_aligned_stuff)); }
5030 ,
4659 , &[_][]const u8{
50314660 "tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'",
5032 );
4661 });
50334662
50344663 cases.addCase(x: {
5035 const tc = cases.create(
5036 "multiple files with private function error",
4664 const tc = cases.create("multiple files with private function error",
50374665 \\const foo = @import("foo.zig",);
50384666 \\
50394667 \\export fn callPrivFunction() void {
50404668 \\ foo.privateFunction();
50414669 \\}
5042 ,
4670 , &[_][]const u8{
50434671 "tmp.zig:4:8: error: 'privateFunction' is private",
50444672 "foo.zig:1:1: note: declared here",
5045 );
4673 });
50464674
50474675 tc.addSourceFile("foo.zig",
50484676 \\fn privateFunction() void { }
......@@ -5051,18 +4679,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
50514679 break :x tc;
50524680 });
50534681
5054 cases.add(
5055 "container init with non-type",
4682 cases.add("container init with non-type",
50564683 \\const zero: i32 = 0;
50574684 \\const a = zero{1};
50584685 \\
50594686 \\export fn entry() usize { return @sizeOf(@typeOf(a)); }
5060 ,
4687 , &[_][]const u8{
50614688 "tmp.zig:2:11: error: expected type 'type', found 'i32'",
5062 );
4689 });
50634690
5064 cases.add(
5065 "assign to constant field",
4691 cases.add("assign to constant field",
50664692 \\const Foo = struct {
50674693 \\ field: i32,
50684694 \\};
......@@ -5070,12 +4696,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
50704696 \\ const f = Foo {.field = 1234,};
50714697 \\ f.field = 0;
50724698 \\}
5073 ,
4699 , &[_][]const u8{
50744700 "tmp.zig:6:15: error: cannot assign to constant",
5075 );
4701 });
50764702
5077 cases.add(
5078 "return from defer expression",
4703 cases.add("return from defer expression",
50794704 \\pub fn testTrickyDefer() !void {
50804705 \\ defer canFail() catch {};
50814706 \\
......@@ -5091,72 +4716,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
50914716 \\}
50924717 \\
50934718 \\export fn entry() usize { return @sizeOf(@typeOf(testTrickyDefer)); }
5094 ,
4719 , &[_][]const u8{
50954720 "tmp.zig:4:11: error: cannot return from defer expression",
5096 );
5097
5098 cases.add(
5099 "attempt to access var args out of bounds",
5100 \\fn add(args: ...) i32 {
5101 \\ return args[0] + args[1];
5102 \\}
5103 \\
5104 \\fn foo() i32 {
5105 \\ return add(@as(i32, 1234));
5106 \\}
5107 \\
5108 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
5109 ,
5110 "tmp.zig:2:26: error: index 1 outside argument list of size 1",
5111 "tmp.zig:6:15: note: called from here",
5112 );
5113
5114 cases.add(
5115 "pass integer literal to var args",
5116 \\fn add(args: ...) i32 {
5117 \\ var sum = @as(i32, 0);
5118 \\ {comptime var i: usize = 0; inline while (i < args.len) : (i += 1) {
5119 \\ sum += args[i];
5120 \\ }}
5121 \\ return sum;
5122 \\}
5123 \\
5124 \\fn bar() i32 {
5125 \\ return add(1, 2, 3, 4);
5126 \\}
5127 \\
5128 \\export fn entry() usize { return @sizeOf(@typeOf(bar)); }
5129 ,
5130 "tmp.zig:10:16: error: compiler bug: integer and float literals in var args function must be casted",
5131 );
4721 });
51324722
5133 cases.add(
5134 "assign too big number to u16",
4723 cases.add("assign too big number to u16",
51354724 \\export fn foo() void {
51364725 \\ var vga_mem: u16 = 0xB8000;
51374726 \\}
5138 ,
4727 , &[_][]const u8{
51394728 "tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'",
5140 );
4729 });
51414730
5142 cases.add(
5143 "global variable alignment non power of 2",
4731 cases.add("global variable alignment non power of 2",
51444732 \\const some_data: [100]u8 align(3) = undefined;
51454733 \\export fn entry() usize { return @sizeOf(@typeOf(some_data)); }
5146 ,
4734 , &[_][]const u8{
51474735 "tmp.zig:1:32: error: alignment value 3 is not a power of 2",
5148 );
4736 });
51494737
5150 cases.add(
5151 "function alignment non power of 2",
4738 cases.add("function alignment non power of 2",
51524739 \\extern fn foo() align(3) void;
51534740 \\export fn entry() void { return foo(); }
5154 ,
4741 , &[_][]const u8{
51554742 "tmp.zig:1:23: error: alignment value 3 is not a power of 2",
5156 );
4743 });
51574744
5158 cases.add(
5159 "compile log",
4745 cases.add("compile log",
51604746 \\export fn foo() void {
51614747 \\ comptime bar(12, "hi",);
51624748 \\}
......@@ -5165,14 +4751,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
51654751 \\ @compileLog("a", a, "b", b);
51664752 \\ @compileLog("end",);
51674753 \\}
5168 ,
4754 , &[_][]const u8{
51694755 "tmp.zig:5:5: error: found compile log statement",
51704756 "tmp.zig:6:5: error: found compile log statement",
51714757 "tmp.zig:7:5: error: found compile log statement",
5172 );
4758 });
51734759
5174 cases.add(
5175 "casting bit offset pointer to regular pointer",
4760 cases.add("casting bit offset pointer to regular pointer",
51764761 \\const BitField = packed struct {
51774762 \\ a: u3,
51784763 \\ b: u3,
......@@ -5188,12 +4773,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
51884773 \\}
51894774 \\
51904775 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
5191 ,
4776 , &[_][]const u8{
51924777 "tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'",
5193 );
4778 });
51944779
5195 cases.add(
5196 "referring to a struct that is invalid",
4780 cases.add("referring to a struct that is invalid",
51974781 \\const UsbDeviceRequest = struct {
51984782 \\ Type: u8,
51994783 \\};
......@@ -5205,13 +4789,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
52054789 \\fn assert(ok: bool) void {
52064790 \\ if (!ok) unreachable;
52074791 \\}
5208 ,
4792 , &[_][]const u8{
52094793 "tmp.zig:10:14: error: unable to evaluate constant expression",
52104794 "tmp.zig:6:20: note: referenced here",
5211 );
4795 });
52124796
5213 cases.add(
5214 "control flow uses comptime var at runtime",
4797 cases.add("control flow uses comptime var at runtime",
52154798 \\export fn foo() void {
52164799 \\ comptime var i = 0;
52174800 \\ while (i < 5) : (i += 1) {
......@@ -5220,79 +4803,71 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
52204803 \\}
52214804 \\
52224805 \\fn bar() void { }
5223 ,
4806 , &[_][]const u8{
52244807 "tmp.zig:3:5: error: control flow attempts to use compile-time variable at runtime",
52254808 "tmp.zig:3:24: note: compile-time variable assigned here",
5226 );
4809 });
52274810
5228 cases.add(
5229 "ignored return value",
4811 cases.add("ignored return value",
52304812 \\export fn foo() void {
52314813 \\ bar();
52324814 \\}
52334815 \\fn bar() i32 { return 0; }
5234 ,
4816 , &[_][]const u8{
52354817 "tmp.zig:2:8: error: expression value is ignored",
5236 );
4818 });
52374819
5238 cases.add(
5239 "ignored assert-err-ok return value",
4820 cases.add("ignored assert-err-ok return value",
52404821 \\export fn foo() void {
52414822 \\ bar() catch unreachable;
52424823 \\}
52434824 \\fn bar() anyerror!i32 { return 0; }
5244 ,
4825 , &[_][]const u8{
52454826 "tmp.zig:2:11: error: expression value is ignored",
5246 );
4827 });
52474828
5248 cases.add(
5249 "ignored statement value",
4829 cases.add("ignored statement value",
52504830 \\export fn foo() void {
52514831 \\ 1;
52524832 \\}
5253 ,
4833 , &[_][]const u8{
52544834 "tmp.zig:2:5: error: expression value is ignored",
5255 );
4835 });
52564836
5257 cases.add(
5258 "ignored comptime statement value",
4837 cases.add("ignored comptime statement value",
52594838 \\export fn foo() void {
52604839 \\ comptime {1;}
52614840 \\}
5262 ,
4841 , &[_][]const u8{
52634842 "tmp.zig:2:15: error: expression value is ignored",
5264 );
4843 });
52654844
5266 cases.add(
5267 "ignored comptime value",
4845 cases.add("ignored comptime value",
52684846 \\export fn foo() void {
52694847 \\ comptime 1;
52704848 \\}
5271 ,
4849 , &[_][]const u8{
52724850 "tmp.zig:2:5: error: expression value is ignored",
5273 );
4851 });
52744852
5275 cases.add(
5276 "ignored defered statement value",
4853 cases.add("ignored defered statement value",
52774854 \\export fn foo() void {
52784855 \\ defer {1;}
52794856 \\}
5280 ,
4857 , &[_][]const u8{
52814858 "tmp.zig:2:12: error: expression value is ignored",
5282 );
4859 });
52834860
5284 cases.add(
5285 "ignored defered function call",
4861 cases.add("ignored defered function call",
52864862 \\export fn foo() void {
52874863 \\ defer bar();
52884864 \\}
52894865 \\fn bar() anyerror!i32 { return 0; }
5290 ,
4866 , &[_][]const u8{
52914867 "tmp.zig:2:14: error: expression value is ignored",
5292 );
4868 });
52934869
5294 cases.add(
5295 "dereference an array",
4870 cases.add("dereference an array",
52964871 \\var s_buffer: [10]u8 = undefined;
52974872 \\pub fn pass(in: []u8) []u8 {
52984873 \\ var out = &s_buffer;
......@@ -5301,12 +4876,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
53014876 \\}
53024877 \\
53034878 \\export fn entry() usize { return @sizeOf(@typeOf(pass)); }
5304 ,
4879 , &[_][]const u8{
53054880 "tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'",
5306 );
4881 });
53074882
5308 cases.add(
5309 "pass const ptr to mutable ptr fn",
4883 cases.add("pass const ptr to mutable ptr fn",
53104884 \\fn foo() bool {
53114885 \\ const a = @as([]const u8, "a",);
53124886 \\ const b = &a;
......@@ -5317,22 +4891,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
53174891 \\}
53184892 \\
53194893 \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
5320 ,
4894 , &[_][]const u8{
53214895 "tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'",
5322 );
4896 });
53234897
53244898 cases.addCase(x: {
5325 const tc = cases.create(
5326 "export collision",
4899 const tc = cases.create("export collision",
53274900 \\const foo = @import("foo.zig",);
53284901 \\
53294902 \\export fn bar() usize {
53304903 \\ return foo.baz;
53314904 \\}
5332 ,
4905 , &[_][]const u8{
53334906 "foo.zig:1:1: error: exported symbol collision: 'bar'",
53344907 "tmp.zig:3:1: note: other symbol here",
5335 );
4908 });
53364909
53374910 tc.addSourceFile("foo.zig",
53384911 \\export fn bar() void {}
......@@ -5342,28 +4915,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
53424915 break :x tc;
53434916 });
53444917
5345 cases.add(
5346 "implicit cast from array to mutable slice",
4918 cases.add("implicit cast from array to mutable slice",
53474919 \\var global_array: [10]i32 = undefined;
53484920 \\fn foo(param: []i32) void {}
53494921 \\export fn entry() void {
53504922 \\ foo(global_array);
53514923 \\}
5352 ,
4924 , &[_][]const u8{
53534925 "tmp.zig:4:9: error: expected type '[]i32', found '[10]i32'",
5354 );
4926 });
53554927
5356 cases.add(
5357 "ptrcast to non-pointer",
4928 cases.add("ptrcast to non-pointer",
53584929 \\export fn entry(a: *i32) usize {
53594930 \\ return @ptrCast(usize, a);
53604931 \\}
5361 ,
4932 , &[_][]const u8{
53624933 "tmp.zig:2:21: error: expected pointer, found 'usize'",
5363 );
4934 });
53644935
5365 cases.add(
5366 "asm at compile time",
4936 cases.add("asm at compile time",
53674937 \\comptime {
53684938 \\ doSomeAsm();
53694939 \\}
......@@ -5375,66 +4945,60 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
53754945 \\ \\.set aoeu, derp;
53764946 \\ );
53774947 \\}
5378 ,
4948 , &[_][]const u8{
53794949 "tmp.zig:6:5: error: unable to evaluate constant expression",
5380 );
4950 });
53814951
5382 cases.add(
5383 "invalid member of builtin enum",
4952 cases.add("invalid member of builtin enum",
53844953 \\const builtin = @import("builtin",);
53854954 \\export fn entry() void {
53864955 \\ const foo = builtin.Arch.x86;
53874956 \\}
5388 ,
4957 , &[_][]const u8{
53894958 "tmp.zig:3:29: error: container 'std.target.Arch' has no member called 'x86'",
5390 );
4959 });
53914960
5392 cases.add(
5393 "int to ptr of 0 bits",
4961 cases.add("int to ptr of 0 bits",
53944962 \\export fn foo() void {
53954963 \\ var x: usize = 0x1000;
53964964 \\ var y: *void = @intToPtr(*void, x);
53974965 \\}
5398 ,
4966 , &[_][]const u8{
53994967 "tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information",
5400 );
4968 });
54014969
5402 cases.add(
5403 "@fieldParentPtr - non struct",
4970 cases.add("@fieldParentPtr - non struct",
54044971 \\const Foo = i32;
54054972 \\export fn foo(a: *i32) *Foo {
54064973 \\ return @fieldParentPtr(Foo, "a", a);
54074974 \\}
5408 ,
4975 , &[_][]const u8{
54094976 "tmp.zig:3:28: error: expected struct type, found 'i32'",
5410 );
4977 });
54114978
5412 cases.add(
5413 "@fieldParentPtr - bad field name",
4979 cases.add("@fieldParentPtr - bad field name",
54144980 \\const Foo = extern struct {
54154981 \\ derp: i32,
54164982 \\};
54174983 \\export fn foo(a: *i32) *Foo {
54184984 \\ return @fieldParentPtr(Foo, "a", a);
54194985 \\}
5420 ,
4986 , &[_][]const u8{
54214987 "tmp.zig:5:33: error: struct 'Foo' has no field 'a'",
5422 );
4988 });
54234989
5424 cases.add(
5425 "@fieldParentPtr - field pointer is not pointer",
4990 cases.add("@fieldParentPtr - field pointer is not pointer",
54264991 \\const Foo = extern struct {
54274992 \\ a: i32,
54284993 \\};
54294994 \\export fn foo(a: i32) *Foo {
54304995 \\ return @fieldParentPtr(Foo, "a", a);
54314996 \\}
5432 ,
4997 , &[_][]const u8{
54334998 "tmp.zig:5:38: error: expected pointer, found 'i32'",
5434 );
4999 });
54355000
5436 cases.add(
5437 "@fieldParentPtr - comptime field ptr not based on struct",
5001 cases.add("@fieldParentPtr - comptime field ptr not based on struct",
54385002 \\const Foo = struct {
54395003 \\ a: i32,
54405004 \\ b: i32,
......@@ -5445,12 +5009,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
54455009 \\ const field_ptr = @intToPtr(*i32, 0x1234);
54465010 \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr);
54475011 \\}
5448 ,
5012 , &[_][]const u8{
54495013 "tmp.zig:9:55: error: pointer value not based on parent struct",
5450 );
5014 });
54515015
5452 cases.add(
5453 "@fieldParentPtr - comptime wrong field index",
5016 cases.add("@fieldParentPtr - comptime wrong field index",
54545017 \\const Foo = struct {
54555018 \\ a: i32,
54565019 \\ b: i32,
......@@ -5460,80 +5023,72 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
54605023 \\comptime {
54615024 \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a);
54625025 \\}
5463 ,
5026 , &[_][]const u8{
54645027 "tmp.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo'",
5465 );
5028 });
54665029
5467 cases.add(
5468 "@byteOffsetOf - non struct",
5030 cases.add("@byteOffsetOf - non struct",
54695031 \\const Foo = i32;
54705032 \\export fn foo() usize {
54715033 \\ return @byteOffsetOf(Foo, "a",);
54725034 \\}
5473 ,
5035 , &[_][]const u8{
54745036 "tmp.zig:3:26: error: expected struct type, found 'i32'",
5475 );
5037 });
54765038
5477 cases.add(
5478 "@byteOffsetOf - bad field name",
5039 cases.add("@byteOffsetOf - bad field name",
54795040 \\const Foo = struct {
54805041 \\ derp: i32,
54815042 \\};
54825043 \\export fn foo() usize {
54835044 \\ return @byteOffsetOf(Foo, "a",);
54845045 \\}
5485 ,
5046 , &[_][]const u8{
54865047 "tmp.zig:5:31: error: struct 'Foo' has no field 'a'",
5487 );
5048 });
54885049
5489 cases.addExe(
5490 "missing main fn in executable",
5050 cases.addExe("missing main fn in executable",
54915051 \\
5492 ,
5052 , &[_][]const u8{
54935053 "error: root source file has no member called 'main'",
5494 );
5054 });
54955055
5496 cases.addExe(
5497 "private main fn",
5056 cases.addExe("private main fn",
54985057 \\fn main() void {}
5499 ,
5058 , &[_][]const u8{
55005059 "error: 'main' is private",
55015060 "tmp.zig:1:1: note: declared here",
5502 );
5061 });
55035062
5504 cases.add(
5505 "setting a section on a local variable",
5063 cases.add("setting a section on a local variable",
55065064 \\export fn entry() i32 {
55075065 \\ var foo: i32 linksection(".text2") = 1234;
55085066 \\ return foo;
55095067 \\}
5510 ,
5068 , &[_][]const u8{
55115069 "tmp.zig:2:30: error: cannot set section of local variable 'foo'",
5512 );
5070 });
55135071
5514 cases.add(
5515 "returning address of local variable - simple",
5072 cases.add("returning address of local variable - simple",
55165073 \\export fn foo() *i32 {
55175074 \\ var a: i32 = undefined;
55185075 \\ return &a;
55195076 \\}
5520 ,
5077 , &[_][]const u8{
55215078 "tmp.zig:3:13: error: function returns address of local variable",
5522 );
5079 });
55235080
5524 cases.add(
5525 "returning address of local variable - phi",
5081 cases.add("returning address of local variable - phi",
55265082 \\export fn foo(c: bool) *i32 {
55275083 \\ var a: i32 = undefined;
55285084 \\ var b: i32 = undefined;
55295085 \\ return if (c) &a else &b;
55305086 \\}
5531 ,
5087 , &[_][]const u8{
55325088 "tmp.zig:4:12: error: function returns address of local variable",
5533 );
5089 });
55345090
5535 cases.add(
5536 "inner struct member shadowing outer struct member",
5091 cases.add("inner struct member shadowing outer struct member",
55375092 \\fn A() type {
55385093 \\ return struct {
55395094 \\ b: B(),
......@@ -5553,73 +5108,66 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
55535108 \\fn assert(ok: bool) void {
55545109 \\ if (!ok) unreachable;
55555110 \\}
5556 ,
5111 , &[_][]const u8{
55575112 "tmp.zig:9:17: error: redefinition of 'Self'",
55585113 "tmp.zig:5:9: note: previous definition is here",
5559 );
5114 });
55605115
5561 cases.add(
5562 "while expected bool, got optional",
5116 cases.add("while expected bool, got optional",
55635117 \\export fn foo() void {
55645118 \\ while (bar()) {}
55655119 \\}
55665120 \\fn bar() ?i32 { return 1; }
5567 ,
5121 , &[_][]const u8{
55685122 "tmp.zig:2:15: error: expected type 'bool', found '?i32'",
5569 );
5123 });
55705124
5571 cases.add(
5572 "while expected bool, got error union",
5125 cases.add("while expected bool, got error union",
55735126 \\export fn foo() void {
55745127 \\ while (bar()) {}
55755128 \\}
55765129 \\fn bar() anyerror!i32 { return 1; }
5577 ,
5130 , &[_][]const u8{
55785131 "tmp.zig:2:15: error: expected type 'bool', found 'anyerror!i32'",
5579 );
5132 });
55805133
5581 cases.add(
5582 "while expected optional, got bool",
5134 cases.add("while expected optional, got bool",
55835135 \\export fn foo() void {
55845136 \\ while (bar()) |x| {}
55855137 \\}
55865138 \\fn bar() bool { return true; }
5587 ,
5139 , &[_][]const u8{
55885140 "tmp.zig:2:15: error: expected optional type, found 'bool'",
5589 );
5141 });
55905142
5591 cases.add(
5592 "while expected optional, got error union",
5143 cases.add("while expected optional, got error union",
55935144 \\export fn foo() void {
55945145 \\ while (bar()) |x| {}
55955146 \\}
55965147 \\fn bar() anyerror!i32 { return 1; }
5597 ,
5148 , &[_][]const u8{
55985149 "tmp.zig:2:15: error: expected optional type, found 'anyerror!i32'",
5599 );
5150 });
56005151
5601 cases.add(
5602 "while expected error union, got bool",
5152 cases.add("while expected error union, got bool",
56035153 \\export fn foo() void {
56045154 \\ while (bar()) |x| {} else |err| {}
56055155 \\}
56065156 \\fn bar() bool { return true; }
5607 ,
5157 , &[_][]const u8{
56085158 "tmp.zig:2:15: error: expected error union type, found 'bool'",
5609 );
5159 });
56105160
5611 cases.add(
5612 "while expected error union, got optional",
5161 cases.add("while expected error union, got optional",
56135162 \\export fn foo() void {
56145163 \\ while (bar()) |x| {} else |err| {}
56155164 \\}
56165165 \\fn bar() ?i32 { return 1; }
5617 ,
5166 , &[_][]const u8{
56185167 "tmp.zig:2:15: error: expected error union type, found '?i32'",
5619 );
5168 });
56205169
5621 cases.add(
5622 "inline fn calls itself indirectly",
5170 cases.add("inline fn calls itself indirectly",
56235171 \\export fn foo() void {
56245172 \\ bar();
56255173 \\}
......@@ -5632,94 +5180,85 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
56325180 \\ quux();
56335181 \\}
56345182 \\extern fn quux() void;
5635 ,
5183 , &[_][]const u8{
56365184 "tmp.zig:4:1: error: unable to inline function",
5637 );
5185 });
56385186
5639 cases.add(
5640 "save reference to inline function",
5187 cases.add("save reference to inline function",
56415188 \\export fn foo() void {
56425189 \\ quux(@ptrToInt(bar));
56435190 \\}
56445191 \\inline fn bar() void { }
56455192 \\extern fn quux(usize) void;
5646 ,
5193 , &[_][]const u8{
56475194 "tmp.zig:4:1: error: unable to inline function",
5648 );
5195 });
56495196
5650 cases.add(
5651 "signed integer division",
5197 cases.add("signed integer division",
56525198 \\export fn foo(a: i32, b: i32) i32 {
56535199 \\ return a / b;
56545200 \\}
5655 ,
5201 , &[_][]const u8{
56565202 "tmp.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact",
5657 );
5203 });
56585204
5659 cases.add(
5660 "signed integer remainder division",
5205 cases.add("signed integer remainder division",
56615206 \\export fn foo(a: i32, b: i32) i32 {
56625207 \\ return a % b;
56635208 \\}
5664 ,
5209 , &[_][]const u8{
56655210 "tmp.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod",
5666 );
5211 });
56675212
5668 cases.add(
5669 "compile-time division by zero",
5213 cases.add("compile-time division by zero",
56705214 \\comptime {
56715215 \\ const a: i32 = 1;
56725216 \\ const b: i32 = 0;
56735217 \\ const c = a / b;
56745218 \\}
5675 ,
5219 , &[_][]const u8{
56765220 "tmp.zig:4:17: error: division by zero",
5677 );
5221 });
56785222
5679 cases.add(
5680 "compile-time remainder division by zero",
5223 cases.add("compile-time remainder division by zero",
56815224 \\comptime {
56825225 \\ const a: i32 = 1;
56835226 \\ const b: i32 = 0;
56845227 \\ const c = a % b;
56855228 \\}
5686 ,
5229 , &[_][]const u8{
56875230 "tmp.zig:4:17: error: division by zero",
5688 );
5231 });
56895232
5690 cases.add(
5691 "@setRuntimeSafety twice for same scope",
5233 cases.add("@setRuntimeSafety twice for same scope",
56925234 \\export fn foo() void {
56935235 \\ @setRuntimeSafety(false);
56945236 \\ @setRuntimeSafety(false);
56955237 \\}
5696 ,
5238 , &[_][]const u8{
56975239 "tmp.zig:3:5: error: runtime safety set twice for same scope",
56985240 "tmp.zig:2:5: note: first set here",
5699 );
5241 });
57005242
5701 cases.add(
5702 "@setFloatMode twice for same scope",
5243 cases.add("@setFloatMode twice for same scope",
57035244 \\export fn foo() void {
57045245 \\ @setFloatMode(@import("builtin").FloatMode.Optimized);
57055246 \\ @setFloatMode(@import("builtin").FloatMode.Optimized);
57065247 \\}
5707 ,
5248 , &[_][]const u8{
57085249 "tmp.zig:3:5: error: float mode set twice for same scope",
57095250 "tmp.zig:2:5: note: first set here",
5710 );
5251 });
57115252
5712 cases.add(
5713 "array access of type",
5253 cases.add("array access of type",
57145254 \\export fn foo() void {
57155255 \\ var b: u8[40] = undefined;
57165256 \\}
5717 ,
5257 , &[_][]const u8{
57185258 "tmp.zig:2:14: error: array access of non-array type 'type'",
5719 );
5259 });
57205260
5721 cases.add(
5722 "cannot break out of defer expression",
5261 cases.add("cannot break out of defer expression",
57235262 \\export fn foo() void {
57245263 \\ while (true) {
57255264 \\ defer {
......@@ -5727,12 +5266,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
57275266 \\ }
57285267 \\ }
57295268 \\}
5730 ,
5269 , &[_][]const u8{
57315270 "tmp.zig:4:13: error: cannot break out of defer expression",
5732 );
5271 });
57335272
5734 cases.add(
5735 "cannot continue out of defer expression",
5273 cases.add("cannot continue out of defer expression",
57365274 \\export fn foo() void {
57375275 \\ while (true) {
57385276 \\ defer {
......@@ -5740,26 +5278,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
57405278 \\ }
57415279 \\ }
57425280 \\}
5743 ,
5281 , &[_][]const u8{
57445282 "tmp.zig:4:13: error: cannot continue out of defer expression",
5745 );
5746
5747 cases.add(
5748 "calling a var args function only known at runtime",
5749 \\var foos = [_]fn(...) void { foo1, foo2 };
5750 \\
5751 \\fn foo1(args: ...) void {}
5752 \\fn foo2(args: ...) void {}
5753 \\
5754 \\pub fn main() !void {
5755 \\ foos[0]();
5756 \\}
5757 ,
5758 "tmp.zig:7:9: error: calling a generic function requires compile-time known function value",
5759 );
5283 });
57605284
5761 cases.add(
5762 "calling a generic function only known at runtime",
5285 cases.add("calling a generic function only known at runtime",
57635286 \\var foos = [_]fn(var) void { foo1, foo2 };
57645287 \\
57655288 \\fn foo1(arg: var) void {}
......@@ -5768,12 +5291,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
57685291 \\pub fn main() !void {
57695292 \\ foos[0](true);
57705293 \\}
5771 ,
5294 , &[_][]const u8{
57725295 "tmp.zig:7:9: error: calling a generic function requires compile-time known function value",
5773 );
5296 });
57745297
5775 cases.add(
5776 "@compileError shows traceback of references that caused it",
5298 cases.add("@compileError shows traceback of references that caused it",
57775299 \\const foo = @compileError("aoeu",);
57785300 \\
57795301 \\const bar = baz + foo;
......@@ -5782,96 +5304,86 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
57825304 \\export fn entry() i32 {
57835305 \\ return bar;
57845306 \\}
5785 ,
5307 , &[_][]const u8{
57865308 "tmp.zig:1:13: error: aoeu",
57875309 "tmp.zig:3:19: note: referenced here",
57885310 "tmp.zig:7:12: note: referenced here",
5789 );
5311 });
57905312
5791 cases.add(
5792 "float literal too large error",
5313 cases.add("float literal too large error",
57935314 \\comptime {
57945315 \\ const a = 0x1.0p18495;
57955316 \\}
5796 ,
5317 , &[_][]const u8{
57975318 "tmp.zig:2:15: error: float literal out of range of any type",
5798 );
5319 });
57995320
5800 cases.add(
5801 "float literal too small error (denormal)",
5321 cases.add("float literal too small error (denormal)",
58025322 \\comptime {
58035323 \\ const a = 0x1.0p-19000;
58045324 \\}
5805 ,
5325 , &[_][]const u8{
58065326 "tmp.zig:2:15: error: float literal out of range of any type",
5807 );
5327 });
58085328
5809 cases.add(
5810 "explicit cast float literal to integer when there is a fraction component",
5329 cases.add("explicit cast float literal to integer when there is a fraction component",
58115330 \\export fn entry() i32 {
58125331 \\ return @as(i32, 12.34);
58135332 \\}
5814 ,
5333 , &[_][]const u8{
58155334 "tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'",
5816 );
5335 });
58175336
5818 cases.add(
5819 "non pointer given to @ptrToInt",
5337 cases.add("non pointer given to @ptrToInt",
58205338 \\export fn entry(x: i32) usize {
58215339 \\ return @ptrToInt(x);
58225340 \\}
5823 ,
5341 , &[_][]const u8{
58245342 "tmp.zig:2:22: error: expected pointer, found 'i32'",
5825 );
5343 });
58265344
5827 cases.add(
5828 "@shlExact shifts out 1 bits",
5345 cases.add("@shlExact shifts out 1 bits",
58295346 \\comptime {
58305347 \\ const x = @shlExact(@as(u8, 0b01010101), 2);
58315348 \\}
5832 ,
5349 , &[_][]const u8{
58335350 "tmp.zig:2:15: error: operation caused overflow",
5834 );
5351 });
58355352
5836 cases.add(
5837 "@shrExact shifts out 1 bits",
5353 cases.add("@shrExact shifts out 1 bits",
58385354 \\comptime {
58395355 \\ const x = @shrExact(@as(u8, 0b10101010), 2);
58405356 \\}
5841 ,
5357 , &[_][]const u8{
58425358 "tmp.zig:2:15: error: exact shift shifted out 1 bits",
5843 );
5359 });
58445360
5845 cases.add(
5846 "shifting without int type or comptime known",
5361 cases.add("shifting without int type or comptime known",
58475362 \\export fn entry(x: u8) u8 {
58485363 \\ return 0x11 << x;
58495364 \\}
5850 ,
5365 , &[_][]const u8{
58515366 "tmp.zig:2:17: error: LHS of shift must be an integer type, or RHS must be compile-time known",
5852 );
5367 });
58535368
5854 cases.add(
5855 "shifting RHS is log2 of LHS int bit width",
5369 cases.add("shifting RHS is log2 of LHS int bit width",
58565370 \\export fn entry(x: u8, y: u8) u8 {
58575371 \\ return x << y;
58585372 \\}
5859 ,
5373 , &[_][]const u8{
58605374 "tmp.zig:2:17: error: expected type 'u3', found 'u8'",
5861 );
5375 });
58625376
5863 cases.add(
5864 "globally shadowing a primitive type",
5377 cases.add("globally shadowing a primitive type",
58655378 \\const u16 = @intType(false, 8);
58665379 \\export fn entry() void {
58675380 \\ const a: u16 = 300;
58685381 \\}
5869 ,
5382 , &[_][]const u8{
58705383 "tmp.zig:1:1: error: declaration shadows primitive type 'u16'",
5871 );
5384 });
58725385
5873 cases.add(
5874 "implicitly increasing pointer alignment",
5386 cases.add("implicitly increasing pointer alignment",
58755387 \\const Foo = packed struct {
58765388 \\ a: u8,
58775389 \\ b: u32,
......@@ -5885,12 +5397,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
58855397 \\fn bar(x: *u32) void {
58865398 \\ x.* += 1;
58875399 \\}
5888 ,
5400 , &[_][]const u8{
58895401 "tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32'",
5890 );
5402 });
58915403
5892 cases.add(
5893 "implicitly increasing slice alignment",
5404 cases.add("implicitly increasing slice alignment",
58945405 \\const Foo = packed struct {
58955406 \\ a: u8,
58965407 \\ b: u32,
......@@ -5905,36 +5416,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
59055416 \\fn bar(x: []u32) void {
59065417 \\ x[0] += 1;
59075418 \\}
5908 ,
5419 , &[_][]const u8{
59095420 "tmp.zig:9:26: error: cast increases pointer alignment",
59105421 "tmp.zig:9:26: note: '*align(1) u32' has alignment 1",
59115422 "tmp.zig:9:26: note: '*[1]u32' has alignment 4",
5912 );
5423 });
59135424
5914 cases.add(
5915 "increase pointer alignment in @ptrCast",
5425 cases.add("increase pointer alignment in @ptrCast",
59165426 \\export fn entry() u32 {
59175427 \\ var bytes: [4]u8 = [_]u8{0x01, 0x02, 0x03, 0x04};
59185428 \\ const ptr = @ptrCast(*u32, &bytes[0]);
59195429 \\ return ptr.*;
59205430 \\}
5921 ,
5431 , &[_][]const u8{
59225432 "tmp.zig:3:17: error: cast increases pointer alignment",
59235433 "tmp.zig:3:38: note: '*u8' has alignment 1",
59245434 "tmp.zig:3:26: note: '*u32' has alignment 4",
5925 );
5435 });
59265436
5927 cases.add(
5928 "@alignCast expects pointer or slice",
5437 cases.add("@alignCast expects pointer or slice",
59295438 \\export fn entry() void {
59305439 \\ @alignCast(4, @as(u32, 3));
59315440 \\}
5932 ,
5441 , &[_][]const u8{
59335442 "tmp.zig:2:19: error: expected pointer or slice, found 'u32'",
5934 );
5443 });
59355444
5936 cases.add(
5937 "passing an under-aligned function pointer",
5445 cases.add("passing an under-aligned function pointer",
59385446 \\export fn entry() void {
59395447 \\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234);
59405448 \\}
......@@ -5942,45 +5450,41 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
59425450 \\ if (ptr() != answer) unreachable;
59435451 \\}
59445452 \\fn alignedSmall() align(4) i32 { return 1234; }
5945 ,
5453 , &[_][]const u8{
59465454 "tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'",
5947 );
5455 });
59485456
5949 cases.add(
5950 "passing a not-aligned-enough pointer to cmpxchg",
5457 cases.add("passing a not-aligned-enough pointer to cmpxchg",
59515458 \\const AtomicOrder = @import("builtin").AtomicOrder;
59525459 \\export fn entry() bool {
59535460 \\ var x: i32 align(1) = 1234;
59545461 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {}
59555462 \\ return x == 5678;
59565463 \\}
5957 ,
5464 , &[_][]const u8{
59585465 "tmp.zig:4:32: error: expected type '*i32', found '*align(1) i32'",
5959 );
5466 });
59605467
5961 cases.add(
5962 "wrong size to an array literal",
5468 cases.add("wrong size to an array literal",
59635469 \\comptime {
59645470 \\ const array = [2]u8{1, 2, 3};
59655471 \\}
5966 ,
5472 , &[_][]const u8{
59675473 "tmp.zig:2:31: error: index 2 outside array of size 2",
5968 );
5474 });
59695475
5970 cases.add(
5971 "wrong pointer coerced to pointer to @OpaqueType()",
5476 cases.add("wrong pointer coerced to pointer to @OpaqueType()",
59725477 \\const Derp = @OpaqueType();
59735478 \\extern fn bar(d: *Derp) void;
59745479 \\export fn foo() void {
59755480 \\ var x = @as(u8, 1);
59765481 \\ bar(@ptrCast(*c_void, &x));
59775482 \\}
5978 ,
5483 , &[_][]const u8{
59795484 "tmp.zig:5:9: error: expected type '*Derp', found '*c_void'",
5980 );
5485 });
59815486
5982 cases.add(
5983 "non-const variables of things that require const variables",
5487 cases.add("non-const variables of things that require const variables",
59845488 \\export fn entry1() void {
59855489 \\ var m2 = &2;
59865490 \\}
......@@ -6012,7 +5516,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
60125516 \\const Foo = struct {
60135517 \\ fn bar(self: *const Foo) void {}
60145518 \\};
6015 ,
5519 , &[_][]const u8{
60165520 "tmp.zig:2:4: error: variable of type '*comptime_int' must be const or comptime",
60175521 "tmp.zig:5:4: error: variable of type '(undefined)' must be const or comptime",
60185522 "tmp.zig:8:4: error: variable of type 'comptime_int' must be const or comptime",
......@@ -6022,30 +5526,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
60225526 "tmp.zig:20:4: error: variable of type 'type' must be const or comptime",
60235527 "tmp.zig:23:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime",
60245528 "tmp.zig:26:22: error: unreachable code",
6025 );
5529 });
60265530
6027 cases.add(
6028 "wrong types given to atomic order args in cmpxchg",
5531 cases.add("wrong types given to atomic order args in cmpxchg",
60295532 \\export fn entry() void {
60305533 \\ var x: i32 = 1234;
60315534 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {}
60325535 \\}
6033 ,
5536 , &[_][]const u8{
60345537 "tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'",
6035 );
5538 });
60365539
6037 cases.add(
6038 "wrong types given to @export",
5540 cases.add("wrong types given to @export",
60395541 \\extern fn entry() void { }
60405542 \\comptime {
60415543 \\ @export("entry", entry, @as(u32, 1234));
60425544 \\}
6043 ,
5545 , &[_][]const u8{
60445546 "tmp.zig:3:29: error: expected type 'std.builtin.GlobalLinkage', found 'u32'",
6045 );
5547 });
60465548
6047 cases.add(
6048 "struct with invalid field",
5549 cases.add("struct with invalid field",
60495550 \\const std = @import("std",);
60505551 \\const Allocator = std.mem.Allocator;
60515552 \\const ArrayList = std.ArrayList;
......@@ -6069,62 +5570,56 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
60695570 \\ .weight = HeaderWeight.H1,
60705571 \\ };
60715572 \\}
6072 ,
5573 , &[_][]const u8{
60735574 "tmp.zig:14:17: error: use of undeclared identifier 'HeaderValue'",
6074 );
5575 });
60755576
6076 cases.add(
6077 "@setAlignStack outside function",
5577 cases.add("@setAlignStack outside function",
60785578 \\comptime {
60795579 \\ @setAlignStack(16);
60805580 \\}
6081 ,
5581 , &[_][]const u8{
60825582 "tmp.zig:2:5: error: @setAlignStack outside function",
6083 );
5583 });
60845584
6085 cases.add(
6086 "@setAlignStack in naked function",
5585 cases.add("@setAlignStack in naked function",
60875586 \\export nakedcc fn entry() void {
60885587 \\ @setAlignStack(16);
60895588 \\}
6090 ,
5589 , &[_][]const u8{
60915590 "tmp.zig:2:5: error: @setAlignStack in naked function",
6092 );
5591 });
60935592
6094 cases.add(
6095 "@setAlignStack in inline function",
5593 cases.add("@setAlignStack in inline function",
60965594 \\export fn entry() void {
60975595 \\ foo();
60985596 \\}
60995597 \\inline fn foo() void {
61005598 \\ @setAlignStack(16);
61015599 \\}
6102 ,
5600 , &[_][]const u8{
61035601 "tmp.zig:5:5: error: @setAlignStack in inline function",
6104 );
5602 });
61055603
6106 cases.add(
6107 "@setAlignStack set twice",
5604 cases.add("@setAlignStack set twice",
61085605 \\export fn entry() void {
61095606 \\ @setAlignStack(16);
61105607 \\ @setAlignStack(16);
61115608 \\}
6112 ,
5609 , &[_][]const u8{
61135610 "tmp.zig:3:5: error: alignstack set twice",
61145611 "tmp.zig:2:5: note: first set here",
6115 );
5612 });
61165613
6117 cases.add(
6118 "@setAlignStack too big",
5614 cases.add("@setAlignStack too big",
61195615 \\export fn entry() void {
61205616 \\ @setAlignStack(511 + 1);
61215617 \\}
6122 ,
5618 , &[_][]const u8{
61235619 "tmp.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256",
6124 );
5620 });
61255621
6126 cases.add(
6127 "storing runtime value in compile time variable then using it",
5622 cases.add("storing runtime value in compile time variable then using it",
61285623 \\const Mode = @import("builtin").Mode;
61295624 \\
61305625 \\fn Free(comptime filename: []const u8) TestCase {
......@@ -6166,12 +5661,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
61665661 \\ }
61675662 \\ }
61685663 \\}
6169 ,
5664 , &[_][]const u8{
61705665 "tmp.zig:37:29: error: cannot store runtime value in compile time variable",
6171 );
5666 });
61725667
6173 cases.add(
6174 "field access of opaque type",
5668 cases.add("field access of opaque type",
61755669 \\const MyType = @OpaqueType();
61765670 \\
61775671 \\export fn entry() bool {
......@@ -6182,163 +5676,143 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
61825676 \\fn bar(x: *MyType) bool {
61835677 \\ return x.blah;
61845678 \\}
6185 ,
5679 , &[_][]const u8{
61865680 "tmp.zig:9:13: error: type '*MyType' does not support field access",
6187 );
5681 });
61885682
6189 cases.add(
6190 "carriage return special case",
6191 "fn test() bool {\r\n" ++
6192 " true\r\n" ++
6193 "}\r\n",
5683 cases.add("carriage return special case", "fn test() bool {\r\n" ++
5684 " true\r\n" ++
5685 "}\r\n", &[_][]const u8{
61945686 "tmp.zig:1:17: error: invalid carriage return, only '\\n' line endings are supported",
6195 );
5687 });
61965688
6197 cases.add(
6198 "invalid legacy unicode escape",
5689 cases.add("invalid legacy unicode escape",
61995690 \\export fn entry() void {
62005691 \\ const a = '\U1234';
62015692 \\}
6202 ,
5693 , &[_][]const u8{
62035694 "tmp.zig:2:17: error: invalid character: 'U'",
6204 );
5695 });
62055696
6206 cases.add(
6207 "invalid empty unicode escape",
5697 cases.add("invalid empty unicode escape",
62085698 \\export fn entry() void {
62095699 \\ const a = '\u{}';
62105700 \\}
6211 ,
5701 , &[_][]const u8{
62125702 "tmp.zig:2:19: error: empty unicode escape sequence",
6213 );
5703 });
62145704
6215 cases.add(
6216 "non-printable invalid character",
6217 "\xff\xfe" ++
6218 \\fn test() bool {\r
6219 \\ true\r
6220 \\}
6221 ,
5705 cases.add("non-printable invalid character", "\xff\xfe" ++
5706 \\fn test() bool {\r
5707 \\ true\r
5708 \\}
5709 , &[_][]const u8{
62225710 "tmp.zig:1:1: error: invalid character: '\\xff'",
6223 );
5711 });
62245712
6225 cases.add(
6226 "non-printable invalid character with escape alternative",
6227 "fn test() bool {\n" ++
6228 "\ttrue\n" ++
6229 "}\n",
5713 cases.add("non-printable invalid character with escape alternative", "fn test() bool {\n" ++
5714 "\ttrue\n" ++
5715 "}\n", &[_][]const u8{
62305716 "tmp.zig:2:1: error: invalid character: '\\t'",
6231 );
5717 });
62325718
6233 cases.add(
6234 "@ArgType given non function parameter",
5719 cases.add("@ArgType given non function parameter",
62355720 \\comptime {
62365721 \\ _ = @ArgType(i32, 3);
62375722 \\}
6238 ,
5723 , &[_][]const u8{
62395724 "tmp.zig:2:18: error: expected function, found 'i32'",
6240 );
5725 });
62415726
6242 cases.add(
6243 "@ArgType arg index out of bounds",
5727 cases.add("@ArgType arg index out of bounds",
62445728 \\comptime {
62455729 \\ _ = @ArgType(@typeOf(add), 2);
62465730 \\}
62475731 \\fn add(a: i32, b: i32) i32 { return a + b; }
6248 ,
5732 , &[_][]const u8{
62495733 "tmp.zig:2:32: error: arg index 2 out of bounds; 'fn(i32, i32) i32' has 2 arguments",
6250 );
5734 });
62515735
6252 cases.add(
6253 "@memberType on unsupported type",
5736 cases.add("@memberType on unsupported type",
62545737 \\comptime {
62555738 \\ _ = @memberType(i32, 0);
62565739 \\}
6257 ,
5740 , &[_][]const u8{
62585741 "tmp.zig:2:21: error: type 'i32' does not support @memberType",
6259 );
5742 });
62605743
6261 cases.add(
6262 "@memberType on enum",
5744 cases.add("@memberType on enum",
62635745 \\comptime {
62645746 \\ _ = @memberType(Foo, 0);
62655747 \\}
62665748 \\const Foo = enum {A,};
6267 ,
5749 , &[_][]const u8{
62685750 "tmp.zig:2:21: error: type 'Foo' does not support @memberType",
6269 );
5751 });
62705752
6271 cases.add(
6272 "@memberType struct out of bounds",
5753 cases.add("@memberType struct out of bounds",
62735754 \\comptime {
62745755 \\ _ = @memberType(Foo, 0);
62755756 \\}
62765757 \\const Foo = struct {};
6277 ,
5758 , &[_][]const u8{
62785759 "tmp.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members",
6279 );
5760 });
62805761
6281 cases.add(
6282 "@memberType union out of bounds",
5762 cases.add("@memberType union out of bounds",
62835763 \\comptime {
62845764 \\ _ = @memberType(Foo, 1);
62855765 \\}
62865766 \\const Foo = union {A: void,};
6287 ,
5767 , &[_][]const u8{
62885768 "tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members",
6289 );
5769 });
62905770
6291 cases.add(
6292 "@memberName on unsupported type",
5771 cases.add("@memberName on unsupported type",
62935772 \\comptime {
62945773 \\ _ = @memberName(i32, 0);
62955774 \\}
6296 ,
5775 , &[_][]const u8{
62975776 "tmp.zig:2:21: error: type 'i32' does not support @memberName",
6298 );
5777 });
62995778
6300 cases.add(
6301 "@memberName struct out of bounds",
5779 cases.add("@memberName struct out of bounds",
63025780 \\comptime {
63035781 \\ _ = @memberName(Foo, 0);
63045782 \\}
63055783 \\const Foo = struct {};
6306 ,
5784 , &[_][]const u8{
63075785 "tmp.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members",
6308 );
5786 });
63095787
6310 cases.add(
6311 "@memberName enum out of bounds",
5788 cases.add("@memberName enum out of bounds",
63125789 \\comptime {
63135790 \\ _ = @memberName(Foo, 1);
63145791 \\}
63155792 \\const Foo = enum {A,};
6316 ,
5793 , &[_][]const u8{
63175794 "tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members",
6318 );
5795 });
63195796
6320 cases.add(
6321 "@memberName union out of bounds",
5797 cases.add("@memberName union out of bounds",
63225798 \\comptime {
63235799 \\ _ = @memberName(Foo, 1);
63245800 \\}
63255801 \\const Foo = union {A:i32,};
6326 ,
5802 , &[_][]const u8{
63275803 "tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members",
6328 );
5804 });
63295805
6330 cases.add(
6331 "calling var args extern function, passing array instead of pointer",
5806 cases.add("calling var args extern function, passing array instead of pointer",
63325807 \\export fn entry() void {
63335808 \\ foo("hello".*,);
63345809 \\}
63355810 \\pub extern fn foo(format: *const u8, ...) void;
6336 ,
5811 , &[_][]const u8{
63375812 "tmp.zig:2:16: error: expected type '*const u8', found '[5:0]u8'",
6338 );
5813 });
63395814
6340 cases.add(
6341 "constant inside comptime function has compile error",
5815 cases.add("constant inside comptime function has compile error",
63425816 \\const ContextAllocator = MemoryPool(usize);
63435817 \\
63445818 \\pub fn MemoryPool(comptime T: type) type {
......@@ -6352,11 +5826,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
63525826 \\export fn entry() void {
63535827 \\ var allocator: ContextAllocator = undefined;
63545828 \\}
6355 ,
5829 , &[_][]const u8{
63565830 "tmp.zig:4:25: error: aoeu",
63575831 "tmp.zig:1:36: note: referenced here",
63585832 "tmp.zig:12:20: note: referenced here",
6359 );
5833 });
63605834
63615835 cases.add("specify enum tag type that is too small",
63625836 \\const Small = enum (u2) {
......@@ -6370,10 +5844,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
63705844 \\export fn entry() void {
63715845 \\ var x = Small.One;
63725846 \\}
6373 , "tmp.zig:6:5: error: enumeration value 4 too large for type 'u2'");
5847 , &[_][]const u8{
5848 "tmp.zig:6:5: error: enumeration value 4 too large for type 'u2'",
5849 });
63745850
6375 cases.add(
6376 "specify non-integer enum tag type",
5851 cases.add("specify non-integer enum tag type",
63775852 \\const Small = enum (f32) {
63785853 \\ One,
63795854 \\ Two,
......@@ -6383,12 +5858,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
63835858 \\export fn entry() void {
63845859 \\ var x = Small.One;
63855860 \\}
6386 ,
5861 , &[_][]const u8{
63875862 "tmp.zig:1:21: error: expected integer, found 'f32'",
6388 );
5863 });
63895864
6390 cases.add(
6391 "implicitly casting enum to tag type",
5865 cases.add("implicitly casting enum to tag type",
63925866 \\const Small = enum(u2) {
63935867 \\ One,
63945868 \\ Two,
......@@ -6399,12 +5873,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
63995873 \\export fn entry() void {
64005874 \\ var x: u2 = Small.Two;
64015875 \\}
6402 ,
5876 , &[_][]const u8{
64035877 "tmp.zig:9:22: error: expected type 'u2', found 'Small'",
6404 );
5878 });
64055879
6406 cases.add(
6407 "explicitly casting non tag type to enum",
5880 cases.add("explicitly casting non tag type to enum",
64085881 \\const Small = enum(u2) {
64095882 \\ One,
64105883 \\ Two,
......@@ -6416,45 +5889,41 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
64165889 \\ var y = @as(u3, 3);
64175890 \\ var x = @intToEnum(Small, y);
64185891 \\}
6419 ,
5892 , &[_][]const u8{
64205893 "tmp.zig:10:31: error: expected type 'u2', found 'u3'",
6421 );
5894 });
64225895
6423 cases.add(
6424 "union fields with value assignments",
5896 cases.add("union fields with value assignments",
64255897 \\const MultipleChoice = union {
64265898 \\ A: i32 = 20,
64275899 \\};
64285900 \\export fn entry() void {
64295901 \\ var x: MultipleChoice = undefined;
64305902 \\}
6431 ,
5903 , &[_][]const u8{
64325904 "tmp.zig:2:14: error: untagged union field assignment",
64335905 "tmp.zig:1:24: note: consider 'union(enum)' here",
6434 );
5906 });
64355907
6436 cases.add(
6437 "enum with 0 fields",
5908 cases.add("enum with 0 fields",
64385909 \\const Foo = enum {};
64395910 \\export fn entry() usize {
64405911 \\ return @sizeOf(Foo);
64415912 \\}
6442 ,
5913 , &[_][]const u8{
64435914 "tmp.zig:1:13: error: enums must have 1 or more fields",
6444 );
5915 });
64455916
6446 cases.add(
6447 "union with 0 fields",
5917 cases.add("union with 0 fields",
64485918 \\const Foo = union {};
64495919 \\export fn entry() usize {
64505920 \\ return @sizeOf(Foo);
64515921 \\}
6452 ,
5922 , &[_][]const u8{
64535923 "tmp.zig:1:13: error: unions must have 1 or more fields",
6454 );
5924 });
64555925
6456 cases.add(
6457 "enum value already taken",
5926 cases.add("enum value already taken",
64585927 \\const MultipleChoice = enum(u32) {
64595928 \\ A = 20,
64605929 \\ B = 40,
......@@ -6465,13 +5934,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
64655934 \\export fn entry() void {
64665935 \\ var x = MultipleChoice.C;
64675936 \\}
6468 ,
5937 , &[_][]const u8{
64695938 "tmp.zig:6:5: error: enum tag value 60 already taken",
64705939 "tmp.zig:4:5: note: other occurrence here",
6471 );
5940 });
64725941
6473 cases.add(
6474 "union with specified enum omits field",
5942 cases.add("union with specified enum omits field",
64755943 \\const Letter = enum {
64765944 \\ A,
64775945 \\ B,
......@@ -6484,50 +5952,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
64845952 \\export fn entry() usize {
64855953 \\ return @sizeOf(Payload);
64865954 \\}
6487 ,
5955 , &[_][]const u8{
64885956 "tmp.zig:6:17: error: enum field missing: 'C'",
64895957 "tmp.zig:4:5: note: declared here",
6490 );
5958 });
64915959
6492 cases.add(
6493 "@TagType when union has no attached enum",
5960 cases.add("@TagType when union has no attached enum",
64945961 \\const Foo = union {
64955962 \\ A: i32,
64965963 \\};
64975964 \\export fn entry() void {
64985965 \\ const x = @TagType(Foo);
64995966 \\}
6500 ,
5967 , &[_][]const u8{
65015968 "tmp.zig:5:24: error: union 'Foo' has no tag",
65025969 "tmp.zig:1:13: note: consider 'union(enum)' here",
6503 );
5970 });
65045971
6505 cases.add(
6506 "non-integer tag type to automatic union enum",
5972 cases.add("non-integer tag type to automatic union enum",
65075973 \\const Foo = union(enum(f32)) {
65085974 \\ A: i32,
65095975 \\};
65105976 \\export fn entry() void {
65115977 \\ const x = @TagType(Foo);
65125978 \\}
6513 ,
5979 , &[_][]const u8{
65145980 "tmp.zig:1:24: error: expected integer tag type, found 'f32'",
6515 );
5981 });
65165982
6517 cases.add(
6518 "non-enum tag type passed to union",
5983 cases.add("non-enum tag type passed to union",
65195984 \\const Foo = union(u32) {
65205985 \\ A: i32,
65215986 \\};
65225987 \\export fn entry() void {
65235988 \\ const x = @TagType(Foo);
65245989 \\}
6525 ,
5990 , &[_][]const u8{
65265991 "tmp.zig:1:19: error: expected enum tag type, found 'u32'",
6527 );
5992 });
65285993
6529 cases.add(
6530 "union auto-enum value already taken",
5994 cases.add("union auto-enum value already taken",
65315995 \\const MultipleChoice = union(enum(u32)) {
65325996 \\ A = 20,
65335997 \\ B = 40,
......@@ -6538,13 +6002,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
65386002 \\export fn entry() void {
65396003 \\ var x = MultipleChoice { .C = {} };
65406004 \\}
6541 ,
6005 , &[_][]const u8{
65426006 "tmp.zig:6:9: error: enum tag value 60 already taken",
65436007 "tmp.zig:4:9: note: other occurrence here",
6544 );
6008 });
65456009
6546 cases.add(
6547 "union enum field does not match enum",
6010 cases.add("union enum field does not match enum",
65486011 \\const Letter = enum {
65496012 \\ A,
65506013 \\ B,
......@@ -6559,13 +6022,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
65596022 \\export fn entry() void {
65606023 \\ var a = Payload {.A = 1234};
65616024 \\}
6562 ,
6025 , &[_][]const u8{
65636026 "tmp.zig:10:5: error: enum field not found: 'D'",
65646027 "tmp.zig:1:16: note: enum declared here",
6565 );
6028 });
65666029
6567 cases.add(
6568 "field type supplied in an enum",
6030 cases.add("field type supplied in an enum",
65696031 \\const Letter = enum {
65706032 \\ A: void,
65716033 \\ B,
......@@ -6574,37 +6036,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
65746036 \\export fn entry() void {
65756037 \\ var b = Letter.B;
65766038 \\}
6577 ,
6039 , &[_][]const u8{
65786040 "tmp.zig:2:8: error: structs and unions, not enums, support field types",
65796041 "tmp.zig:1:16: note: consider 'union(enum)' here",
6580 );
6042 });
65816043
6582 cases.add(
6583 "struct field missing type",
6044 cases.add("struct field missing type",
65846045 \\const Letter = struct {
65856046 \\ A,
65866047 \\};
65876048 \\export fn entry() void {
65886049 \\ var a = Letter { .A = {} };
65896050 \\}
6590 ,
6051 , &[_][]const u8{
65916052 "tmp.zig:2:5: error: struct field missing type",
6592 );
6053 });
65936054
6594 cases.add(
6595 "extern union field missing type",
6055 cases.add("extern union field missing type",
65966056 \\const Letter = extern union {
65976057 \\ A,
65986058 \\};
65996059 \\export fn entry() void {
66006060 \\ var a = Letter { .A = {} };
66016061 \\}
6602 ,
6062 , &[_][]const u8{
66036063 "tmp.zig:2:5: error: union field missing type",
6604 );
6064 });
66056065
6606 cases.add(
6607 "extern union given enum tag type",
6066 cases.add("extern union given enum tag type",
66086067 \\const Letter = enum {
66096068 \\ A,
66106069 \\ B,
......@@ -6618,12 +6077,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
66186077 \\export fn entry() void {
66196078 \\ var a = Payload { .A = 1234 };
66206079 \\}
6621 ,
6080 , &[_][]const u8{
66226081 "tmp.zig:6:30: error: extern union does not support enum tag type",
6623 );
6082 });
66246083
6625 cases.add(
6626 "packed union given enum tag type",
6084 cases.add("packed union given enum tag type",
66276085 \\const Letter = enum {
66286086 \\ A,
66296087 \\ B,
......@@ -6637,12 +6095,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
66376095 \\export fn entry() void {
66386096 \\ var a = Payload { .A = 1234 };
66396097 \\}
6640 ,
6098 , &[_][]const u8{
66416099 "tmp.zig:6:30: error: packed union does not support enum tag type",
6642 );
6100 });
66436101
6644 cases.add(
6645 "packed union with automatic layout field",
6102 cases.add("packed union with automatic layout field",
66466103 \\const Foo = struct {
66476104 \\ a: u32,
66486105 \\ b: f32,
......@@ -6654,12 +6111,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
66546111 \\export fn entry() void {
66556112 \\ var a = Payload { .B = true };
66566113 \\}
6657 ,
6114 , &[_][]const u8{
66586115 "tmp.zig:6:5: error: non-packed, non-extern struct 'Foo' not allowed in packed union; no guaranteed in-memory representation",
6659 );
6116 });
66606117
6661 cases.add(
6662 "switch on union with no attached enum",
6118 cases.add("switch on union with no attached enum",
66636119 \\const Payload = union {
66646120 \\ A: i32,
66656121 \\ B: f64,
......@@ -6675,13 +6131,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
66756131 \\ else => unreachable,
66766132 \\ }
66776133 \\}
6678 ,
6134 , &[_][]const u8{
66796135 "tmp.zig:11:14: error: switch on union which has no attached enum",
66806136 "tmp.zig:1:17: note: consider 'union(enum)' here",
6681 );
6137 });
66826138
6683 cases.add(
6684 "enum in field count range but not matching tag",
6139 cases.add("enum in field count range but not matching tag",
66856140 \\const Foo = enum(u32) {
66866141 \\ A = 10,
66876142 \\ B = 11,
......@@ -6689,13 +6144,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
66896144 \\export fn entry() void {
66906145 \\ var x = @intToEnum(Foo, 0);
66916146 \\}
6692 ,
6147 , &[_][]const u8{
66936148 "tmp.zig:6:13: error: enum 'Foo' has no tag matching integer value 0",
66946149 "tmp.zig:1:13: note: 'Foo' declared here",
6695 );
6150 });
66966151
6697 cases.add(
6698 "comptime cast enum to union but field has payload",
6152 cases.add("comptime cast enum to union but field has payload",
66996153 \\const Letter = enum { A, B, C };
67006154 \\const Value = union(Letter) {
67016155 \\ A: i32,
......@@ -6705,13 +6159,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
67056159 \\export fn entry() void {
67066160 \\ var x: Value = Letter.A;
67076161 \\}
6708 ,
6162 , &[_][]const u8{
67096163 "tmp.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'",
67106164 "tmp.zig:3:5: note: field 'A' declared here",
6711 );
6165 });
67126166
6713 cases.add(
6714 "runtime cast to union which has non-void fields",
6167 cases.add("runtime cast to union which has non-void fields",
67156168 \\const Letter = enum { A, B, C };
67166169 \\const Value = union(Letter) {
67176170 \\ A: i32,
......@@ -6724,37 +6177,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
67246177 \\fn foo(l: Letter) void {
67256178 \\ var x: Value = l;
67266179 \\}
6727 ,
6180 , &[_][]const u8{
67286181 "tmp.zig:11:20: error: runtime cast to union 'Value' which has non-void fields",
67296182 "tmp.zig:3:5: note: field 'A' has type 'i32'",
6730 );
6183 });
67316184
6732 cases.add(
6733 "taking byte offset of void field in struct",
6185 cases.add("taking byte offset of void field in struct",
67346186 \\const Empty = struct {
67356187 \\ val: void,
67366188 \\};
67376189 \\export fn foo() void {
67386190 \\ const fieldOffset = @byteOffsetOf(Empty, "val",);
67396191 \\}
6740 ,
6192 , &[_][]const u8{
67416193 "tmp.zig:5:46: error: zero-bit field 'val' in struct 'Empty' has no offset",
6742 );
6194 });
67436195
6744 cases.add(
6745 "taking bit offset of void field in struct",
6196 cases.add("taking bit offset of void field in struct",
67466197 \\const Empty = struct {
67476198 \\ val: void,
67486199 \\};
67496200 \\export fn foo() void {
67506201 \\ const fieldOffset = @bitOffsetOf(Empty, "val",);
67516202 \\}
6752 ,
6203 , &[_][]const u8{
67536204 "tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset",
6754 );
6205 });
67556206
6756 cases.add(
6757 "invalid union field access in comptime",
6207 cases.add("invalid union field access in comptime",
67586208 \\const Foo = union {
67596209 \\ Bar: u8,
67606210 \\ Baz: void,
......@@ -6763,60 +6213,54 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
67636213 \\ var foo = Foo {.Baz = {}};
67646214 \\ const bar_val = foo.Bar;
67656215 \\}
6766 ,
6216 , &[_][]const u8{
67676217 "tmp.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set",
6768 );
6218 });
67696219
6770 cases.add(
6771 "getting return type of generic function",
6220 cases.add("getting return type of generic function",
67726221 \\fn generic(a: var) void {}
67736222 \\comptime {
67746223 \\ _ = @typeOf(generic).ReturnType;
67756224 \\}
6776 ,
6225 , &[_][]const u8{
67776226 "tmp.zig:3:25: error: ReturnType has not been resolved because 'fn(var)var' is generic",
6778 );
6227 });
67796228
6780 cases.add(
6781 "getting @ArgType of generic function",
6229 cases.add("getting @ArgType of generic function",
67826230 \\fn generic(a: var) void {}
67836231 \\comptime {
67846232 \\ _ = @ArgType(@typeOf(generic), 0);
67856233 \\}
6786 ,
6234 , &[_][]const u8{
67876235 "tmp.zig:3:36: error: @ArgType could not resolve the type of arg 0 because 'fn(var)var' is generic",
6788 );
6236 });
67896237
6790 cases.add(
6791 "unsupported modifier at start of asm output constraint",
6238 cases.add("unsupported modifier at start of asm output constraint",
67926239 \\export fn foo() void {
67936240 \\ var bar: u32 = 3;
67946241 \\ asm volatile ("" : [baz]"+r"(bar) : : "");
67956242 \\}
6796 ,
6243 , &[_][]const u8{
67976244 "tmp.zig:3:5: error: invalid modifier starting output constraint for 'baz': '+', only '=' is supported. Compiler TODO: see https://github.com/ziglang/zig/issues/215",
6798 );
6245 });
67996246
6800 cases.add(
6801 "comptime_int in asm input",
6247 cases.add("comptime_int in asm input",
68026248 \\export fn foo() void {
68036249 \\ asm volatile ("" : : [bar]"r"(3) : "");
68046250 \\}
6805 ,
6251 , &[_][]const u8{
68066252 "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int",
6807 );
6253 });
68086254
6809 cases.add(
6810 "comptime_float in asm input",
6255 cases.add("comptime_float in asm input",
68116256 \\export fn foo() void {
68126257 \\ asm volatile ("" : : [bar]"r"(3.17) : "");
68136258 \\}
6814 ,
6259 , &[_][]const u8{
68156260 "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float",
6816 );
6261 });
68176262
6818 cases.add(
6819 "runtime assignment to comptime struct type",
6263 cases.add("runtime assignment to comptime struct type",
68206264 \\const Foo = struct {
68216265 \\ Bar: u8,
68226266 \\ Baz: type,
......@@ -6825,12 +6269,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
68256269 \\ var x: u8 = 0;
68266270 \\ const foo = Foo { .Bar = x, .Baz = u8 };
68276271 \\}
6828 ,
6272 , &[_][]const u8{
68296273 "tmp.zig:7:23: error: unable to evaluate constant expression",
6830 );
6274 });
68316275
6832 cases.add(
6833 "runtime assignment to comptime union type",
6276 cases.add("runtime assignment to comptime union type",
68346277 \\const Foo = union {
68356278 \\ Bar: u8,
68366279 \\ Baz: type,
......@@ -6839,42 +6282,39 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
68396282 \\ var x: u8 = 0;
68406283 \\ const foo = Foo { .Bar = x };
68416284 \\}
6842 ,
6285 , &[_][]const u8{
68436286 "tmp.zig:7:23: error: unable to evaluate constant expression",
6844 );
6287 });
68456288
6846 cases.addTest(
6847 "@shuffle with selected index past first vector length",
6289 cases.addTest("@shuffle with selected index past first vector length",
68486290 \\export fn entry() void {
68496291 \\ const v: @Vector(4, u32) = [4]u32{ 10, 11, 12, 13 };
68506292 \\ const x: @Vector(4, u32) = [4]u32{ 14, 15, 16, 17 };
68516293 \\ var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 });
68526294 \\}
6853 ,
6295 , &[_][]const u8{
68546296 "tmp.zig:4:39: error: mask index '4' has out-of-bounds selection",
68556297 "tmp.zig:4:27: note: selected index '7' out of bounds of @Vector(4, u32)",
68566298 "tmp.zig:4:30: note: selections from the second vector are specified with negative numbers",
6857 );
6299 });
68586300
6859 cases.addTest(
6860 "nested vectors",
6301 cases.addTest("nested vectors",
68616302 \\export fn entry() void {
68626303 \\ const V = @Vector(4, @Vector(4, u8));
68636304 \\ var v: V = undefined;
68646305 \\}
6865 ,
6306 , &[_][]const u8{
68666307 "tmp.zig:2:26: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid",
6867 );
6308 });
68686309
6869 cases.addTest(
6870 "bad @splat type",
6310 cases.addTest("bad @splat type",
68716311 \\export fn entry() void {
68726312 \\ const c = 4;
68736313 \\ var v = @splat(4, c);
68746314 \\}
6875 ,
6315 , &[_][]const u8{
68766316 "tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid",
6877 );
6317 });
68786318
68796319 cases.add("compileLog of tagged enum doesn't crash the compiler",
68806320 \\const Bar = union(enum(u32)) {
......@@ -6888,33 +6328,32 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
68886328 \\pub fn main () void {
68896329 \\ comptime testCompileLog(Bar{.X = 123});
68906330 \\}
6891 , "tmp.zig:6:5: error: found compile log statement");
6331 , &[_][]const u8{
6332 "tmp.zig:6:5: error: found compile log statement",
6333 });
68926334
6893 cases.add(
6894 "attempted implicit cast from *const T to *[1]T",
6335 cases.add("attempted implicit cast from *const T to *[1]T",
68956336 \\export fn entry(byte: u8) void {
68966337 \\ const w: i32 = 1234;
68976338 \\ var x: *const i32 = &w;
68986339 \\ var y: *[1]i32 = x;
68996340 \\ y[0] += 1;
69006341 \\}
6901 ,
6342 , &[_][]const u8{
69026343 "tmp.zig:4:22: error: expected type '*[1]i32', found '*const i32'",
69036344 "tmp.zig:4:22: note: cast discards const qualifier",
6904 );
6345 });
69056346
6906 cases.add(
6907 "attempted implicit cast from *const T to []T",
6347 cases.add("attempted implicit cast from *const T to []T",
69086348 \\export fn entry() void {
69096349 \\ const u: u32 = 42;
69106350 \\ const x: []u32 = &u;
69116351 \\}
6912 ,
6352 , &[_][]const u8{
69136353 "tmp.zig:3:23: error: expected type '[]u32', found '*const u32'",
6914 );
6354 });
69156355
6916 cases.add(
6917 "for loop body expression ignored",
6356 cases.add("for loop body expression ignored",
69186357 \\fn returns() usize {
69196358 \\ return 2;
69206359 \\}
......@@ -6925,37 +6364,35 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
69256364 \\ var x: anyerror!i32 = error.Bad;
69266365 \\ for ("hello") |_| returns() else unreachable;
69276366 \\}
6928 ,
6367 , &[_][]const u8{
69296368 "tmp.zig:5:30: error: expression value is ignored",
69306369 "tmp.zig:9:30: error: expression value is ignored",
6931 );
6370 });
69326371
6933 cases.add(
6934 "aligned variable of zero-bit type",
6372 cases.add("aligned variable of zero-bit type",
69356373 \\export fn f() void {
69366374 \\ var s: struct {} align(4) = undefined;
69376375 \\}
6938 ,
6376 , &[_][]const u8{
69396377 "tmp.zig:2:5: error: variable 's' of zero-bit type 'struct:2:12' has no in-memory representation, it cannot be aligned",
6940 );
6378 });
69416379
6942 cases.add(
6943 "function returning opaque type",
6380 cases.add("function returning opaque type",
69446381 \\const FooType = @OpaqueType();
69456382 \\export fn bar() !FooType {
69466383 \\ return error.InvalidValue;
69476384 \\}
6948 ,
6385 , &[_][]const u8{
69496386 "tmp.zig:2:18: error: opaque return type 'FooType' not allowed",
69506387 "tmp.zig:1:1: note: declared here",
6951 );
6388 });
69526389
69536390 cases.add( // fixed bug #2032
69546391 "compile diagnostic string for top level decl type",
69556392 \\export fn entry() void {
69566393 \\ var foo: u32 = @This(){};
69576394 \\}
6958 ,
6395 , &[_][]const u8{
69596396 "tmp.zig:2:27: error: type 'u32' does not support array initialization",
6960 );
6397 });
69616398}
test/gen_h.zig+16-16
......@@ -4,7 +4,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
44 cases.add("declare enum",
55 \\const Foo = extern enum { A, B, C };
66 \\export fn entry(foo: Foo) void { }
7 ,
7 , &[_][]const u8{
88 \\enum Foo {
99 \\ A = 0,
1010 \\ B = 1,
......@@ -12,7 +12,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
1212 \\};
1313 ,
1414 \\void entry(enum Foo foo);
15 );
15 });
1616
1717 cases.add("declare struct",
1818 \\const Foo = extern struct {
......@@ -24,7 +24,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
2424 \\ F: u64,
2525 \\};
2626 \\export fn entry(foo: Foo) void { }
27 ,
27 , &[_][]const u8{
2828 \\struct Foo {
2929 \\ int32_t A;
3030 \\ float B;
......@@ -36,7 +36,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
3636 ,
3737 \\void entry(struct Foo foo);
3838 \\
39 );
39 });
4040
4141 cases.add("declare union",
4242 \\const Big = extern struct {
......@@ -53,7 +53,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
5353 \\ D: Big,
5454 \\};
5555 \\export fn entry(foo: Foo) void {}
56 ,
56 , &[_][]const u8{
5757 \\struct Big {
5858 \\ uint64_t A;
5959 \\ uint64_t B;
......@@ -71,17 +71,17 @@ pub fn addCases(cases: *tests.GenHContext) void {
7171 ,
7272 \\void entry(union Foo foo);
7373 \\
74 );
74 });
7575
7676 cases.add("declare opaque type",
7777 \\const Foo = @OpaqueType();
7878 \\
7979 \\export fn entry(foo: ?*Foo) void { }
80 ,
80 , &[_][]const u8{
8181 \\struct Foo;
8282 ,
8383 \\void entry(struct Foo * foo);
84 );
84 });
8585
8686 cases.add("array field-type",
8787 \\const Foo = extern struct {
......@@ -89,7 +89,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
8989 \\ B: [4]*u32,
9090 \\};
9191 \\export fn entry(foo: Foo, bar: [3]u8) void { }
92 ,
92 , &[_][]const u8{
9393 \\struct Foo {
9494 \\ int32_t A[2];
9595 \\ uint32_t * B[4];
......@@ -97,7 +97,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
9797 ,
9898 \\void entry(struct Foo foo, uint8_t bar[]);
9999 \\
100 );
100 });
101101
102102 cases.add("ptr to zig struct",
103103 \\const S = struct {
......@@ -107,12 +107,12 @@ pub fn addCases(cases: *tests.GenHContext) void {
107107 \\export fn a(s: *S) u8 {
108108 \\ return s.a;
109109 \\}
110 ,
110 , &[_][]const u8{
111111 \\struct S;
112112 ,
113113 \\uint8_t a(struct S * s);
114114 \\
115 );
115 });
116116
117117 cases.add("ptr to zig union",
118118 \\const U = union(enum) {
......@@ -123,12 +123,12 @@ pub fn addCases(cases: *tests.GenHContext) void {
123123 \\export fn a(s: *U) u8 {
124124 \\ return s.A;
125125 \\}
126 ,
126 , &[_][]const u8{
127127 \\union U;
128128 ,
129129 \\uint8_t a(union U * s);
130130 \\
131 );
131 });
132132
133133 cases.add("ptr to zig enum",
134134 \\const E = enum(u8) {
......@@ -139,10 +139,10 @@ pub fn addCases(cases: *tests.GenHContext) void {
139139 \\export fn a(s: *E) u8 {
140140 \\ return @enumToInt(s.*);
141141 \\}
142 ,
142 , &[_][]const u8{
143143 \\enum E;
144144 ,
145145 \\uint8_t a(enum E * s);
146146 \\
147 );
147 });
148148}
test/stage1/behavior/eval.zig+2-2
......@@ -670,10 +670,10 @@ fn loopNTimes(comptime n: usize) void {
670670}
671671
672672test "variable inside inline loop that has different types on different iterations" {
673 testVarInsideInlineLoop(true, @as(u32, 42));
673 testVarInsideInlineLoop(.{true, @as(u32, 42)});
674674}
675675
676fn testVarInsideInlineLoop(args: ...) void {
676fn testVarInsideInlineLoop(args: var) void {
677677 comptime var i = 0;
678678 inline while (i < args.len) : (i += 1) {
679679 const x = args[i];
test/stage1/behavior/reflection.zig-2
......@@ -15,7 +15,6 @@ test "reflection: function return type, var args, and param types" {
1515 comptime {
1616 expect(@typeOf(dummy).ReturnType == i32);
1717 expect(!@typeOf(dummy).is_var_args);
18 expect(@typeOf(dummy_varargs).is_var_args);
1918 expect(@typeOf(dummy).arg_count == 3);
2019 expect(@ArgType(@typeOf(dummy), 0) == bool);
2120 expect(@ArgType(@typeOf(dummy), 1) == i32);
......@@ -26,7 +25,6 @@ test "reflection: function return type, var args, and param types" {
2625fn dummy(a: bool, b: i32, c: f32) i32 {
2726 return 1234;
2827}
29fn dummy_varargs(args: ...) void {}
3028
3129test "reflection: struct member types and names" {
3230 comptime {
test/stage1/behavior/type_info.zig+1-1
......@@ -198,7 +198,7 @@ fn testUnion() void {
198198 expect(@as(TypeId, typeinfo_info) == TypeId.Union);
199199 expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto);
200200 expect(typeinfo_info.Union.tag_type.? == TypeId);
201 expect(typeinfo_info.Union.fields.len == 26);
201 expect(typeinfo_info.Union.fields.len == 25);
202202 expect(typeinfo_info.Union.fields[4].enum_field != null);
203203 expect(typeinfo_info.Union.fields[4].enum_field.?.value == 4);
204204 expect(typeinfo_info.Union.fields[4].field_type == @typeOf(@typeInfo(u8).Int));
test/stage1/behavior/var_args.zig+26-27
......@@ -1,6 +1,6 @@
11const expect = @import("std").testing.expect;
22
3fn add(args: ...) i32 {
3fn add(args: var) i32 {
44 var sum = @as(i32, 0);
55 {
66 comptime var i: usize = 0;
......@@ -12,43 +12,42 @@ fn add(args: ...) i32 {
1212}
1313
1414test "add arbitrary args" {
15 expect(add(@as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4)) == 10);
16 expect(add(@as(i32, 1234)) == 1234);
17 expect(add() == 0);
15 expect(add(.{ @as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4) }) == 10);
16 expect(add(.{@as(i32, 1234)}) == 1234);
17 expect(add(.{}) == 0);
1818}
1919
20fn readFirstVarArg(args: ...) void {
20fn readFirstVarArg(args: var) void {
2121 const value = args[0];
2222}
2323
2424test "send void arg to var args" {
25 readFirstVarArg({});
25 readFirstVarArg(.{{}});
2626}
2727
2828test "pass args directly" {
29 expect(addSomeStuff(@as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4)) == 10);
30 expect(addSomeStuff(@as(i32, 1234)) == 1234);
31 expect(addSomeStuff() == 0);
29 expect(addSomeStuff(.{ @as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4) }) == 10);
30 expect(addSomeStuff(.{@as(i32, 1234)}) == 1234);
31 expect(addSomeStuff(.{}) == 0);
3232}
3333
34fn addSomeStuff(args: ...) i32 {
34fn addSomeStuff(args: var) i32 {
3535 return add(args);
3636}
3737
3838test "runtime parameter before var args" {
39 expect(extraFn(10) == 0);
40 expect(extraFn(10, false) == 1);
41 expect(extraFn(10, false, true) == 2);
39 expect(extraFn(10, .{}) == 0);
40 expect(extraFn(10, .{false}) == 1);
41 expect(extraFn(10, .{ false, true }) == 2);
4242
43 // TODO issue #313
44 //comptime {
45 // expect(extraFn(10) == 0);
46 // expect(extraFn(10, false) == 1);
47 // expect(extraFn(10, false, true) == 2);
48 //}
43 comptime {
44 expect(extraFn(10, .{}) == 0);
45 expect(extraFn(10, .{false}) == 1);
46 expect(extraFn(10, .{ false, true }) == 2);
47 }
4948}
5049
51fn extraFn(extra: u32, args: ...) usize {
50fn extraFn(extra: u32, args: var) usize {
5251 if (args.len >= 1) {
5352 expect(args[0] == false);
5453 }
......@@ -58,27 +57,27 @@ fn extraFn(extra: u32, args: ...) usize {
5857 return args.len;
5958}
6059
61const foos = [_]fn (...) bool{
60const foos = [_]fn (var) bool{
6261 foo1,
6362 foo2,
6463};
6564
66fn foo1(args: ...) bool {
65fn foo1(args: var) bool {
6766 return true;
6867}
69fn foo2(args: ...) bool {
68fn foo2(args: var) bool {
7069 return false;
7170}
7271
7372test "array of var args functions" {
74 expect(foos[0]());
75 expect(!foos[1]());
73 expect(foos[0](.{}));
74 expect(!foos[1](.{}));
7675}
7776
7877test "pass zero length array to var args param" {
79 doNothingWithFirstArg("");
78 doNothingWithFirstArg(.{""});
8079}
8180
82fn doNothingWithFirstArg(args: ...) void {
81fn doNothingWithFirstArg(args: var) void {
8382 const a = args[0];
8483}
test/tests.zig+89-21
......@@ -1253,7 +1253,12 @@ pub const CompileErrorContext = struct {
12531253 }
12541254 };
12551255
1256 pub fn create(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {
1256 pub fn create(
1257 self: *CompileErrorContext,
1258 name: []const u8,
1259 source: []const u8,
1260 expected_lines: []const []const u8,
1261 ) *TestCase {
12571262 const tc = self.b.allocator.create(TestCase) catch unreachable;
12581263 tc.* = TestCase{
12591264 .name = name,
......@@ -1266,31 +1271,46 @@ pub const CompileErrorContext = struct {
12661271 };
12671272
12681273 tc.addSourceFile("tmp.zig", source);
1269 comptime var arg_i = 0;
1270 inline while (arg_i < expected_lines.len) : (arg_i += 1) {
1274 var arg_i: usize = 0;
1275 while (arg_i < expected_lines.len) : (arg_i += 1) {
12711276 tc.addExpectedError(expected_lines[arg_i]);
12721277 }
12731278 return tc;
12741279 }
12751280
1276 pub fn addC(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
1281 pub fn addC(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: []const []const u8) void {
12771282 var tc = self.create(name, source, expected_lines);
12781283 tc.link_libc = true;
12791284 self.addCase(tc);
12801285 }
12811286
1282 pub fn addExe(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
1287 pub fn addExe(
1288 self: *CompileErrorContext,
1289 name: []const u8,
1290 source: []const u8,
1291 expected_lines: []const []const u8,
1292 ) void {
12831293 var tc = self.create(name, source, expected_lines);
12841294 tc.is_exe = true;
12851295 self.addCase(tc);
12861296 }
12871297
1288 pub fn add(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
1298 pub fn add(
1299 self: *CompileErrorContext,
1300 name: []const u8,
1301 source: []const u8,
1302 expected_lines: []const []const u8,
1303 ) void {
12891304 const tc = self.create(name, source, expected_lines);
12901305 self.addCase(tc);
12911306 }
12921307
1293 pub fn addTest(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void {
1308 pub fn addTest(
1309 self: *CompileErrorContext,
1310 name: []const u8,
1311 source: []const u8,
1312 expected_lines: []const []const u8,
1313 ) void {
12941314 const tc = self.create(name, source, expected_lines);
12951315 tc.is_test = true;
12961316 self.addCase(tc);
......@@ -1549,7 +1569,14 @@ pub const TranslateCContext = struct {
15491569 warn("\n", .{});
15501570 }
15511571
1552 pub fn create(self: *TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {
1572 pub fn create(
1573 self: *TranslateCContext,
1574 allow_warnings: bool,
1575 filename: []const u8,
1576 name: []const u8,
1577 source: []const u8,
1578 expected_lines: []const []const u8,
1579 ) *TestCase {
15531580 const tc = self.b.allocator.create(TestCase) catch unreachable;
15541581 tc.* = TestCase{
15551582 .name = name,
......@@ -1560,24 +1587,39 @@ pub const TranslateCContext = struct {
15601587 };
15611588
15621589 tc.addSourceFile(filename, source);
1563 comptime var arg_i = 0;
1564 inline while (arg_i < expected_lines.len) : (arg_i += 1) {
1590 var arg_i: usize = 0;
1591 while (arg_i < expected_lines.len) : (arg_i += 1) {
15651592 tc.addExpectedLine(expected_lines[arg_i]);
15661593 }
15671594 return tc;
15681595 }
15691596
1570 pub fn add(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
1597 pub fn add(
1598 self: *TranslateCContext,
1599 name: []const u8,
1600 source: []const u8,
1601 expected_lines: []const []const u8,
1602 ) void {
15711603 const tc = self.create(false, "source.h", name, source, expected_lines);
15721604 self.addCase(tc);
15731605 }
15741606
1575 pub fn addC(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
1607 pub fn addC(
1608 self: *TranslateCContext,
1609 name: []const u8,
1610 source: []const u8,
1611 expected_lines: []const []const u8,
1612 ) void {
15761613 const tc = self.create(false, "source.c", name, source, expected_lines);
15771614 self.addCase(tc);
15781615 }
15791616
1580 pub fn add_both(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
1617 pub fn add_both(
1618 self: *TranslateCContext,
1619 name: []const u8,
1620 source: []const u8,
1621 expected_lines: []const []const u8,
1622 ) void {
15811623 for ([_]bool{ false, true }) |stage2| {
15821624 const tc = self.create(false, "source.h", name, source, expected_lines);
15831625 tc.stage2 = stage2;
......@@ -1585,7 +1627,12 @@ pub const TranslateCContext = struct {
15851627 }
15861628 }
15871629
1588 pub fn addC_both(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
1630 pub fn addC_both(
1631 self: *TranslateCContext,
1632 name: []const u8,
1633 source: []const u8,
1634 expected_lines: []const []const u8,
1635 ) void {
15891636 for ([_]bool{ false, true }) |stage2| {
15901637 const tc = self.create(false, "source.c", name, source, expected_lines);
15911638 tc.stage2 = stage2;
......@@ -1593,19 +1640,34 @@ pub const TranslateCContext = struct {
15931640 }
15941641 }
15951642
1596 pub fn add_2(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
1643 pub fn add_2(
1644 self: *TranslateCContext,
1645 name: []const u8,
1646 source: []const u8,
1647 expected_lines: []const []const u8,
1648 ) void {
15971649 const tc = self.create(false, "source.h", name, source, expected_lines);
15981650 tc.stage2 = true;
15991651 self.addCase(tc);
16001652 }
16011653
1602 pub fn addC_2(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
1654 pub fn addC_2(
1655 self: *TranslateCContext,
1656 name: []const u8,
1657 source: []const u8,
1658 expected_lines: []const []const u8,
1659 ) void {
16031660 const tc = self.create(false, "source.c", name, source, expected_lines);
16041661 tc.stage2 = true;
16051662 self.addCase(tc);
16061663 }
16071664
1608 pub fn addAllowWarnings(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void {
1665 pub fn addAllowWarnings(
1666 self: *TranslateCContext,
1667 name: []const u8,
1668 source: []const u8,
1669 expected_lines: []const []const u8,
1670 ) void {
16091671 const tc = self.create(true, "source.h", name, source, expected_lines);
16101672 self.addCase(tc);
16111673 }
......@@ -1723,7 +1785,13 @@ pub const GenHContext = struct {
17231785 warn("\n", .{});
17241786 }
17251787
1726 pub fn create(self: *GenHContext, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase {
1788 pub fn create(
1789 self: *GenHContext,
1790 filename: []const u8,
1791 name: []const u8,
1792 source: []const u8,
1793 expected_lines: []const []const u8,
1794 ) *TestCase {
17271795 const tc = self.b.allocator.create(TestCase) catch unreachable;
17281796 tc.* = TestCase{
17291797 .name = name,
......@@ -1732,14 +1800,14 @@ pub const GenHContext = struct {
17321800 };
17331801
17341802 tc.addSourceFile(filename, source);
1735 comptime var arg_i = 0;
1736 inline while (arg_i < expected_lines.len) : (arg_i += 1) {
1803 var arg_i: usize = 0;
1804 while (arg_i < expected_lines.len) : (arg_i += 1) {
17371805 tc.addExpectedLine(expected_lines[arg_i]);
17381806 }
17391807 return tc;
17401808 }
17411809
1742 pub fn add(self: *GenHContext, name: []const u8, source: []const u8, expected_lines: ...) void {
1810 pub fn add(self: *GenHContext, name: []const u8, source: []const u8, expected_lines: []const []const u8) void {
17431811 const tc = self.create("test.zig", name, source, expected_lines);
17441812 self.addCase(tc);
17451813 }
test/translate_c.zig+242-226
......@@ -13,10 +13,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
1313 cases.add_both("simple function prototypes",
1414 \\void __attribute__((noreturn)) foo(void);
1515 \\int bar(void);
16 ,
16 , &[_][]const u8{
1717 \\pub extern fn foo() noreturn;
1818 \\pub extern fn bar() c_int;
19 );
19 });
2020
2121 cases.add_both("simple var decls",
2222 \\void foo(void) {
......@@ -25,14 +25,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
2525 \\ const int c;
2626 \\ const unsigned d = 440;
2727 \\}
28 ,
28 , &[_][]const u8{
2929 \\pub fn foo() void {
3030 \\ var a: c_int = undefined;
3131 \\ var b: u8 = @as(u8, 123);
3232 \\ const c: c_int = undefined;
3333 \\ const d: c_uint = @as(c_uint, 440);
3434 \\}
35 );
35 });
3636
3737 cases.add_both("ignore result, explicit function arguments",
3838 \\void foo(void) {
......@@ -43,7 +43,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
4343 \\ 1 - 1;
4444 \\ a = 1;
4545 \\}
46 ,
46 , &[_][]const u8{
4747 \\pub fn foo() void {
4848 \\ var a: c_int = undefined;
4949 \\ _ = 1;
......@@ -52,7 +52,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
5252 \\ _ = (1 - 1);
5353 \\ a = 1;
5454 \\}
55 );
55 });
5656
5757 /////////////// Cases that pass for only stage2 ////////////////
5858 // TODO: restore these tests after removing "import mode" concept
......@@ -83,12 +83,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
8383 \\void b(void) {}
8484 \\void c();
8585 \\void d(void);
86 ,
86 , &[_][]const u8{
8787 \\pub fn a(...) void {}
8888 \\pub fn b() void {}
8989 \\pub extern fn c(...) void;
9090 \\pub extern fn d() void;
91 );
91 });
9292
9393 /////////////// Cases for only stage1 which are TODO items for stage2 ////////////////
9494
......@@ -98,13 +98,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
9898 \\ void (*func)(void);
9999 \\ lws_callback_function *callback_http;
100100 \\};
101 ,
101 , &[_][]const u8{
102102 \\pub const lws_callback_function = extern fn () void;
103103 \\pub const struct_Foo = extern struct {
104104 \\ func: ?extern fn () void,
105105 \\ callback_http: ?lws_callback_function,
106106 \\};
107 );
107 });
108108
109109 cases.add("pointer to struct demoted to opaque due to bit fields",
110110 \\struct Foo {
......@@ -113,26 +113,26 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
113113 \\struct Bar {
114114 \\ struct Foo *foo;
115115 \\};
116 ,
116 , &[_][]const u8{
117117 \\pub const struct_Foo = @OpaqueType();
118118 \\pub const struct_Bar = extern struct {
119119 \\ foo: ?*struct_Foo,
120120 \\};
121 );
121 });
122122
123123 cases.add_both("simple function definition",
124124 \\void foo(void) {}
125125 \\static void bar(void) {}
126 ,
126 , &[_][]const u8{
127127 \\pub fn foo() void {}
128128 \\pub fn bar() void {}
129 );
129 });
130130
131131 cases.add("macro with left shift",
132132 \\#define REDISMODULE_READ (1<<0)
133 ,
133 , &[_][]const u8{
134134 \\pub const REDISMODULE_READ = 1 << 0;
135 );
135 });
136136
137137 cases.add_both("casting pointers to ints and ints to pointers",
138138 \\void foo(void);
......@@ -140,13 +140,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
140140 \\ void *func_ptr = foo;
141141 \\ void (*typed_func_ptr)(void) = (void (*)(void)) (unsigned long) func_ptr;
142142 \\}
143 ,
143 , &[_][]const u8{
144144 \\pub extern fn foo() void;
145145 \\pub fn bar() void {
146146 \\ var func_ptr: ?*c_void = @ptrCast(?*c_void, foo);
147147 \\ var typed_func_ptr: ?extern fn () void = @intToPtr(?extern fn () void, @as(c_ulong, @ptrToInt(func_ptr)));
148148 \\}
149 );
149 });
150150
151151 if (builtin.os != builtin.Os.windows) {
152152 // Windows treats this as an enum with type c_int
......@@ -176,7 +176,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
176176 \\ VAL22 = 0xFFFFFFFFFFFFFFFF + 1,
177177 \\ VAL23 = 0xFFFFFFFFFFFFFFFF,
178178 \\};
179 ,
179 , &[_][]const u8{
180180 \\pub const enum_EnumWithInits = extern enum(c_longlong) {
181181 \\ VAL01 = 0,
182182 \\ VAL02 = 1,
......@@ -202,7 +202,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
202202 \\ VAL22 = 0,
203203 \\ VAL23 = -1,
204204 \\};
205 );
205 });
206206 }
207207
208208 cases.add("predefined expressions",
......@@ -211,13 +211,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
211211 \\ __FUNCTION__;
212212 \\ __PRETTY_FUNCTION__;
213213 \\}
214 ,
214 , &[_][]const u8{
215215 \\pub fn foo() void {
216216 \\ _ = "foo";
217217 \\ _ = "foo";
218218 \\ _ = "void foo(void)";
219219 \\}
220 );
220 });
221221
222222 cases.add("ignore result, no function arguments",
223223 \\void foo() {
......@@ -228,7 +228,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
228228 \\ 1 - 1;
229229 \\ a = 1;
230230 \\}
231 ,
231 , &[_][]const u8{
232232 \\pub fn foo() void {
233233 \\ var a: c_int = undefined;
234234 \\ _ = 1;
......@@ -237,53 +237,53 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
237237 \\ _ = (1 - 1);
238238 \\ a = 1;
239239 \\}
240 );
240 });
241241
242242 cases.add("for loop with var init but empty body",
243243 \\void foo(void) {
244244 \\ for (int x = 0; x < 10; x++);
245245 \\}
246 ,
246 , &[_][]const u8{
247247 \\pub fn foo() void {
248248 \\ {
249249 \\ var x: c_int = 0;
250250 \\ while (x < 10) : (x += 1) {}
251251 \\ }
252252 \\}
253 );
253 });
254254
255255 cases.add("do while with empty body",
256256 \\void foo(void) {
257257 \\ do ; while (1);
258258 \\}
259 , // TODO this should be if (1 != 0) break
259 , &[_][]const u8{ // TODO this should be if (1 != 0) break
260260 \\pub fn foo() void {
261261 \\ while (true) {
262262 \\ {}
263263 \\ if (!1) break;
264264 \\ }
265265 \\}
266 );
266 });
267267
268268 cases.add("for with empty body",
269269 \\void foo(void) {
270270 \\ for (;;);
271271 \\}
272 ,
272 , &[_][]const u8{
273273 \\pub fn foo() void {
274274 \\ while (true) {}
275275 \\}
276 );
276 });
277277
278278 cases.add("while with empty body",
279279 \\void foo(void) {
280280 \\ while (1);
281281 \\}
282 ,
282 , &[_][]const u8{
283283 \\pub fn foo() void {
284284 \\ while (1 != 0) {}
285285 \\}
286 );
286 });
287287
288288 cases.add("double define struct",
289289 \\typedef struct Bar Bar;
......@@ -296,7 +296,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
296296 \\struct Bar {
297297 \\ Foo *a;
298298 \\};
299 ,
299 , &[_][]const u8{
300300 \\pub const struct_Foo = extern struct {
301301 \\ a: [*c]Foo,
302302 \\};
......@@ -304,7 +304,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
304304 \\pub const struct_Bar = extern struct {
305305 \\ a: [*c]Foo,
306306 \\};
307 );
307 });
308308
309309 cases.addAllowWarnings("simple data types",
310310 \\#include <stdint.h>
......@@ -312,29 +312,29 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
312312 \\int foo(char a, unsigned char b, signed char c); // test a duplicate prototype
313313 \\void bar(uint8_t a, uint16_t b, uint32_t c, uint64_t d);
314314 \\void baz(int8_t a, int16_t b, int32_t c, int64_t d);
315 ,
315 , &[_][]const u8{
316316 \\pub extern fn foo(a: u8, b: u8, c: i8) c_int;
317317 ,
318318 \\pub extern fn bar(a: u8, b: u16, c: u32, d: u64) void;
319319 ,
320320 \\pub extern fn baz(a: i8, b: i16, c: i32, d: i64) void;
321 );
321 });
322322
323323 cases.add_both("noreturn attribute",
324324 \\void foo(void) __attribute__((noreturn));
325 ,
325 , &[_][]const u8{
326326 \\pub extern fn foo() noreturn;
327 );
327 });
328328
329329 cases.addC("simple function",
330330 \\int abs(int a) {
331331 \\ return a < 0 ? -a : a;
332332 \\}
333 ,
333 , &[_][]const u8{
334334 \\export fn abs(a: c_int) c_int {
335335 \\ return if (a < 0) -a else a;
336336 \\}
337 );
337 });
338338
339339 cases.add("enums",
340340 \\enum Foo {
......@@ -342,7 +342,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
342342 \\ FooB,
343343 \\ Foo1,
344344 \\};
345 ,
345 , &[_][]const u8{
346346 \\pub const enum_Foo = extern enum {
347347 \\ A,
348348 \\ B,
......@@ -356,7 +356,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
356356 \\pub const Foo1 = enum_Foo.@"1";
357357 ,
358358 \\pub const Foo = enum_Foo;
359 );
359 });
360360
361361 cases.add("enums",
362362 \\enum Foo {
......@@ -364,7 +364,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
364364 \\ FooB = 5,
365365 \\ Foo1,
366366 \\};
367 ,
367 , &[_][]const u8{
368368 \\pub const enum_Foo = extern enum {
369369 \\ A = 2,
370370 \\ B = 5,
......@@ -378,27 +378,27 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
378378 \\pub const Foo1 = enum_Foo.@"1";
379379 ,
380380 \\pub const Foo = enum_Foo;
381 );
381 });
382382
383383 cases.add("restrict -> noalias",
384384 \\void foo(void *restrict bar, void *restrict);
385 ,
385 , &[_][]const u8{
386386 \\pub extern fn foo(noalias bar: ?*c_void, noalias arg1: ?*c_void) void;
387 );
387 });
388388
389389 cases.add("simple struct",
390390 \\struct Foo {
391391 \\ int x;
392392 \\ char *y;
393393 \\};
394 ,
394 , &[_][]const u8{
395395 \\const struct_Foo = extern struct {
396396 \\ x: c_int,
397397 \\ y: [*c]u8,
398398 \\};
399399 ,
400400 \\pub const Foo = struct_Foo;
401 );
401 });
402402
403403 cases.add("qualified struct and enum",
404404 \\struct Foo {
......@@ -410,7 +410,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
410410 \\ BarB,
411411 \\};
412412 \\void func(struct Foo *a, enum Bar **b);
413 ,
413 , &[_][]const u8{
414414 \\pub const struct_Foo = extern struct {
415415 \\ x: c_int,
416416 \\ y: c_int,
......@@ -430,66 +430,66 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
430430 \\pub const Foo = struct_Foo;
431431 ,
432432 \\pub const Bar = enum_Bar;
433 );
433 });
434434
435435 cases.add("constant size array",
436436 \\void func(int array[20]);
437 ,
437 , &[_][]const u8{
438438 \\pub extern fn func(array: [*c]c_int) void;
439 );
439 });
440440
441441 cases.add("self referential struct with function pointer",
442442 \\struct Foo {
443443 \\ void (*derp)(struct Foo *foo);
444444 \\};
445 ,
445 , &[_][]const u8{
446446 \\pub const struct_Foo = extern struct {
447447 \\ derp: ?extern fn ([*c]struct_Foo) void,
448448 \\};
449449 ,
450450 \\pub const Foo = struct_Foo;
451 );
451 });
452452
453453 cases.add("struct prototype used in func",
454454 \\struct Foo;
455455 \\struct Foo *some_func(struct Foo *foo, int x);
456 ,
456 , &[_][]const u8{
457457 \\pub const struct_Foo = @OpaqueType();
458458 ,
459459 \\pub extern fn some_func(foo: ?*struct_Foo, x: c_int) ?*struct_Foo;
460460 ,
461461 \\pub const Foo = struct_Foo;
462 );
462 });
463463
464464 cases.add("#define a char literal",
465465 \\#define A_CHAR 'a'
466 ,
466 , &[_][]const u8{
467467 \\pub const A_CHAR = 97;
468 );
468 });
469469
470470 cases.add("#define an unsigned integer literal",
471471 \\#define CHANNEL_COUNT 24
472 ,
472 , &[_][]const u8{
473473 \\pub const CHANNEL_COUNT = 24;
474 );
474 });
475475
476476 cases.add("#define referencing another #define",
477477 \\#define THING2 THING1
478478 \\#define THING1 1234
479 ,
479 , &[_][]const u8{
480480 \\pub const THING1 = 1234;
481481 ,
482482 \\pub const THING2 = THING1;
483 );
483 });
484484
485485 cases.add("variables",
486486 \\extern int extern_var;
487487 \\static const int int_var = 13;
488 ,
488 , &[_][]const u8{
489489 \\pub extern var extern_var: c_int;
490490 ,
491491 \\pub const int_var: c_int = 13;
492 );
492 });
493493
494494 cases.add("circular struct definitions",
495495 \\struct Bar;
......@@ -501,7 +501,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
501501 \\struct Bar {
502502 \\ struct Foo *next;
503503 \\};
504 ,
504 , &[_][]const u8{
505505 \\pub const struct_Bar = extern struct {
506506 \\ next: [*c]struct_Foo,
507507 \\};
......@@ -509,16 +509,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
509509 \\pub const struct_Foo = extern struct {
510510 \\ next: [*c]struct_Bar,
511511 \\};
512 );
512 });
513513
514514 cases.add("typedef void",
515515 \\typedef void Foo;
516516 \\Foo fun(Foo *a);
517 ,
517 , &[_][]const u8{
518518 \\pub const Foo = c_void;
519519 ,
520520 \\pub extern fn fun(a: ?*Foo) Foo;
521 );
521 });
522522
523523 cases.add("generate inline func for #define global extern fn",
524524 \\extern void (*fn_ptr)(void);
......@@ -526,7 +526,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
526526 \\
527527 \\extern char (*fn_ptr2)(int, float);
528528 \\#define bar fn_ptr2
529 ,
529 , &[_][]const u8{
530530 \\pub extern var fn_ptr: ?extern fn () void;
531531 ,
532532 \\pub inline fn foo() void {
......@@ -538,109 +538,109 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
538538 \\pub inline fn bar(arg0: c_int, arg1: f32) u8 {
539539 \\ return fn_ptr2.?(arg0, arg1);
540540 \\}
541 );
541 });
542542
543543 cases.add("#define string",
544544 \\#define foo "a string"
545 ,
545 , &[_][]const u8{
546546 \\pub const foo = "a string";
547 );
547 });
548548
549549 cases.add("__cdecl doesn't mess up function pointers",
550550 \\void foo(void (__cdecl *fn_ptr)(void));
551 ,
551 , &[_][]const u8{
552552 \\pub extern fn foo(fn_ptr: ?extern fn () void) void;
553 );
553 });
554554
555555 cases.add("comment after integer literal",
556556 \\#define SDL_INIT_VIDEO 0x00000020 /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
557 ,
557 , &[_][]const u8{
558558 \\pub const SDL_INIT_VIDEO = 32;
559 );
559 });
560560
561561 cases.add("u integer suffix after hex literal",
562562 \\#define SDL_INIT_VIDEO 0x00000020u /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
563 ,
563 , &[_][]const u8{
564564 \\pub const SDL_INIT_VIDEO = @as(c_uint, 32);
565 );
565 });
566566
567567 cases.add("l integer suffix after hex literal",
568568 \\#define SDL_INIT_VIDEO 0x00000020l /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
569 ,
569 , &[_][]const u8{
570570 \\pub const SDL_INIT_VIDEO = @as(c_long, 32);
571 );
571 });
572572
573573 cases.add("ul integer suffix after hex literal",
574574 \\#define SDL_INIT_VIDEO 0x00000020ul /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
575 ,
575 , &[_][]const u8{
576576 \\pub const SDL_INIT_VIDEO = @as(c_ulong, 32);
577 );
577 });
578578
579579 cases.add("lu integer suffix after hex literal",
580580 \\#define SDL_INIT_VIDEO 0x00000020lu /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
581 ,
581 , &[_][]const u8{
582582 \\pub const SDL_INIT_VIDEO = @as(c_ulong, 32);
583 );
583 });
584584
585585 cases.add("ll integer suffix after hex literal",
586586 \\#define SDL_INIT_VIDEO 0x00000020ll /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
587 ,
587 , &[_][]const u8{
588588 \\pub const SDL_INIT_VIDEO = @as(c_longlong, 32);
589 );
589 });
590590
591591 cases.add("ull integer suffix after hex literal",
592592 \\#define SDL_INIT_VIDEO 0x00000020ull /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
593 ,
593 , &[_][]const u8{
594594 \\pub const SDL_INIT_VIDEO = @as(c_ulonglong, 32);
595 );
595 });
596596
597597 cases.add("llu integer suffix after hex literal",
598598 \\#define SDL_INIT_VIDEO 0x00000020llu /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */
599 ,
599 , &[_][]const u8{
600600 \\pub const SDL_INIT_VIDEO = @as(c_ulonglong, 32);
601 );
601 });
602602
603603 cases.add("zig keywords in C code",
604604 \\struct comptime {
605605 \\ int defer;
606606 \\};
607 ,
607 , &[_][]const u8{
608608 \\pub const struct_comptime = extern struct {
609609 \\ @"defer": c_int,
610610 \\};
611611 ,
612612 \\pub const @"comptime" = struct_comptime;
613 );
613 });
614614
615615 cases.add("macro defines string literal with hex",
616616 \\#define FOO "aoeu\xab derp"
617617 \\#define FOO2 "aoeu\x0007a derp"
618618 \\#define FOO_CHAR '\xfF'
619 ,
619 , &[_][]const u8{
620620 \\pub const FOO = "aoeu\xab derp";
621621 ,
622622 \\pub const FOO2 = "aoeuz derp";
623623 ,
624624 \\pub const FOO_CHAR = 255;
625 );
625 });
626626
627627 cases.add("macro defines string literal with octal",
628628 \\#define FOO "aoeu\023 derp"
629629 \\#define FOO2 "aoeu\0234 derp"
630630 \\#define FOO_CHAR '\077'
631 ,
631 , &[_][]const u8{
632632 \\pub const FOO = "aoeu\x13 derp";
633633 ,
634634 \\pub const FOO2 = "aoeu\x134 derp";
635635 ,
636636 \\pub const FOO_CHAR = 63;
637 );
637 });
638638
639639 cases.add("macro with parens around negative number",
640640 \\#define LUA_GLOBALSINDEX (-10002)
641 ,
641 , &[_][]const u8{
642642 \\pub const LUA_GLOBALSINDEX = -10002;
643 );
643 });
644644
645645 cases.addC("post increment",
646646 \\unsigned foo1(unsigned a) {
......@@ -651,7 +651,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
651651 \\ a++;
652652 \\ return a;
653653 \\}
654 ,
654 , &[_][]const u8{
655655 \\pub export fn foo1(_arg_a: c_uint) c_uint {
656656 \\ var a = _arg_a;
657657 \\ a +%= 1;
......@@ -662,7 +662,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
662662 \\ a += 1;
663663 \\ return a;
664664 \\}
665 );
665 });
666666
667667 cases.addC("shift right assign",
668668 \\int log2(unsigned a) {
......@@ -672,7 +672,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
672672 \\ }
673673 \\ return i;
674674 \\}
675 ,
675 , &[_][]const u8{
676676 \\pub export fn log2(_arg_a: c_uint) c_int {
677677 \\ var a = _arg_a;
678678 \\ var i: c_int = 0;
......@@ -681,7 +681,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
681681 \\ }
682682 \\ return i;
683683 \\}
684 );
684 });
685685
686686 cases.addC("if statement",
687687 \\int max(int a, int b) {
......@@ -695,13 +695,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
695695 \\
696696 \\ if (a < b) ; else ;
697697 \\}
698 ,
698 , &[_][]const u8{
699699 \\pub export fn max(a: c_int, b: c_int) c_int {
700700 \\ if (a < b) return b;
701701 \\ if (a < b) return b else return a;
702702 \\ if (a < b) {} else {}
703703 \\}
704 );
704 });
705705
706706 cases.addC("==, !=",
707707 \\int max(int a, int b) {
......@@ -711,13 +711,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
711711 \\ return b;
712712 \\ return a;
713713 \\}
714 ,
714 , &[_][]const u8{
715715 \\pub export fn max(a: c_int, b: c_int) c_int {
716716 \\ if (a == b) return a;
717717 \\ if (a != b) return b;
718718 \\ return a;
719719 \\}
720 );
720 });
721721
722722 cases.addC("add, sub, mul, div, rem",
723723 \\int s(int a, int b) {
......@@ -736,7 +736,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
736736 \\ c = a / b;
737737 \\ c = a % b;
738738 \\}
739 ,
739 , &[_][]const u8{
740740 \\pub export fn s(a: c_int, b: c_int) c_int {
741741 \\ var c: c_int = undefined;
742742 \\ c = (a + b);
......@@ -753,17 +753,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
753753 \\ c = (a / b);
754754 \\ c = (a % b);
755755 \\}
756 );
756 });
757757
758758 cases.addC("bitwise binary operators",
759759 \\int max(int a, int b) {
760760 \\ return (a & b) ^ (a | b);
761761 \\}
762 ,
762 , &[_][]const u8{
763763 \\pub export fn max(a: c_int, b: c_int) c_int {
764764 \\ return (a & b) ^ (a | b);
765765 \\}
766 );
766 });
767767
768768 cases.addC("logical and, logical or",
769769 \\int max(int a, int b) {
......@@ -773,13 +773,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
773773 \\ return a;
774774 \\ return a;
775775 \\}
776 ,
776 , &[_][]const u8{
777777 \\pub export fn max(a: c_int, b: c_int) c_int {
778778 \\ if ((a < b) or (a == b)) return b;
779779 \\ if ((a >= b) and (a == b)) return a;
780780 \\ return a;
781781 \\}
782 );
782 });
783783
784784 cases.addC("logical and, logical or on none bool values",
785785 \\int and_or_none_bool(int a, float b, void *c) {
......@@ -791,7 +791,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
791791 \\ if (a || c) return 5;
792792 \\ return 6;
793793 \\}
794 ,
794 , &[_][]const u8{
795795 \\pub export fn and_or_none_bool(a: c_int, b: f32, c: ?*c_void) c_int {
796796 \\ if ((a != 0) and (b != 0)) return 0;
797797 \\ if ((b != 0) and (c != null)) return 1;
......@@ -801,7 +801,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
801801 \\ if ((a != 0) or (c != null)) return 5;
802802 \\ return 6;
803803 \\}
804 );
804 });
805805
806806 cases.addC("assign",
807807 \\int max(int a) {
......@@ -809,21 +809,21 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
809809 \\ tmp = a;
810810 \\ a = tmp;
811811 \\}
812 ,
812 , &[_][]const u8{
813813 \\pub export fn max(_arg_a: c_int) c_int {
814814 \\ var a = _arg_a;
815815 \\ var tmp: c_int = undefined;
816816 \\ tmp = a;
817817 \\ a = tmp;
818818 \\}
819 );
819 });
820820
821821 cases.addC("chaining assign",
822822 \\void max(int a) {
823823 \\ int b, c;
824824 \\ c = b = a;
825825 \\}
826 ,
826 , &[_][]const u8{
827827 \\pub export fn max(a: c_int) void {
828828 \\ var b: c_int = undefined;
829829 \\ var c: c_int = undefined;
......@@ -833,7 +833,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
833833 \\ break :x _tmp;
834834 \\ });
835835 \\}
836 );
836 });
837837
838838 cases.addC("shift right assign with a fixed size type",
839839 \\#include <stdint.h>
......@@ -844,7 +844,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
844844 \\ }
845845 \\ return i;
846846 \\}
847 ,
847 , &[_][]const u8{
848848 \\pub export fn log2(_arg_a: u32) c_int {
849849 \\ var a = _arg_a;
850850 \\ var i: c_int = 0;
......@@ -853,17 +853,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
853853 \\ }
854854 \\ return i;
855855 \\}
856 );
856 });
857857
858858 cases.add("anonymous enum",
859859 \\enum {
860860 \\ One,
861861 \\ Two,
862862 \\};
863 ,
863 , &[_][]const u8{
864864 \\pub const One = 0;
865865 \\pub const Two = 1;
866 );
866 });
867867
868868 cases.addC("function call",
869869 \\static void bar(void) { }
......@@ -872,7 +872,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
872872 \\ bar();
873873 \\ baz();
874874 \\}
875 ,
875 , &[_][]const u8{
876876 \\pub fn bar() void {}
877877 \\pub fn baz() c_int {
878878 \\ return 0;
......@@ -881,7 +881,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
881881 \\ bar();
882882 \\ _ = baz();
883883 \\}
884 );
884 });
885885
886886 cases.addC("field access expression",
887887 \\struct Foo {
......@@ -890,20 +890,20 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
890890 \\int read_field(struct Foo *foo) {
891891 \\ return foo->field;
892892 \\}
893 ,
893 , &[_][]const u8{
894894 \\pub const struct_Foo = extern struct {
895895 \\ field: c_int,
896896 \\};
897897 \\pub export fn read_field(foo: [*c]struct_Foo) c_int {
898898 \\ return foo.*.field;
899899 \\}
900 );
900 });
901901
902902 cases.addC("null statements",
903903 \\void foo(void) {
904904 \\ ;;;;;
905905 \\}
906 ,
906 , &[_][]const u8{
907907 \\pub export fn foo() void {
908908 \\ {}
909909 \\ {}
......@@ -911,89 +911,89 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
911911 \\ {}
912912 \\ {}
913913 \\}
914 );
914 });
915915
916916 cases.add("undefined array global",
917917 \\int array[100];
918 ,
918 , &[_][]const u8{
919919 \\pub var array: [100]c_int = undefined;
920 );
920 });
921921
922922 cases.addC("array access",
923923 \\int array[100];
924924 \\int foo(int index) {
925925 \\ return array[index];
926926 \\}
927 ,
927 , &[_][]const u8{
928928 \\pub var array: [100]c_int = undefined;
929929 \\pub export fn foo(index: c_int) c_int {
930930 \\ return array[index];
931931 \\}
932 );
932 });
933933
934934 cases.addC("c style cast",
935935 \\int float_to_int(float a) {
936936 \\ return (int)a;
937937 \\}
938 ,
938 , &[_][]const u8{
939939 \\pub export fn float_to_int(a: f32) c_int {
940940 \\ return @as(c_int, a);
941941 \\}
942 );
942 });
943943
944944 cases.addC("void cast",
945945 \\void foo(int a) {
946946 \\ (void) a;
947947 \\}
948 ,
948 , &[_][]const u8{
949949 \\pub export fn foo(a: c_int) void {
950950 \\ _ = a;
951951 \\}
952 );
952 });
953953
954954 cases.addC("implicit cast to void *",
955955 \\void *foo(unsigned short *x) {
956956 \\ return x;
957957 \\}
958 ,
958 , &[_][]const u8{
959959 \\pub export fn foo(x: [*c]c_ushort) ?*c_void {
960960 \\ return @ptrCast(?*c_void, x);
961961 \\}
962 );
962 });
963963
964964 cases.addC("sizeof",
965965 \\#include <stddef.h>
966966 \\size_t size_of(void) {
967967 \\ return sizeof(int);
968968 \\}
969 ,
969 , &[_][]const u8{
970970 \\pub export fn size_of() usize {
971971 \\ return @sizeOf(c_int);
972972 \\}
973 );
973 });
974974
975975 cases.addC("null pointer implicit cast",
976976 \\int* foo(void) {
977977 \\ return 0;
978978 \\}
979 ,
979 , &[_][]const u8{
980980 \\pub export fn foo() [*c]c_int {
981981 \\ return null;
982982 \\}
983 );
983 });
984984
985985 cases.addC("comma operator",
986986 \\int foo(void) {
987987 \\ return 1, 2;
988988 \\}
989 ,
989 , &[_][]const u8{
990990 \\pub export fn foo() c_int {
991991 \\ return x: {
992992 \\ _ = 1;
993993 \\ break :x 2;
994994 \\ };
995995 \\}
996 );
996 });
997997
998998 cases.addC("statement expression",
999999 \\int foo(void) {
......@@ -1002,34 +1002,34 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
10021002 \\ a;
10031003 \\ });
10041004 \\}
1005 ,
1005 , &[_][]const u8{
10061006 \\pub export fn foo() c_int {
10071007 \\ return x: {
10081008 \\ var a: c_int = 1;
10091009 \\ break :x a;
10101010 \\ };
10111011 \\}
1012 );
1012 });
10131013
10141014 cases.addC("__extension__ cast",
10151015 \\int foo(void) {
10161016 \\ return __extension__ 1;
10171017 \\}
1018 ,
1018 , &[_][]const u8{
10191019 \\pub export fn foo() c_int {
10201020 \\ return 1;
10211021 \\}
1022 );
1022 });
10231023
10241024 cases.addC("bitshift",
10251025 \\int foo(void) {
10261026 \\ return (1 << 2) >> 1;
10271027 \\}
1028 ,
1028 , &[_][]const u8{
10291029 \\pub export fn foo() c_int {
10301030 \\ return (1 << @as(@import("std").math.Log2Int(c_int), 2)) >> @as(@import("std").math.Log2Int(c_int), 1);
10311031 \\}
1032 );
1032 });
10331033
10341034 cases.addC("compound assignment operators",
10351035 \\void foo(void) {
......@@ -1043,7 +1043,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
10431043 \\ a >>= (a >>= 1);
10441044 \\ a <<= (a <<= 1);
10451045 \\}
1046 ,
1046 , &[_][]const u8{
10471047 \\pub export fn foo() void {
10481048 \\ var a: c_int = 0;
10491049 \\ a += (x: {
......@@ -1087,7 +1087,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
10871087 \\ break :x _ref.*;
10881088 \\ }));
10891089 \\}
1090 );
1090 });
10911091
10921092 cases.addC("compound assignment operators unsigned",
10931093 \\void foo(void) {
......@@ -1101,7 +1101,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
11011101 \\ a >>= (a >>= 1);
11021102 \\ a <<= (a <<= 1);
11031103 \\}
1104 ,
1104 , &[_][]const u8{
11051105 \\pub export fn foo() void {
11061106 \\ var a: c_uint = @as(c_uint, 0);
11071107 \\ a +%= (x: {
......@@ -1145,18 +1145,18 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
11451145 \\ break :x _ref.*;
11461146 \\ }));
11471147 \\}
1148 );
1148 });
11491149
11501150 cases.addC("duplicate typedef",
11511151 \\typedef long foo;
11521152 \\typedef int bar;
11531153 \\typedef long foo;
11541154 \\typedef int baz;
1155 ,
1155 , &[_][]const u8{
11561156 \\pub const foo = c_long;
11571157 \\pub const bar = c_int;
11581158 \\pub const baz = c_int;
1159 );
1159 });
11601160
11611161 cases.addC("post increment/decrement",
11621162 \\void foo(void) {
......@@ -1171,7 +1171,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
11711171 \\ u = u++;
11721172 \\ u = u--;
11731173 \\}
1174 ,
1174 , &[_][]const u8{
11751175 \\pub export fn foo() void {
11761176 \\ var i: c_int = 0;
11771177 \\ var u: c_uint = @as(c_uint, 0);
......@@ -1204,7 +1204,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
12041204 \\ break :x _tmp;
12051205 \\ });
12061206 \\}
1207 );
1207 });
12081208
12091209 cases.addC("pre increment/decrement",
12101210 \\void foo(void) {
......@@ -1219,7 +1219,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
12191219 \\ u = ++u;
12201220 \\ u = --u;
12211221 \\}
1222 ,
1222 , &[_][]const u8{
12231223 \\pub export fn foo() void {
12241224 \\ var i: c_int = 0;
12251225 \\ var u: c_uint = @as(c_uint, 0);
......@@ -1248,7 +1248,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
12481248 \\ break :x _ref.*;
12491249 \\ });
12501250 \\}
1251 );
1251 });
12521252
12531253 cases.addC("do loop",
12541254 \\void foo(void) {
......@@ -1262,7 +1262,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
12621262 \\ b--;
12631263 \\ while (b != 0);
12641264 \\}
1265 ,
1265 , &[_][]const u8{
12661266 \\pub export fn foo() void {
12671267 \\ var a: c_int = 2;
12681268 \\ while (true) {
......@@ -1275,7 +1275,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
12751275 \\ if (!(b != 0)) break;
12761276 \\ }
12771277 \\}
1278 );
1278 });
12791279
12801280 cases.addC("deref function pointer",
12811281 \\void foo(void) {}
......@@ -1290,7 +1290,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
12901290 \\ (*(b))();
12911291 \\ baz();
12921292 \\}
1293 ,
1293 , &[_][]const u8{
12941294 \\pub export fn foo() void {}
12951295 \\pub export fn baz() c_int {
12961296 \\ return 0;
......@@ -1305,31 +1305,31 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
13051305 \\ _ = b.?();
13061306 \\ _ = baz();
13071307 \\}
1308 );
1308 });
13091309
13101310 cases.addC("normal deref",
13111311 \\void foo(int *x) {
13121312 \\ *x = 1;
13131313 \\}
1314 ,
1314 , &[_][]const u8{
13151315 \\pub export fn foo(x: [*c]c_int) void {
13161316 \\ x.?.* = 1;
13171317 \\}
1318 );
1318 });
13191319
13201320 cases.add("simple union",
13211321 \\union Foo {
13221322 \\ int x;
13231323 \\ double y;
13241324 \\};
1325 ,
1325 , &[_][]const u8{
13261326 \\pub const union_Foo = extern union {
13271327 \\ x: c_int,
13281328 \\ y: f64,
13291329 \\};
13301330 ,
13311331 \\pub const Foo = union_Foo;
1332 );
1332 });
13331333
13341334 cases.add("address of operator",
13351335 \\int foo(void) {
......@@ -1337,56 +1337,56 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
13371337 \\ int *ptr = &x;
13381338 \\ return *ptr;
13391339 \\}
1340 ,
1340 , &[_][]const u8{
13411341 \\pub fn foo() c_int {
13421342 \\ var x: c_int = 1234;
13431343 \\ var ptr: [*c]c_int = &x;
13441344 \\ return ptr.?.*;
13451345 \\}
1346 );
1346 });
13471347
13481348 cases.add("string literal",
13491349 \\const char *foo(void) {
13501350 \\ return "bar";
13511351 \\}
1352 ,
1352 , &[_][]const u8{
13531353 \\pub fn foo() [*c]const u8 {
13541354 \\ return "bar";
13551355 \\}
1356 );
1356 });
13571357
13581358 cases.add("return void",
13591359 \\void foo(void) {
13601360 \\ return;
13611361 \\}
1362 ,
1362 , &[_][]const u8{
13631363 \\pub fn foo() void {
13641364 \\ return;
13651365 \\}
1366 );
1366 });
13671367
13681368 cases.add("for loop",
13691369 \\void foo(void) {
13701370 \\ for (int i = 0; i < 10; i += 1) { }
13711371 \\}
1372 ,
1372 , &[_][]const u8{
13731373 \\pub fn foo() void {
13741374 \\ {
13751375 \\ var i: c_int = 0;
13761376 \\ while (i < 10) : (i += 1) {}
13771377 \\ }
13781378 \\}
1379 );
1379 });
13801380
13811381 cases.add("empty for loop",
13821382 \\void foo(void) {
13831383 \\ for (;;) { }
13841384 \\}
1385 ,
1385 , &[_][]const u8{
13861386 \\pub fn foo() void {
13871387 \\ while (true) {}
13881388 \\}
1389 );
1389 });
13901390
13911391 cases.add("break statement",
13921392 \\void foo(void) {
......@@ -1394,13 +1394,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
13941394 \\ break;
13951395 \\ }
13961396 \\}
1397 ,
1397 , &[_][]const u8{
13981398 \\pub fn foo() void {
13991399 \\ while (true) {
14001400 \\ break;
14011401 \\ }
14021402 \\}
1403 );
1403 });
14041404
14051405 cases.add("continue statement",
14061406 \\void foo(void) {
......@@ -1408,13 +1408,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
14081408 \\ continue;
14091409 \\ }
14101410 \\}
1411 ,
1411 , &[_][]const u8{
14121412 \\pub fn foo() void {
14131413 \\ while (true) {
14141414 \\ continue;
14151415 \\ }
14161416 \\}
1417 );
1417 });
14181418
14191419 cases.add("macros with field targets",
14201420 \\typedef unsigned int GLbitfield;
......@@ -1429,7 +1429,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
14291429 \\extern union OpenGLProcs glProcs;
14301430 \\#define glClearUnion glProcs.gl.Clear
14311431 \\#define glClearPFN PFNGLCLEARPROC
1432 ,
1432 , &[_][]const u8{
14331433 \\pub const GLbitfield = c_uint;
14341434 ,
14351435 \\pub const PFNGLCLEARPROC = ?extern fn (GLbitfield) void;
......@@ -1452,7 +1452,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
14521452 \\}
14531453 ,
14541454 \\pub const OpenGLProcs = union_OpenGLProcs;
1455 );
1455 });
14561456
14571457 cases.add("variable name shadowing",
14581458 \\int foo(void) {
......@@ -1463,7 +1463,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
14631463 \\ }
14641464 \\ return x;
14651465 \\}
1466 ,
1466 , &[_][]const u8{
14671467 \\pub fn foo() c_int {
14681468 \\ var x: c_int = 1;
14691469 \\ {
......@@ -1472,27 +1472,27 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
14721472 \\ }
14731473 \\ return x;
14741474 \\}
1475 );
1475 });
14761476
14771477 cases.add("pointer casting",
14781478 \\float *ptrcast(int *a) {
14791479 \\ return (float *)a;
14801480 \\}
1481 ,
1481 , &[_][]const u8{
14821482 \\fn ptrcast(a: [*c]c_int) [*c]f32 {
14831483 \\ return @ptrCast([*c]f32, @alignCast(@alignOf(f32), a));
14841484 \\}
1485 );
1485 });
14861486
14871487 cases.add("bin not",
14881488 \\int foo(int x) {
14891489 \\ return ~x;
14901490 \\}
1491 ,
1491 , &[_][]const u8{
14921492 \\pub fn foo(x: c_int) c_int {
14931493 \\ return ~x;
14941494 \\}
1495 );
1495 });
14961496
14971497 cases.add("bool not",
14981498 \\int foo(int a, float b, void *c) {
......@@ -1501,46 +1501,46 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15011501 \\ return !b;
15021502 \\ return !c;
15031503 \\}
1504 ,
1504 , &[_][]const u8{
15051505 \\pub fn foo(a: c_int, b: f32, c: ?*c_void) c_int {
15061506 \\ return !(a == 0);
15071507 \\ return !(a != 0);
15081508 \\ return !(b != 0);
15091509 \\ return !(c != null);
15101510 \\}
1511 );
1511 });
15121512
15131513 cases.add("primitive types included in defined symbols",
15141514 \\int foo(int u32) {
15151515 \\ return u32;
15161516 \\}
1517 ,
1517 , &[_][]const u8{
15181518 \\pub fn foo(u32_0: c_int) c_int {
15191519 \\ return u32_0;
15201520 \\}
1521 );
1521 });
15221522
15231523 cases.add("const ptr initializer",
15241524 \\static const char *v0 = "0.0.0";
1525 ,
1525 , &[_][]const u8{
15261526 \\pub var v0: [*c]const u8 = "0.0.0";
1527 );
1527 });
15281528
15291529 cases.add("static incomplete array inside function",
15301530 \\void foo(void) {
15311531 \\ static const char v2[] = "2.2.2";
15321532 \\}
1533 ,
1533 , &[_][]const u8{
15341534 \\pub fn foo() void {
15351535 \\ const v2: [*c]const u8 = "2.2.2";
15361536 \\}
1537 );
1537 });
15381538
15391539 cases.add("macro pointer cast",
15401540 \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE)
1541 ,
1541 , &[_][]const u8{
15421542 \\pub const NRF_GPIO = if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Pointer) @ptrCast([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else if (@typeId(@typeOf(NRF_GPIO_BASE)) == @import("builtin").TypeId.Int) @intToPtr([*c]NRF_GPIO_Type, NRF_GPIO_BASE) else @as([*c]NRF_GPIO_Type, NRF_GPIO_BASE);
1543 );
1543 });
15441544
15451545 cases.add("if on non-bool",
15461546 \\enum SomeEnum { A, B, C };
......@@ -1551,7 +1551,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15511551 \\ if (d) return 3;
15521552 \\ return 4;
15531553 \\}
1554 ,
1554 , &[_][]const u8{
15551555 \\pub const A = enum_SomeEnum.A;
15561556 \\pub const B = enum_SomeEnum.B;
15571557 \\pub const C = enum_SomeEnum.C;
......@@ -1567,7 +1567,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15671567 \\ if (d != @bitCast(enum_SomeEnum, @as(@TagType(enum_SomeEnum), 0))) return 3;
15681568 \\ return 4;
15691569 \\}
1570 );
1570 });
15711571
15721572 cases.add("while on non-bool",
15731573 \\int while_none_bool(int a, float b, void *c) {
......@@ -1576,14 +1576,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15761576 \\ while (c) return 2;
15771577 \\ return 3;
15781578 \\}
1579 ,
1579 , &[_][]const u8{
15801580 \\pub fn while_none_bool(a: c_int, b: f32, c: ?*c_void) c_int {
15811581 \\ while (a != 0) return 0;
15821582 \\ while (b != 0) return 1;
15831583 \\ while (c != null) return 2;
15841584 \\ return 3;
15851585 \\}
1586 );
1586 });
15871587
15881588 cases.add("for on non-bool",
15891589 \\int for_none_bool(int a, float b, void *c) {
......@@ -1592,14 +1592,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
15921592 \\ for (;c;) return 2;
15931593 \\ return 3;
15941594 \\}
1595 ,
1595 , &[_][]const u8{
15961596 \\pub fn for_none_bool(a: c_int, b: f32, c: ?*c_void) c_int {
15971597 \\ while (a != 0) return 0;
15981598 \\ while (b != 0) return 1;
15991599 \\ while (c != null) return 2;
16001600 \\ return 3;
16011601 \\}
1602 );
1602 });
16031603
16041604 cases.add("switch on int",
16051605 \\int switch_fn(int i) {
......@@ -1616,7 +1616,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16161616 \\ res = 5;
16171617 \\ }
16181618 \\}
1619 ,
1619 , &[_][]const u8{
16201620 \\pub fn switch_fn(i: c_int) c_int {
16211621 \\ var res: c_int = 0;
16221622 \\ __switch: {
......@@ -1641,54 +1641,70 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
16411641 \\ res = 5;
16421642 \\ }
16431643 \\}
1644 );
1644 });
16451645
16461646 cases.addC(
16471647 "u integer suffix after 0 (zero) in macro definition",
16481648 "#define ZERO 0U",
1649 "pub const ZERO = @as(c_uint, 0);",
1649 &[_][]const u8{
1650 "pub const ZERO = @as(c_uint, 0);",
1651 },
16501652 );
16511653
16521654 cases.addC(
16531655 "l integer suffix after 0 (zero) in macro definition",
16541656 "#define ZERO 0L",
1655 "pub const ZERO = @as(c_long, 0);",
1657 &[_][]const u8{
1658 "pub const ZERO = @as(c_long, 0);",
1659 },
16561660 );
16571661
16581662 cases.addC(
16591663 "ul integer suffix after 0 (zero) in macro definition",
16601664 "#define ZERO 0UL",
1661 "pub const ZERO = @as(c_ulong, 0);",
1665 &[_][]const u8{
1666 "pub const ZERO = @as(c_ulong, 0);",
1667 },
16621668 );
16631669
16641670 cases.addC(
16651671 "lu integer suffix after 0 (zero) in macro definition",
16661672 "#define ZERO 0LU",
1667 "pub const ZERO = @as(c_ulong, 0);",
1673 &[_][]const u8{
1674 "pub const ZERO = @as(c_ulong, 0);",
1675 },
16681676 );
16691677
16701678 cases.addC(
16711679 "ll integer suffix after 0 (zero) in macro definition",
16721680 "#define ZERO 0LL",
1673 "pub const ZERO = @as(c_longlong, 0);",
1681 &[_][]const u8{
1682 "pub const ZERO = @as(c_longlong, 0);",
1683 },
16741684 );
16751685
16761686 cases.addC(
16771687 "ull integer suffix after 0 (zero) in macro definition",
16781688 "#define ZERO 0ULL",
1679 "pub const ZERO = @as(c_ulonglong, 0);",
1689 &[_][]const u8{
1690 "pub const ZERO = @as(c_ulonglong, 0);",
1691 },
16801692 );
16811693
16821694 cases.addC(
16831695 "llu integer suffix after 0 (zero) in macro definition",
16841696 "#define ZERO 0LLU",
1685 "pub const ZERO = @as(c_ulonglong, 0);",
1697 &[_][]const u8{
1698 "pub const ZERO = @as(c_ulonglong, 0);",
1699 },
16861700 );
16871701
16881702 cases.addC(
16891703 "bitwise not on u-suffixed 0 (zero) in macro definition",
16901704 "#define NOT_ZERO (~0U)",
1691 "pub const NOT_ZERO = ~@as(c_uint, 0);",
1705 &[_][]const u8{
1706 "pub const NOT_ZERO = ~@as(c_uint, 0);",
1707 },
16921708 );
16931709
16941710 cases.addC("implicit casts",
......@@ -1719,7 +1735,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
17191735 \\ fn_int(&fn_int);
17201736 \\ fn_ptr(42);
17211737 \\}
1722 ,
1738 , &[_][]const u8{
17231739 \\pub extern fn fn_int(x: c_int) void;
17241740 \\pub extern fn fn_f32(x: f32) void;
17251741 \\pub extern fn fn_f64(x: f64) void;
......@@ -1744,7 +1760,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
17441760 \\ fn_int(@intCast(c_int, @ptrToInt(&fn_int)));
17451761 \\ fn_ptr(@intToPtr(?*c_void, 42));
17461762 \\}
1747 );
1763 });
17481764
17491765 cases.addC("pointer conversion with different alignment",
17501766 \\void test_ptr_cast() {
......@@ -1762,7 +1778,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
17621778 \\ long long *to_longlong = p;
17631779 \\ }
17641780 \\}
1765 ,
1781 , &[_][]const u8{
17661782 \\pub export fn test_ptr_cast() void {
17671783 \\ var p: ?*c_void = undefined;
17681784 \\ {
......@@ -1778,7 +1794,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
17781794 \\ var to_longlong: [*c]c_longlong = @ptrCast([*c]c_longlong, @alignCast(@alignOf(c_longlong), p));
17791795 \\ }
17801796 \\}
1781 );
1797 });
17821798
17831799 cases.addC("escape sequences",
17841800 \\const char *escapes() {
......@@ -1796,7 +1812,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
17961812 \\ return "\'\\\a\b\f\n\r\t\v\0\"";
17971813 \\}
17981814 \\
1799 ,
1815 , &[_][]const u8{
18001816 \\pub export fn escapes() [*c]const u8 {
18011817 \\ var a: u8 = @as(u8, '\'');
18021818 \\ var b: u8 = @as(u8, '\\');
......@@ -1812,23 +1828,23 @@ pub fn addCases(cases: *tests.TranslateCContext) void {
18121828 \\ return "\'\\\x07\x08\x0c\n\r\t\x0b\x00\"";
18131829 \\}
18141830 \\
1815 );
1831 });
18161832
18171833 if (builtin.os != builtin.Os.windows) {
18181834 // sysv_abi not currently supported on windows
18191835 cases.add("Macro qualified functions",
18201836 \\void __attribute__((sysv_abi)) foo(void);
1821 ,
1837 , &[_][]const u8{
18221838 \\pub extern fn foo() void;
1823 );
1839 });
18241840 }
18251841
18261842 /////////////// Cases for only stage1 because stage2 behavior is better ////////////////
18271843 cases.addC("Parameterless function prototypes",
18281844 \\void foo() {}
18291845 \\void bar(void) {}
1830 ,
1846 , &[_][]const u8{
18311847 \\pub export fn foo() void {}
18321848 \\pub export fn bar() void {}
1833 );
1849 });
18341850}