diff --git a/doc/langref.html.in b/doc/langref.html.in index bc23865a84..e51e59d562 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -5862,7 +5862,7 @@ pub fn main() void { {#code_begin|syntax#} /// Calls print and then flushes the buffer. -pub fn printf(self: *OutStream, comptime format: []const u8, args: ...) anyerror!void { +pub fn printf(self: *OutStream, comptime format: []const u8, args: var) anyerror!void { const State = enum { Start, OpenBrace, @@ -8277,7 +8277,6 @@ test "integer truncation" {
  • {#link|union#}
  • {#link|Functions#}
  • BoundFn
  • -
  • ArgTuple
  • {#link|struct#}
  • {#header_close#} @@ -8310,7 +8309,6 @@ pub const TypeId = enum { Fn, Block, BoundFn, - ArgTuple, Opaque, }; {#code_end#} @@ -8343,7 +8341,6 @@ pub const TypeInfo = union(TypeId) { Union: Union, Fn: Fn, BoundFn: Fn, - ArgTuple: void, Opaque: void, Promise: Promise, Vector: Vector, diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 4c57915f92..36fa46e953 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -116,7 +116,6 @@ pub const TypeInfo = union(enum) { Union: Union, Fn: Fn, BoundFn: Fn, - ArgTuple: void, Opaque: void, Frame: void, AnyFrame: AnyFrame, diff --git a/lib/std/fmt.zig b/lib/std/fmt.zig index f557e716a5..f01510b02c 100644 --- a/lib/std/fmt.zig +++ b/lib/std/fmt.zig @@ -94,9 +94,7 @@ pub fn format( args: var, ) Errors!void { const ArgSetType = @IntType(false, 32); - const args_fields = std.meta.fields(@typeOf(args)); - const args_len = args_fields.len; - if (args_len > ArgSetType.bit_count) { + if (args.len > ArgSetType.bit_count) { @compileError("32 arguments max are supported per format call"); } @@ -160,14 +158,14 @@ pub fn format( maybe_pos_arg.? += c - '0'; specifier_start = i + 1; - if (maybe_pos_arg.? >= args_len) { + if (maybe_pos_arg.? >= args.len) { @compileError("Positional value refers to non-existent argument"); } }, '}' => { const arg_to_print = comptime nextArg(&used_pos_args, maybe_pos_arg, &next_arg); - if (arg_to_print >= args_len) { + if (arg_to_print >= args.len) { @compileError("Too few arguments"); } @@ -304,7 +302,7 @@ pub fn format( used_pos_args |= 1 << i; } - if (@popCount(ArgSetType, used_pos_args) != args_len) { + if (@popCount(ArgSetType, used_pos_args) != args.len) { @compileError("Unused arguments"); } if (state != State.Start) { diff --git a/lib/std/hash/auto_hash.zig b/lib/std/hash/auto_hash.zig index 07ee1d3d00..696a5e81dc 100644 --- a/lib/std/hash/auto_hash.zig +++ b/lib/std/hash/auto_hash.zig @@ -79,7 +79,6 @@ pub fn hash(hasher: var, key: var, comptime strat: HashStrategy) void { .NoReturn, .Opaque, .Undefined, - .ArgTuple, .Void, .Null, .BoundFn, diff --git a/lib/std/special/docs/main.js b/lib/std/special/docs/main.js index 349f496de0..8ea4598ee0 100644 --- a/lib/std/special/docs/main.js +++ b/lib/std/special/docs/main.js @@ -1194,7 +1194,7 @@ // This is just for debugging purposes, not needed to function var assertList = ["Type","Void","Bool","NoReturn","Int","Float","Pointer","Array","Struct", "ComptimeFloat","ComptimeInt","Undefined","Null","Optional","ErrorUnion","ErrorSet","Enum", - "Union","Fn","BoundFn","ArgTuple","Opaque","Frame","AnyFrame","Vector","EnumLiteral"]; + "Union","Fn","BoundFn","Opaque","Frame","AnyFrame","Vector","EnumLiteral"]; for (var i = 0; i < assertList.length; i += 1) { if (map[assertList[i]] == null) throw new Error("No type kind '" + assertList[i] + "' found"); } diff --git a/lib/std/testing.zig b/lib/std/testing.zig index e808930b60..7ffe022011 100644 --- a/lib/std/testing.zig +++ b/lib/std/testing.zig @@ -33,7 +33,6 @@ pub fn expectEqual(expected: var, actual: @typeOf(expected)) void { switch (@typeInfo(@typeOf(actual))) { .NoReturn, .BoundFn, - .ArgTuple, .Opaque, .Frame, .AnyFrame, diff --git a/src-self-hosted/type.zig b/src-self-hosted/type.zig index fa8e133b69..84efeea68a 100644 --- a/src-self-hosted/type.zig +++ b/src-self-hosted/type.zig @@ -41,7 +41,6 @@ pub const Type = struct { .Enum => @fieldParentPtr(Enum, "base", base).destroy(comp), .Union => @fieldParentPtr(Union, "base", base).destroy(comp), .BoundFn => @fieldParentPtr(BoundFn, "base", base).destroy(comp), - .ArgTuple => @fieldParentPtr(ArgTuple, "base", base).destroy(comp), .Opaque => @fieldParentPtr(Opaque, "base", base).destroy(comp), .Frame => @fieldParentPtr(Frame, "base", base).destroy(comp), .AnyFrame => @fieldParentPtr(AnyFrame, "base", base).destroy(comp), @@ -76,7 +75,6 @@ pub const Type = struct { .Enum => return @fieldParentPtr(Enum, "base", base).getLlvmType(allocator, llvm_context), .Union => return @fieldParentPtr(Union, "base", base).getLlvmType(allocator, llvm_context), .BoundFn => return @fieldParentPtr(BoundFn, "base", base).getLlvmType(allocator, llvm_context), - .ArgTuple => unreachable, .Opaque => return @fieldParentPtr(Opaque, "base", base).getLlvmType(allocator, llvm_context), .Frame => return @fieldParentPtr(Frame, "base", base).getLlvmType(allocator, llvm_context), .AnyFrame => return @fieldParentPtr(AnyFrame, "base", base).getLlvmType(allocator, llvm_context), @@ -93,7 +91,6 @@ pub const Type = struct { .Undefined, .Null, .BoundFn, - .ArgTuple, .Opaque, => unreachable, @@ -128,7 +125,6 @@ pub const Type = struct { .Undefined, .Null, .BoundFn, - .ArgTuple, .Opaque, => unreachable, @@ -1004,14 +1000,6 @@ pub const Type = struct { } }; - pub const ArgTuple = struct { - base: Type, - - pub fn destroy(self: *ArgTuple, comp: *Compilation) void { - comp.gpa().destroy(self); - } - }; - pub const Opaque = struct { base: Type, diff --git a/src/all_types.hpp b/src/all_types.hpp index a7945e700d..e364b3d362 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1471,7 +1471,6 @@ enum ZigTypeId { ZigTypeIdUnion, ZigTypeIdFn, ZigTypeIdBoundFn, - ZigTypeIdArgTuple, ZigTypeIdOpaque, ZigTypeIdFnFrame, ZigTypeIdAnyFrame, @@ -2039,7 +2038,6 @@ struct CodeGen { ZigType *entry_null; ZigType *entry_var; ZigType *entry_global_error_set; - ZigType *entry_arg_tuple; ZigType *entry_enum_literal; ZigType *entry_any_frame; } builtin_types; diff --git a/src/analyze.cpp b/src/analyze.cpp index fefa5352da..64a0f14372 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -323,7 +323,6 @@ AstNode *type_decl_node(ZigType *type_entry) { case ZigTypeIdErrorSet: case ZigTypeIdFn: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdVector: case ZigTypeIdAnyFrame: return nullptr; @@ -392,7 +391,6 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) { case ZigTypeIdErrorSet: case ZigTypeIdFn: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdVector: case ZigTypeIdAnyFrame: return true; @@ -1558,7 +1556,6 @@ static Error emit_error_unless_type_allowed_in_packed_container(CodeGen *g, ZigT case ZigTypeIdErrorUnion: case ZigTypeIdErrorSet: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdOpaque: case ZigTypeIdFnFrame: case ZigTypeIdAnyFrame: @@ -1661,7 +1658,6 @@ Error type_allowed_in_extern(CodeGen *g, ZigType *type_entry, bool *result) { case ZigTypeIdErrorUnion: case ZigTypeIdErrorSet: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdVoid: case ZigTypeIdFnFrame: case ZigTypeIdAnyFrame: @@ -1786,12 +1782,9 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc if (fn_type_id.cc == CallingConventionC) { fn_type_id.param_count = fn_type_id.next_param_index; continue; - } else if (calling_convention_allows_zig_types(fn_type_id.cc)) { - return get_generic_fn_type(g, &fn_type_id); } else { add_node_error(g, param_node, - buf_sprintf("var args not allowed in function with calling convention '%s'", - calling_convention_name(fn_type_id.cc))); + buf_sprintf("var args only allowed in functions with C calling convention")); return g->builtin_types.entry_invalid; } } 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 case ZigTypeIdUnreachable: case ZigTypeIdUndefined: case ZigTypeIdNull: - case ZigTypeIdArgTuple: case ZigTypeIdOpaque: add_node_error(g, param_node->data.param_decl.type, 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 case ZigTypeIdUndefined: case ZigTypeIdNull: - case ZigTypeIdArgTuple: add_node_error(g, fn_proto->return_type, buf_sprintf("return type '%s' not allowed", buf_ptr(&specified_return_type->name))); return g->builtin_types.entry_invalid; @@ -1963,7 +1954,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc case ZigTypeIdInvalid: case ZigTypeIdUndefined: case ZigTypeIdNull: - case ZigTypeIdArgTuple: case ZigTypeIdOpaque: zig_unreachable(); @@ -3720,7 +3710,6 @@ ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry case ZigTypeIdUnreachable: case ZigTypeIdUndefined: case ZigTypeIdNull: - case ZigTypeIdArgTuple: case ZigTypeIdOpaque: add_node_error(g, source_node, buf_sprintf("variable of type '%s' not allowed", buf_ptr(&type_entry->name))); @@ -4275,7 +4264,6 @@ bool is_container(ZigType *type_entry) { case ZigTypeIdErrorSet: case ZigTypeIdFn: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdOpaque: case ZigTypeIdVector: case ZigTypeIdFnFrame: @@ -4982,7 +4970,6 @@ bool handle_is_ptr(ZigType *type_entry) { case ZigTypeIdUndefined: case ZigTypeIdNull: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdOpaque: zig_unreachable(); case ZigTypeIdUnreachable: @@ -5201,9 +5188,6 @@ static uint32_t hash_const_val(ZigValue *const_val) { memcpy(&ints[0], &f128, 16); return ints[0] ^ ints[1] ^ ints[2] ^ ints[3] ^ 0xed8b3dfb; } - case ZigTypeIdArgTuple: - return (uint32_t)const_val->data.x_arg_tuple.start_index * (uint32_t)281907309 + - (uint32_t)const_val->data.x_arg_tuple.end_index * (uint32_t)2290442768; case ZigTypeIdFn: assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst); assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction); @@ -5357,9 +5341,6 @@ static bool can_mutate_comptime_var_state(ZigValue *value) { case ZigTypeIdUnion: return can_mutate_comptime_var_state(value->data.x_union.payload); - - case ZigTypeIdArgTuple: - zig_panic("TODO var args at comptime is currently not supported"); } zig_unreachable(); } @@ -5400,9 +5381,6 @@ static bool return_type_is_cacheable(ZigType *return_type) { case ZigTypeIdErrorUnion: return return_type_is_cacheable(return_type->data.error_union.payload_type); - - case ZigTypeIdArgTuple: - zig_panic("TODO var args at comptime is currently not supported"); } zig_unreachable(); } @@ -5540,7 +5518,6 @@ OnePossibleValue type_has_one_possible_value(CodeGen *g, ZigType *type_entry) { case ZigTypeIdEnumLiteral: case ZigTypeIdMetaType: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdOptional: case ZigTypeIdFn: case ZigTypeIdBool: @@ -5626,7 +5603,6 @@ ReqCompTime type_requires_comptime(CodeGen *g, ZigType *ty) { case ZigTypeIdNull: case ZigTypeIdMetaType: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: return ReqCompTimeYes; case ZigTypeIdArray: 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, return const_val; } -void init_const_arg_tuple(CodeGen *g, ZigValue *const_val, size_t arg_index_start, size_t arg_index_end) { - const_val->special = ConstValSpecialStatic; - const_val->type = g->builtin_types.entry_arg_tuple; - const_val->data.x_arg_tuple.start_index = arg_index_start; - const_val->data.x_arg_tuple.end_index = arg_index_end; -} - -ZigValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end) { - ZigValue *const_val = create_const_vals(1); - init_const_arg_tuple(g, const_val, arg_index_start, arg_index_end); - return const_val; -} - - ZigValue *create_const_vals(size_t count) { return allocate(count, "ZigValue"); } @@ -6679,9 +6641,6 @@ bool const_values_equal(CodeGen *g, ZigValue *a, ZigValue *b) { } case ZigTypeIdErrorUnion: zig_panic("TODO"); - case ZigTypeIdArgTuple: - return a->data.x_arg_tuple.start_index == b->data.x_arg_tuple.start_index && - a->data.x_arg_tuple.end_index == b->data.x_arg_tuple.end_index; case ZigTypeIdBoundFn: case ZigTypeIdInvalid: case ZigTypeIdUnreachable: @@ -7008,11 +6967,6 @@ void render_const_value(CodeGen *g, Buf *buf, ZigValue *const_val) { } case ZigTypeIdErrorSet: return render_const_val_err_set(g, buf, const_val, type_entry); - case ZigTypeIdArgTuple: - { - buf_appendf(buf, "(args value)"); - return; - } case ZigTypeIdFnFrame: buf_appendf(buf, "(TODO: async function frame value)"); return; @@ -7075,7 +7029,6 @@ uint32_t type_id_hash(TypeId x) { case ZigTypeIdUnion: case ZigTypeIdFn: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdFnFrame: case ZigTypeIdAnyFrame: zig_unreachable(); @@ -7127,7 +7080,6 @@ bool type_id_eql(TypeId a, TypeId b) { case ZigTypeIdUnion: case ZigTypeIdFn: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdOpaque: case ZigTypeIdFnFrame: case ZigTypeIdAnyFrame: @@ -7350,7 +7302,6 @@ static const ZigTypeId all_type_ids[] = { ZigTypeIdUnion, ZigTypeIdFn, ZigTypeIdBoundFn, - ZigTypeIdArgTuple, ZigTypeIdOpaque, ZigTypeIdFnFrame, ZigTypeIdAnyFrame, @@ -7413,18 +7364,16 @@ size_t type_id_index(ZigType *entry) { return 18; case ZigTypeIdBoundFn: return 19; - case ZigTypeIdArgTuple: - return 20; case ZigTypeIdOpaque: - return 21; + return 20; case ZigTypeIdFnFrame: - return 22; + return 21; case ZigTypeIdAnyFrame: - return 23; + return 22; case ZigTypeIdVector: - return 24; + return 23; case ZigTypeIdEnumLiteral: - return 25; + return 24; } zig_unreachable(); } @@ -7475,8 +7424,6 @@ const char *type_id_name(ZigTypeId id) { return "Fn"; case ZigTypeIdBoundFn: return "BoundFn"; - case ZigTypeIdArgTuple: - return "ArgTuple"; case ZigTypeIdOpaque: return "Opaque"; case ZigTypeIdVector: @@ -9064,7 +9011,6 @@ static void resolve_llvm_types(CodeGen *g, ZigType *type, ResolveStatus wanted_r case ZigTypeIdUndefined: case ZigTypeIdNull: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: zig_unreachable(); case ZigTypeIdFloat: case ZigTypeIdOpaque: diff --git a/src/analyze.hpp b/src/analyze.hpp index 2fdaa00ab2..8f07434203 100644 --- a/src/analyze.hpp +++ b/src/analyze.hpp @@ -171,9 +171,6 @@ void init_const_slice(CodeGen *g, ZigValue *const_val, ZigValue *array_val, size_t start, size_t len, bool is_const); ZigValue *create_const_slice(CodeGen *g, ZigValue *array_val, size_t start, size_t len, bool is_const); -void init_const_arg_tuple(CodeGen *g, ZigValue *const_val, size_t arg_index_start, size_t arg_index_end); -ZigValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_t arg_index_end); - void init_const_null(ZigValue *const_val, ZigType *type); ZigValue *create_const_null(ZigType *type); diff --git a/src/codegen.cpp b/src/codegen.cpp index 387d10a189..a7bf7a50c4 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -6539,7 +6539,6 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Zig case ZigTypeIdErrorUnion: case ZigTypeIdErrorSet: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdVoid: case ZigTypeIdOpaque: zig_unreachable(); @@ -7182,7 +7181,6 @@ check: switch (const_val->special) { case ZigTypeIdUndefined: case ZigTypeIdNull: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdOpaque: zig_unreachable(); case ZigTypeIdFnFrame: @@ -7887,11 +7885,6 @@ static void define_builtin_types(CodeGen *g) { buf_init_from_str(&entry->name, "(var)"); g->builtin_types.entry_var = entry; } - { - ZigType *entry = new_type_table_entry(ZigTypeIdArgTuple); - buf_init_from_str(&entry->name, "(args)"); - g->builtin_types.entry_arg_tuple = entry; - } for (size_t i = 0; i < array_length(c_int_type_infos); i += 1) { 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 case ZigTypeIdUndefined: case ZigTypeIdNull: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdErrorUnion: case ZigTypeIdErrorSet: case ZigTypeIdFnFrame: @@ -9721,7 +9713,6 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu case ZigTypeIdEnumLiteral: case ZigTypeIdUndefined: case ZigTypeIdNull: - case ZigTypeIdArgTuple: case ZigTypeIdFnFrame: case ZigTypeIdAnyFrame: zig_unreachable(); @@ -9781,7 +9772,6 @@ static void gen_h_file_types(CodeGen* g, GenH* gen_h, Buf* out_buf) { case ZigTypeIdErrorUnion: case ZigTypeIdErrorSet: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdOptional: case ZigTypeIdFn: case ZigTypeIdVector: diff --git a/src/ir.cpp b/src/ir.cpp index 241ef73ce2..154b258327 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -780,7 +780,6 @@ static bool types_have_same_zig_comptime_repr(CodeGen *codegen, ZigType *expecte case ZigTypeIdErrorUnion: case ZigTypeIdEnum: case ZigTypeIdUnion: - case ZigTypeIdArgTuple: case ZigTypeIdVector: case ZigTypeIdFnFrame: return false; @@ -14791,7 +14790,6 @@ static IrInstruction *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp * case ZigTypeIdFn: case ZigTypeIdOpaque: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdEnum: case ZigTypeIdEnumLiteral: case ZigTypeIdAnyFrame: @@ -16437,7 +16435,6 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio case ZigTypeIdErrorUnion: case ZigTypeIdErrorSet: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdOpaque: case ZigTypeIdFnFrame: case ZigTypeIdAnyFrame: @@ -16462,7 +16459,6 @@ static IrInstruction *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructio case ZigTypeIdVector: zig_panic("TODO export const value of type %s", buf_ptr(&target->value->type->name)); case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdOpaque: case ZigTypeIdEnumLiteral: case ZigTypeIdFnFrame: @@ -16609,7 +16605,6 @@ static bool type_can_bit_cast(ZigType *t) { case ZigTypeIdMetaType: case ZigTypeIdOpaque: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdUnreachable: case ZigTypeIdComptimeFloat: case ZigTypeIdComptimeInt: @@ -17416,23 +17411,6 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod return true; } -static ZigVar *get_fn_var_by_index(ZigFn *fn_entry, size_t index) { - FnTypeParamInfo *src_param_info = &fn_entry->type_entry->data.fn.fn_type_id.param_info[index]; - if (!type_has_bits(src_param_info->type)) - return nullptr; - - size_t next_var_i = 0; - for (size_t param_i = 0; param_i < index; param_i += 1) { - FnTypeParamInfo *src_param_info = &fn_entry->type_entry->data.fn.fn_type_id.param_info[param_i]; - if (!type_has_bits(src_param_info->type)) { - continue; - } - - next_var_i += 1; - } - return fn_entry->variable_list.at(next_var_i); -} - static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var) { while (var->next_var != nullptr) { var = var->next_var; @@ -17690,16 +17668,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i var_args_1_or_0 = fn_type_id->is_var_args ? 1 : 0; } size_t src_param_count = fn_type_id->param_count - var_args_1_or_0; - size_t call_param_count = args_len + first_arg_1_or_0; - for (size_t i = 0; i < args_len; i += 1) { - ZigValue *arg_tuple_value = args_ptr[i]->value; - if (arg_tuple_value->type->id == ZigTypeIdArgTuple) { - call_param_count -= 1; - call_param_count += arg_tuple_value->data.x_arg_tuple.end_index - - arg_tuple_value->data.x_arg_tuple.start_index; - } - } AstNode *source_node = source_instr->source_node; 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 return ira->codegen->invalid_instruction; } - // Count the arguments of the function type id we are creating - size_t new_fn_arg_count = first_arg_1_or_0; - for (size_t call_i = 0; call_i < args_len; call_i += 1) { - IrInstruction *arg = args_ptr[call_i]; - if (arg->value->type->id == ZigTypeIdArgTuple) { - new_fn_arg_count += arg->value->data.x_arg_tuple.end_index - arg->value->data.x_arg_tuple.start_index; - } else { - new_fn_arg_count += 1; - } - } + size_t new_fn_arg_count = first_arg_1_or_0 + args_len; IrInstruction **casted_args = allocate(new_fn_arg_count); @@ -17914,76 +17874,19 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstruction *source_i } } - bool found_first_var_arg = false; - size_t first_var_arg; - ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec); assert(parent_fn_entry); for (size_t call_i = 0; call_i < args_len; call_i += 1) { IrInstruction *arg = args_ptr[call_i]; - if (arg->value->type->id == ZigTypeIdArgTuple) { - for (size_t arg_tuple_i = arg->value->data.x_arg_tuple.start_index; - arg_tuple_i < arg->value->data.x_arg_tuple.end_index; arg_tuple_i += 1) - { - AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i); - assert(param_decl_node->type == NodeTypeParamDecl); - bool is_var_args = param_decl_node->data.param_decl.is_var_args; - if (is_var_args && !found_first_var_arg) { - first_var_arg = inst_fn_type_id.param_count; - found_first_var_arg = true; - } - - ZigVar *arg_var = get_fn_var_by_index(parent_fn_entry, arg_tuple_i); - if (arg_var == nullptr) { - ir_add_error(ira, arg, - buf_sprintf("compiler bug: var args can't handle void. https://github.com/ziglang/zig/issues/557")); - return ira->codegen->invalid_instruction; - } - IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, arg, arg_var); - if (type_is_invalid(arg_var_ptr_inst->value->type)) - return ira->codegen->invalid_instruction; - - IrInstruction *arg_tuple_arg = ir_get_deref(ira, arg, arg_var_ptr_inst, nullptr); - if (type_is_invalid(arg_tuple_arg->value->type)) - return ira->codegen->invalid_instruction; - - if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg_tuple_arg, &impl_fn->child_scope, - &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn)) - { - return ira->codegen->invalid_instruction; - } - } - } else { - AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i); - assert(param_decl_node->type == NodeTypeParamDecl); - bool is_var_args = param_decl_node->data.param_decl.is_var_args; - if (is_var_args && !found_first_var_arg) { - first_var_arg = inst_fn_type_id.param_count; - found_first_var_arg = true; - } - - if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, &impl_fn->child_scope, - &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn)) - { - return ira->codegen->invalid_instruction; - } - } - } - - if (fn_proto_node->data.fn_proto.is_var_args) { AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i); - Buf *param_name = param_decl_node->data.param_decl.name; + assert(param_decl_node->type == NodeTypeParamDecl); - if (!found_first_var_arg) { - first_var_arg = inst_fn_type_id.param_count; + if (!ir_analyze_fn_call_generic_arg(ira, fn_proto_node, arg, &impl_fn->child_scope, + &next_proto_i, generic_id, &inst_fn_type_id, casted_args, impl_fn)) + { + return ira->codegen->invalid_instruction; } - - ZigValue *var_args_val = create_const_arg_tuple(ira->codegen, - first_var_arg, inst_fn_type_id.param_count); - ZigVar *var = add_variable(ira->codegen, param_decl_node, - impl_fn->child_scope, param_name, true, var_args_val, nullptr, var_args_val->type); - impl_fn->child_scope = var->child_scope; } 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 if (type_is_invalid(old_arg->value->type)) return ira->codegen->invalid_instruction; - if (old_arg->value->type->id == ZigTypeIdArgTuple) { - for (size_t arg_tuple_i = old_arg->value->data.x_arg_tuple.start_index; - arg_tuple_i < old_arg->value->data.x_arg_tuple.end_index; arg_tuple_i += 1) - { - ZigVar *arg_var = get_fn_var_by_index(parent_fn_entry, arg_tuple_i); - if (arg_var == nullptr) { - ir_add_error(ira, old_arg, - buf_sprintf("compiler bug: var args can't handle void. https://github.com/ziglang/zig/issues/557")); - return ira->codegen->invalid_instruction; - } - IrInstruction *arg_var_ptr_inst = ir_get_var_ptr(ira, old_arg, arg_var); - if (type_is_invalid(arg_var_ptr_inst->value->type)) - return ira->codegen->invalid_instruction; - - IrInstruction *arg_tuple_arg = ir_get_deref(ira, old_arg, arg_var_ptr_inst, nullptr); - if (type_is_invalid(arg_tuple_arg->value->type)) - return ira->codegen->invalid_instruction; - - IrInstruction *casted_arg; - if (next_arg_index < src_param_count) { - ZigType *param_type = fn_type_id->param_info[next_arg_index].type; - if (type_is_invalid(param_type)) - return ira->codegen->invalid_instruction; - casted_arg = ir_implicit_cast(ira, arg_tuple_arg, param_type); - if (type_is_invalid(casted_arg->value->type)) - return ira->codegen->invalid_instruction; - } else { - casted_arg = arg_tuple_arg; - } - - casted_args[next_arg_index] = casted_arg; - next_arg_index += 1; - } + IrInstruction *casted_arg; + if (next_arg_index < src_param_count) { + ZigType *param_type = fn_type_id->param_info[next_arg_index].type; + if (type_is_invalid(param_type)) + return ira->codegen->invalid_instruction; + casted_arg = ir_implicit_cast(ira, old_arg, param_type); + if (type_is_invalid(casted_arg->value->type)) + return ira->codegen->invalid_instruction; } else { - IrInstruction *casted_arg; - if (next_arg_index < src_param_count) { - ZigType *param_type = fn_type_id->param_info[next_arg_index].type; - if (type_is_invalid(param_type)) - return ira->codegen->invalid_instruction; - casted_arg = ir_implicit_cast(ira, old_arg, param_type); - if (type_is_invalid(casted_arg->value->type)) - return ira->codegen->invalid_instruction; - } else { - casted_arg = old_arg; - } - - casted_args[next_arg_index] = casted_arg; - next_arg_index += 1; + casted_arg = old_arg; } + + casted_args[next_arg_index] = casted_arg; + next_arg_index += 1; } assert(next_arg_index == call_param_count); @@ -19186,37 +19054,6 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct } else if (is_slice(array_type)) { return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index]->type_entry, elem_ptr_instruction->ptr_len); - } else if (array_type->id == ZigTypeIdArgTuple) { - ZigValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad); - if (!ptr_val) - return ira->codegen->invalid_instruction; - ZigValue *args_val = const_ptr_pointee(ira, ira->codegen, ptr_val, elem_ptr_instruction->base.source_node); - if (args_val == nullptr) - return ira->codegen->invalid_instruction; - size_t start = args_val->data.x_arg_tuple.start_index; - size_t end = args_val->data.x_arg_tuple.end_index; - uint64_t elem_index_val; - if (!ir_resolve_usize(ira, elem_index, &elem_index_val)) - return ira->codegen->invalid_instruction; - size_t index = elem_index_val; - size_t len = end - start; - if (index >= len) { - ir_add_error(ira, &elem_ptr_instruction->base, - buf_sprintf("index %" ZIG_PRI_usize " outside argument list of size %" ZIG_PRI_usize "", index, len)); - return ira->codegen->invalid_instruction; - } - size_t abs_index = start + index; - ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); - assert(fn_entry); - ZigVar *var = get_fn_var_by_index(fn_entry, abs_index); - bool is_const = true; - bool is_volatile = false; - if (var) { - return ir_get_var_ptr(ira, &elem_ptr_instruction->base, var); - } else { - return ir_get_const_ptr(ira, &elem_ptr_instruction->base, ira->codegen->intern.for_void(), - ira->codegen->builtin_types.entry_void, ConstPtrMutComptimeConst, is_const, is_volatile, 0); - } } else if (array_type->id == ZigTypeIdVector) { // This depends on whether the element index is comptime, so it is computed later. return_type = nullptr; @@ -20025,6 +19862,10 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc if (type_is_invalid(container_type)) { return ira->codegen->invalid_instruction; + } else if (is_tuple(container_type) && !field_ptr_instruction->initializing && buf_eql_str(field_name, "len")) { + IrInstruction *len_inst = ir_const_unsigned(ira, &field_ptr_instruction->base, + container_type->data.structure.src_field_count); + return ir_get_ref(ira, &field_ptr_instruction->base, len_inst, true, false); } else if (is_slice(container_type) || is_container_ref(container_type)) { assert(container_ptr->value->type->id == ZigTypeIdPointer); if (container_type->id == ZigTypeIdPointer) { @@ -20045,32 +19886,6 @@ static IrInstruction *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstruc init_const_usize(ira->codegen, len_val, container_type->data.array.len); } - ZigType *usize = ira->codegen->builtin_types.entry_usize; - bool ptr_is_const = true; - bool ptr_is_volatile = false; - return ir_get_const_ptr(ira, &field_ptr_instruction->base, len_val, - usize, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile, 0); - } else { - ir_add_error_node(ira, source_node, - buf_sprintf("no member named '%s' in '%s'", buf_ptr(field_name), - buf_ptr(&container_type->name))); - return ira->codegen->invalid_instruction; - } - } else if (container_type->id == ZigTypeIdArgTuple) { - ZigValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); - if (!container_ptr_val) - return ira->codegen->invalid_instruction; - - assert(container_ptr->value->type->id == ZigTypeIdPointer); - ZigValue *child_val = const_ptr_pointee(ira, ira->codegen, container_ptr_val, source_node); - if (child_val == nullptr) - return ira->codegen->invalid_instruction; - - if (buf_eql_str(field_name, "len")) { - ZigValue *len_val = create_const_vals(1); - size_t len = child_val->data.x_arg_tuple.end_index - child_val->data.x_arg_tuple.start_index; - init_const_usize(ira->codegen, len_val, len); - ZigType *usize = ira->codegen->builtin_types.entry_usize; bool ptr_is_const = true; bool ptr_is_volatile = false; @@ -21258,7 +21073,6 @@ static IrInstruction *ir_analyze_instruction_switch_target(IrAnalyze *ira, case ZigTypeIdNull: case ZigTypeIdOptional: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdOpaque: case ZigTypeIdVector: case ZigTypeIdFnFrame: @@ -22580,7 +22394,6 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr case ZigTypeIdEnumLiteral: case ZigTypeIdUndefined: case ZigTypeIdNull: - case ZigTypeIdArgTuple: case ZigTypeIdOpaque: result = ira->codegen->intern.for_void(); break; @@ -23357,7 +23170,6 @@ static ZigType *type_info_to_type(IrAnalyze *ira, IrInstruction *instruction, Zi case ZigTypeIdUnion: case ZigTypeIdFn: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdStruct: ir_add_error(ira, instruction, buf_sprintf( "@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) case ZigTypeIdMetaType: case ZigTypeIdOpaque: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdUnreachable: case ZigTypeIdComptimeFloat: case ZigTypeIdComptimeInt: @@ -26609,7 +26420,6 @@ static Error buf_read_value_bytes(IrAnalyze *ira, CodeGen *codegen, AstNode *sou case ZigTypeIdMetaType: case ZigTypeIdOpaque: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdUnreachable: case ZigTypeIdComptimeFloat: case ZigTypeIdComptimeInt: @@ -28838,7 +28648,6 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { case ZigTypeIdUndefined: case ZigTypeIdNull: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdVoid: case ZigTypeIdOpaque: ir_add_error(ira, lazy_align_of->target_type, @@ -28890,7 +28699,6 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { case ZigTypeIdUndefined: case ZigTypeIdNull: case ZigTypeIdBoundFn: - case ZigTypeIdArgTuple: case ZigTypeIdOpaque: ir_add_error(ira, lazy_size_of->target_type, buf_sprintf("no size available for type '%s'", @@ -28969,7 +28777,6 @@ static Error ir_resolve_lazy_raw(AstNode *source_node, ZigValue *val) { case ZigTypeIdUnreachable: case ZigTypeIdUndefined: case ZigTypeIdNull: - case ZigTypeIdArgTuple: case ZigTypeIdOpaque: ir_add_error(ira, lazy_slice_type->elem_type, 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) { case ZigTypeIdUnreachable: case ZigTypeIdUndefined: case ZigTypeIdNull: - case ZigTypeIdArgTuple: case ZigTypeIdOpaque: ir_add_error(ira, lazy_array_type->elem_type, buf_sprintf("array of type '%s' not allowed", diff --git a/src/parser.cpp b/src/parser.cpp index 1786e38d4b..96162632b9 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -802,12 +802,6 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc) { res->data.fn_proto.auto_err_set = exmark != nullptr; res->data.fn_proto.return_type = return_type; - // It seems that the Zig compiler expects varargs to be the - // last parameter in the decl list. This is not encoded in - // the grammar, which allows varargs anywhere in the decl. - // Since varargs is gonna be removed at some point, I'm not - // gonna encode this "varargs is always last" rule in the - // grammar, and just enforce it here, until varargs is removed. for (size_t i = 0; i < params.length; i++) { AstNode *param_decl = params.at(i); assert(param_decl->type == NodeTypeParamDecl); diff --git a/test/compile_errors.zig b/test/compile_errors.zig index ebc57d264d..b89287949b 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -2,6 +2,15 @@ const tests = @import("tests.zig"); const builtin = @import("builtin"); pub fn addCases(cases: *tests.CompileErrorContext) void { + cases.add("var args without c calling conv", + \\fn foo(args: ...) void {} + \\comptime { + \\ _ = foo; + \\} + , &[_][]const u8{ + "tmp.zig:1:8: error: var args only allowed in functions with C calling convention", + }); + cases.add("comptime struct field, no init value", \\const Foo = struct { \\ comptime b: i32, @@ -9,10 +18,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ var f: Foo = undefined; \\} - , "tmp.zig:2:5: error: comptime struct field missing initialization value"); + , &[_][]const u8{ + "tmp.zig:2:5: error: comptime struct field missing initialization value", + }); - cases.add( - "bad usage of @call", + cases.add("bad usage of @call", \\export fn entry1() void { \\ @call(.{}, foo, {}); \\} @@ -33,24 +43,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\inline fn bar() void {} \\fn baz1() void {} \\fn baz2() void {} - , + , &[_][]const u8{ "tmp.zig:2:21: error: expected tuple or struct, found 'void'", "tmp.zig:5:14: error: unable to perform 'never_inline' call at compile-time", "tmp.zig:8:14: error: unable to perform 'never_tail' call at compile-time", "tmp.zig:11:5: error: no-inline call of inline function", "tmp.zig:15:43: error: unable to evaluate constant expression", - ); + }); cases.add("exported async function", \\export async fn foo() void {} - , "tmp.zig:1:1: error: exported function cannot be async"); + , &[_][]const u8{ + "tmp.zig:1:1: error: exported function cannot be async", + }); - cases.addExe( - "main missing name", + cases.addExe("main missing name", \\pub fn (main) void {} - , + , &[_][]const u8{ "tmp.zig:1:5: error: missing function name", - ); + }); cases.addCase(x: { var tc = cases.create("call with new stack on unsupported target", @@ -59,7 +70,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ @call(.{.stack = &buf}, foo, .{}); \\} \\fn foo() void {} - , "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack"); + , &[_][]const u8{ + "tmp.zig:3:5: error: target arch 'wasm32' does not support calling with a new stack", + }); tc.target = tests.Target{ .Cross = tests.CrossTarget{ .arch = .wasm32, @@ -72,8 +85,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { // Note: One of the error messages here is backwards. It would be nice to fix, but that's not // going to stop me from merging this branch which fixes a bunch of other stuff. - cases.add( - "incompatible sentinels", + cases.add("incompatible sentinels", \\export fn entry1(ptr: [*:255]u8) [*:0]u8 { \\ return ptr; \\} @@ -86,7 +98,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry4() void { \\ var array: [2:0]u8 = [_]u8{1, 2}; \\} - , + , &[_][]const u8{ "tmp.zig:2:12: error: expected type '[*:0]u8', found '[*:255]u8'", "tmp.zig:2:12: note: destination pointer requires a terminating '0' sentinel, but source pointer has a terminating '255' sentinel", "tmp.zig:5:12: error: expected type '[*:0]u8', found '[*]u8'", @@ -96,20 +108,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "tmp.zig:8:35: note: destination array requires a terminating '255' sentinel, but source array has a terminating '0' sentinel", "tmp.zig:11:31: error: expected type '[2:0]u8', found '[2]u8'", "tmp.zig:11:31: note: destination array requires a terminating '0' sentinel", - ); + }); - cases.add( - "empty switch on an integer", + cases.add("empty switch on an integer", \\export fn entry() void { \\ var x: u32 = 0; \\ switch(x) {} \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: switch must handle all possibilities", - ); + }); - cases.add( - "incorrect return type", + cases.add("incorrect return type", \\ pub export fn entry() void{ \\ _ = foo(); \\ } @@ -125,12 +135,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ fn bar() B { \\ unreachable; \\ } - , + , &[_][]const u8{ "tmp.zig:8:16: error: expected type 'A', found 'B'", - ); + }); - cases.add( - "regression test #2980: base type u32 is not type checked properly when assigning a value within a struct", + cases.add("regression test #2980: base type u32 is not type checked properly when assigning a value within a struct", \\const Foo = struct { \\ ptr: ?*usize, \\ uval: u32, @@ -144,12 +153,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ .uval = get_uval(42), \\ }; \\} - , + , &[_][]const u8{ "tmp.zig:11:25: error: expected type 'u32', found '@typeOf(get_uval).ReturnType.ErrorSet!u32'", - ); + }); - cases.add( - "asigning to struct or union fields that are not optionals with a function that returns an optional", + cases.add("asigning to struct or union fields that are not optionals with a function that returns an optional", \\fn maybe(is: bool) ?u8 { \\ if (is) return @as(u8, 10) else return null; \\} @@ -163,24 +171,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var u = U{ .Ye = maybe(false) }; \\ var s = S{ .num = maybe(false) }; \\} - , + , &[_][]const u8{ "tmp.zig:11:27: error: expected type 'u8', found '?u8'", - ); + }); - cases.add( - "missing result type for phi node", + cases.add("missing result type for phi node", \\fn foo() !void { \\ return anyerror.Foo; \\} \\export fn entry() void { \\ foo() catch 0; \\} - , + , &[_][]const u8{ "tmp.zig:5:17: error: integer value 0 cannot be coerced to type 'void'", - ); + }); - cases.add( - "atomicrmw with enum op not .Xchg", + cases.add("atomicrmw with enum op not .Xchg", \\export fn entry() void { \\ const E = enum(u8) { \\ a, @@ -191,34 +197,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var x: E = .a; \\ _ = @atomicRmw(E, &x, .Add, .b, .SeqCst); \\} - , + , &[_][]const u8{ "tmp.zig:9:27: error: @atomicRmw on enum only works with .Xchg", - ); + }); - cases.add( - "disallow coercion from non-null-terminated pointer to null-terminated pointer", + cases.add("disallow coercion from non-null-terminated pointer to null-terminated pointer", \\extern fn puts(s: [*:0]const u8) c_int; \\pub fn main() void { \\ const no_zero_array = [_]u8{'h', 'e', 'l', 'l', 'o'}; \\ const no_zero_ptr: [*]const u8 = &no_zero_array; \\ _ = puts(no_zero_ptr); \\} - , + , &[_][]const u8{ "tmp.zig:5:14: error: expected type '[*:0]const u8', found '[*]const u8'", - ); + }); - cases.add( - "atomic orderings of atomicStore Acquire or AcqRel", + cases.add("atomic orderings of atomicStore Acquire or AcqRel", \\export fn entry() void { \\ var x: u32 = 0; \\ @atomicStore(u32, &x, 1, .Acquire); \\} - , + , &[_][]const u8{ "tmp.zig:3:30: error: @atomicStore atomic ordering must not be Acquire or AcqRel", - ); + }); - cases.add( - "missing const in slice with nested array type", + cases.add("missing const in slice with nested array type", \\const Geo3DTex2D = struct { vertices: [][2]f32 }; \\pub fn getGeo3DTex2D() Geo3DTex2D { \\ return Geo3DTex2D{ @@ -230,34 +233,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ var geo_data = getGeo3DTex2D(); \\} - , + , &[_][]const u8{ "tmp.zig:4:30: error: array literal requires address-of operator to coerce to slice type '[][2]f32'", - ); + }); - cases.add( - "slicing of global undefined pointer", + cases.add("slicing of global undefined pointer", \\var buf: *[1]u8 = undefined; \\export fn entry() void { \\ _ = buf[0..1]; \\} - , + , &[_][]const u8{ "tmp.zig:3:12: error: non-zero length slice of undefined pointer", - ); + }); - cases.add( - "using invalid types in function call raises an error", + cases.add("using invalid types in function call raises an error", \\const MenuEffect = enum {}; \\fn func(effect: MenuEffect) void {} \\export fn entry() void { \\ func(MenuEffect.ThisDoesNotExist); \\} - , + , &[_][]const u8{ "tmp.zig:1:20: error: enums must have 1 or more fields", "tmp.zig:4:20: note: referenced here", - ); + }); - cases.add( - "store vector pointer with unknown runtime index", + cases.add("store vector pointer with unknown runtime index", \\export fn entry() void { \\ var v: @Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; \\ @@ -268,12 +268,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn storev(ptr: var, val: i32) void { \\ ptr.* = val; \\} - , + , &[_][]const u8{ "tmp.zig:9:8: error: unable to determine vector element index of type '*align(16:0:4:?) i32", - ); + }); - cases.add( - "load vector pointer with unknown runtime index", + cases.add("load vector pointer with unknown runtime index", \\export fn entry() void { \\ var v: @Vector(4, i32) = [_]i32{ 1, 5, 3, undefined }; \\ @@ -284,12 +283,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn loadv(ptr: var) i32 { \\ return ptr.*; \\} - , + , &[_][]const u8{ "tmp.zig:9:12: error: unable to determine vector element index of type '*align(16:0:4:?) i32", - ); + }); - cases.add( - "using an unknown len ptr type instead of array", + cases.add("using an unknown len ptr type instead of array", \\const resolutions = [*][*]const u8{ \\ "[320 240 ]", \\ null, @@ -297,22 +295,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\comptime { \\ _ = resolutions; \\} - , + , &[_][]const u8{ "tmp.zig:1:21: error: expected array type or [_], found '[*][*]const u8'", - ); + }); - cases.add( - "comparison with error union and error value", + cases.add("comparison with error union and error value", \\export fn entry() void { \\ var number_or_error: anyerror!i32 = error.SomethingAwful; \\ _ = number_or_error == error.SomethingAwful; \\} - , + , &[_][]const u8{ "tmp.zig:3:25: error: operator not allowed for type 'anyerror!i32'", - ); + }); - cases.add( - "switch with overlapping case ranges", + cases.add("switch with overlapping case ranges", \\export fn entry() void { \\ var q: u8 = 0; \\ switch (q) { @@ -320,22 +316,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ 0...255 => {}, \\ } \\} - , + , &[_][]const u8{ "tmp.zig:5:9: error: duplicate switch value", - ); + }); - cases.add( - "invalid optional type in extern struct", + cases.add("invalid optional type in extern struct", \\const stroo = extern struct { \\ moo: ?[*c]u8, \\}; \\export fn testf(fluff: *stroo) void {} - , + , &[_][]const u8{ "tmp.zig:2:5: error: extern structs cannot contain fields of type '?[*c]u8'", - ); + }); - cases.add( - "attempt to negate a non-integer, non-float or non-vector type", + cases.add("attempt to negate a non-integer, non-float or non-vector type", \\fn foo() anyerror!u32 { \\ return 1; \\} @@ -343,42 +337,38 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ const x = -foo(); \\} - , + , &[_][]const u8{ "tmp.zig:6:15: error: negation of type 'anyerror!u32'", - ); + }); - cases.add( - "attempt to create 17 bit float type", + cases.add("attempt to create 17 bit float type", \\const builtin = @import("builtin"); \\comptime { \\ _ = @Type(builtin.TypeInfo { .Float = builtin.TypeInfo.Float { .bits = 17 } }); \\} - , + , &[_][]const u8{ "tmp.zig:3:32: error: 17-bit float unsupported", - ); + }); - cases.add( - "wrong type for @Type", + cases.add("wrong type for @Type", \\export fn entry() void { \\ _ = @Type(0); \\} - , + , &[_][]const u8{ "tmp.zig:2:15: error: expected type 'std.builtin.TypeInfo', found 'comptime_int'", - ); + }); - cases.add( - "@Type with non-constant expression", + cases.add("@Type with non-constant expression", \\const builtin = @import("builtin"); \\var globalTypeInfo : builtin.TypeInfo = undefined; \\export fn entry() void { \\ _ = @Type(globalTypeInfo); \\} - , + , &[_][]const u8{ "tmp.zig:4:15: error: unable to evaluate constant expression", - ); + }); - cases.add( - "@Type with TypeInfo.Int", + cases.add("@Type with TypeInfo.Int", \\const builtin = @import("builtin"); \\export fn entry() void { \\ _ = @Type(builtin.TypeInfo.Int { @@ -386,21 +376,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ .bits = 8, \\ }); \\} - , + , &[_][]const u8{ "tmp.zig:3:36: error: expected type 'std.builtin.TypeInfo', found 'std.builtin.Int'", - ); + }); - cases.add( - "Struct unavailable for @Type", + cases.add("Struct unavailable for @Type", \\export fn entry() void { \\ _ = @Type(@typeInfo(struct { })); \\} - , + , &[_][]const u8{ "tmp.zig:2:15: error: @Type not availble for 'TypeInfo.Struct'", - ); + }); - cases.add( - "wrong type for result ptr to @asyncCall", + cases.add("wrong type for result ptr to @asyncCall", \\export fn entry() void { \\ _ = async amain(); \\} @@ -411,32 +399,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn foo() i32 { \\ return 1234; \\} - , + , &[_][]const u8{ "tmp.zig:6:37: error: expected type '*i32', found 'bool'", - ); + }); - cases.add( - "shift amount has to be an integer type", + cases.add("shift amount has to be an integer type", \\export fn entry() void { \\ const x = 1 << &@as(u8, 10); \\} - , + , &[_][]const u8{ "tmp.zig:2:21: error: shift amount has to be an integer type, but found '*u8'", "tmp.zig:2:17: note: referenced here", - ); + }); - cases.add( - "bit shifting only works on integer types", + cases.add("bit shifting only works on integer types", \\export fn entry() void { \\ const x = &@as(u8, 1) << 10; \\} - , + , &[_][]const u8{ "tmp.zig:2:16: error: bit shifting operation expected integer type, found '*u8'", "tmp.zig:2:27: note: referenced here", - ); + }); - cases.add( - "struct depends on itself via optional field", + cases.add("struct depends on itself via optional field", \\const LhsExpr = struct { \\ rhsExpr: ?AstObject, \\}; @@ -447,14 +432,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ const lhsExpr = LhsExpr{ .rhsExpr = null }; \\ const obj = AstObject{ .lhsExpr = lhsExpr }; \\} - , + , &[_][]const u8{ "tmp.zig:1:17: error: struct 'LhsExpr' depends on itself", "tmp.zig:5:5: note: while checking this field", "tmp.zig:2:5: note: while checking this field", - ); + }); - cases.add( - "alignment of enum field specified", + cases.add("alignment of enum field specified", \\const Number = enum { \\ a, \\ b align(i32), @@ -462,23 +446,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry1() void { \\ var x: Number = undefined; \\} - , + , &[_][]const u8{ "tmp.zig:3:13: error: structs and unions, not enums, support field alignment", "tmp.zig:1:16: note: consider 'union(enum)' here", - ); + }); - cases.add( - "bad alignment type", + cases.add("bad alignment type", \\export fn entry1() void { \\ var x: []align(true) i32 = undefined; \\} \\export fn entry2() void { \\ var x: *align(@as(f64, 12.34)) i32 = undefined; \\} - , + , &[_][]const u8{ "tmp.zig:2:20: error: expected type 'u29', found 'bool'", "tmp.zig:5:19: error: fractional component prevents float value 12.340000 from being casted to type 'u29'", - ); + }); cases.addCase(x: { var tc = cases.create("variable in inline assembly template cannot be found", @@ -488,7 +471,9 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ : [bar] "=r" (-> usize) \\ ); \\} - , "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs"); + , &[_][]const u8{ + "tmp.zig:2:14: error: could not find 'foo' in the inputs or outputs", + }); tc.target = tests.Target{ .Cross = tests.CrossTarget{ .arch = .x86_64, @@ -499,8 +484,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { break :x tc; }); - cases.add( - "indirect recursion of async functions detected", + cases.add("indirect recursion of async functions detected", \\var frame: ?anyframe = null; \\ \\export fn a() void { @@ -529,14 +513,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var child = rangeSum(x - 1); \\ return child + 1; \\} - , + , &[_][]const u8{ "tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself", "tmp.zig:15:33: note: when analyzing type '@Frame(rangeSum)' here", "tmp.zig:26:25: note: when analyzing type '@Frame(rangeSumIndirect)' here", - ); + }); - cases.add( - "non-async function pointer eventually is inferred to become async", + cases.add("non-async function pointer eventually is inferred to become async", \\export fn a() void { \\ var non_async_fn: fn () void = undefined; \\ non_async_fn = func; @@ -544,45 +527,41 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn func() void { \\ suspend; \\} - , + , &[_][]const u8{ "tmp.zig:5:1: error: 'func' cannot be async", "tmp.zig:3:20: note: required to be non-async here", "tmp.zig:6:5: note: suspends here", - ); + }); - cases.add( - "bad alignment in @asyncCall", + cases.add("bad alignment in @asyncCall", \\export fn entry() void { \\ var ptr: async fn () void = func; \\ var bytes: [64]u8 = undefined; \\ _ = @asyncCall(&bytes, {}, ptr); \\} \\async fn func() void {} - , + , &[_][]const u8{ "tmp.zig:4:21: error: expected type '[]align(16) u8', found '*[64]u8'", - ); + }); - cases.add( - "atomic orderings of fence Acquire or stricter", + cases.add("atomic orderings of fence Acquire or stricter", \\export fn entry() void { \\ @fence(.Monotonic); \\} - , + , &[_][]const u8{ "tmp.zig:2:12: error: atomic ordering must be Acquire or stricter", - ); + }); - cases.add( - "bad alignment in implicit cast from array pointer to slice", + cases.add("bad alignment in implicit cast from array pointer to slice", \\export fn a() void { \\ var x: [10]u8 = undefined; \\ var y: []align(16) u8 = &x; \\} - , + , &[_][]const u8{ "tmp.zig:3:30: error: expected type '[]align(16) u8', found '*[10]u8'", - ); + }); - cases.add( - "result location incompatibility mismatching handle_is_ptr (generic call)", + cases.add("result location incompatibility mismatching handle_is_ptr (generic call)", \\export fn entry() void { \\ var damn = Container{ \\ .not_optional = getOptional(i32), @@ -594,12 +573,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\pub const Container = struct { \\ not_optional: i32, \\}; - , + , &[_][]const u8{ "tmp.zig:3:36: error: expected type 'i32', found '?i32'", - ); + }); - cases.add( - "result location incompatibility mismatching handle_is_ptr", + cases.add("result location incompatibility mismatching handle_is_ptr", \\export fn entry() void { \\ var damn = Container{ \\ .not_optional = getOptional(), @@ -611,12 +589,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\pub const Container = struct { \\ not_optional: i32, \\}; - , + , &[_][]const u8{ "tmp.zig:3:36: error: expected type 'i32', found '?i32'", - ); + }); - cases.add( - "const frame cast to anyframe", + cases.add("const frame cast to anyframe", \\export fn a() void { \\ const f = async func(); \\ resume f; @@ -628,13 +605,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn func() void { \\ suspend; \\} - , + , &[_][]const u8{ "tmp.zig:3:12: error: expected type 'anyframe', found '*const @Frame(func)'", "tmp.zig:7:24: error: expected type 'anyframe', found '*const @Frame(func)'", - ); + }); - cases.add( - "prevent bad implicit casting of anyframe types", + cases.add("prevent bad implicit casting of anyframe types", \\export fn a() void { \\ var x: anyframe = undefined; \\ var y: anyframe->i32 = x; @@ -648,14 +624,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var y: anyframe->i32 = &x; \\} \\fn func() void {} - , + , &[_][]const u8{ "tmp.zig:3:28: error: expected type 'anyframe->i32', found 'anyframe'", "tmp.zig:7:28: error: expected type 'anyframe->i32', found 'i32'", "tmp.zig:11:29: error: expected type 'anyframe->i32', found '*@Frame(func)'", - ); + }); - cases.add( - "wrong frame type used for async call", + cases.add("wrong frame type used for async call", \\export fn entry() void { \\ var frame: @Frame(foo) = undefined; \\ frame = async bar(); @@ -666,37 +641,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn bar() void { \\ suspend; \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: expected type '*@Frame(bar)', found '*@Frame(foo)'", - ); + }); - cases.add( - "@Frame() of generic function", + cases.add("@Frame() of generic function", \\export fn entry() void { \\ var frame: @Frame(func) = undefined; \\} \\fn func(comptime T: type) void { \\ var x: T = undefined; \\} - , + , &[_][]const u8{ "tmp.zig:2:16: error: @Frame() of generic function", - ); + }); - cases.add( - "@frame() causes function to be async", + cases.add("@frame() causes function to be async", \\export fn entry() void { \\ func(); \\} \\fn func() void { \\ _ = @frame(); \\} - , + , &[_][]const u8{ "tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async", "tmp.zig:5:9: note: @frame() causes function to be async", - ); + }); - cases.add( - "invalid suspend in exported function", + cases.add("invalid suspend in exported function", \\export fn entry() void { \\ var frame = async func(); \\ var result = await frame; @@ -704,13 +676,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn func() void { \\ suspend; \\} - , + , &[_][]const u8{ "tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async", "tmp.zig:3:18: note: await here is a suspend point", - ); + }); - cases.add( - "async function indirectly depends on its own frame", + cases.add("async function indirectly depends on its own frame", \\export fn entry() void { \\ _ = async amain(); \\} @@ -720,39 +691,36 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn other() void { \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined; \\} - , + , &[_][]const u8{ "tmp.zig:4:1: error: unable to determine async function frame of 'amain'", "tmp.zig:5:10: note: analysis of function 'other' depends on the frame", "tmp.zig:8:13: note: referenced here", - ); + }); - cases.add( - "async function depends on its own frame", + cases.add("async function depends on its own frame", \\export fn entry() void { \\ _ = async amain(); \\} \\async fn amain() void { \\ var x: [@sizeOf(@Frame(amain))]u8 = undefined; \\} - , + , &[_][]const u8{ "tmp.zig:4:1: error: cannot resolve '@Frame(amain)': function not fully analyzed yet", "tmp.zig:5:13: note: referenced here", - ); + }); - cases.add( - "non async function pointer passed to @asyncCall", + cases.add("non async function pointer passed to @asyncCall", \\export fn entry() void { \\ var ptr = afunc; \\ var bytes: [100]u8 align(16) = undefined; \\ _ = @asyncCall(&bytes, {}, ptr); \\} \\fn afunc() void { } - , + , &[_][]const u8{ "tmp.zig:4:32: error: expected async function, found 'fn() void'", - ); + }); - cases.add( - "runtime-known async function called", + cases.add("runtime-known async function called", \\export fn entry() void { \\ _ = async amain(); \\} @@ -761,24 +729,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ _ = ptr(); \\} \\async fn afunc() void {} - , + , &[_][]const u8{ "tmp.zig:6:12: error: function is not comptime-known; @asyncCall required", - ); + }); - cases.add( - "runtime-known function called with async keyword", + cases.add("runtime-known function called with async keyword", \\export fn entry() void { \\ var ptr = afunc; \\ _ = async ptr(); \\} \\ \\async fn afunc() void { } - , + , &[_][]const u8{ "tmp.zig:3:15: error: function is not comptime-known; @asyncCall required", - ); + }); - cases.add( - "function with ccc indirectly calling async function", + cases.add("function with ccc indirectly calling async function", \\export fn entry() void { \\ foo(); \\} @@ -788,15 +754,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn bar() void { \\ suspend; \\} - , + , &[_][]const u8{ "tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async", "tmp.zig:2:8: note: async function call here", "tmp.zig:5:8: note: async function call here", "tmp.zig:8:5: note: suspends here", - ); + }); - cases.add( - "capture group on switch prong with incompatible payload types", + cases.add("capture group on switch prong with incompatible payload types", \\const Union = union(enum) { \\ A: usize, \\ B: isize, @@ -807,59 +772,53 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ .A, .B => |e| unreachable, \\ } \\} - , + , &[_][]const u8{ "tmp.zig:8:20: error: capture group with incompatible types", "tmp.zig:8:9: note: type 'usize' here", "tmp.zig:8:13: note: type 'isize' here", - ); + }); - cases.add( - "wrong type to @hasField", + cases.add("wrong type to @hasField", \\export fn entry() bool { \\ return @hasField(i32, "hi"); \\} - , + , &[_][]const u8{ "tmp.zig:2:22: error: type 'i32' does not support @hasField", - ); + }); - cases.add( - "slice passed as array init type with elems", + cases.add("slice passed as array init type with elems", \\export fn entry() void { \\ const x = []u8{1, 2}; \\} - , + , &[_][]const u8{ "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'", - ); + }); - cases.add( - "slice passed as array init type", + cases.add("slice passed as array init type", \\export fn entry() void { \\ const x = []u8{}; \\} - , + , &[_][]const u8{ "tmp.zig:2:15: error: array literal requires address-of operator to coerce to slice type '[]u8'", - ); + }); - cases.add( - "inferred array size invalid here", + cases.add("inferred array size invalid here", \\export fn entry() void { \\ const x = [_]u8; \\} - , + , &[_][]const u8{ "tmp.zig:2:15: error: inferred array size invalid here", - ); + }); - cases.add( - "initializing array with struct syntax", + cases.add("initializing array with struct syntax", \\export fn entry() void { \\ const x = [_]u8{ .y = 2 }; \\} - , + , &[_][]const u8{ "tmp.zig:2:15: error: initializing array with struct syntax", - ); + }); - cases.add( - "compile error in struct init expression", + cases.add("compile error in struct init expression", \\const Foo = struct { \\ a: i32 = crap, \\ b: i32, @@ -869,54 +828,49 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ .b = 5, \\ }; \\} - , + , &[_][]const u8{ "tmp.zig:2:14: error: use of undeclared identifier 'crap'", - ); + }); - cases.add( - "undefined as field type is rejected", + cases.add("undefined as field type is rejected", \\const Foo = struct { \\ a: undefined, \\}; \\export fn entry1() void { \\ const foo: Foo = undefined; \\} - , + , &[_][]const u8{ "tmp.zig:2:8: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "@hasDecl with non-container", + cases.add("@hasDecl with non-container", \\export fn entry() void { \\ _ = @hasDecl(i32, "hi"); \\} - , + , &[_][]const u8{ "tmp.zig:2:18: error: expected struct, enum, or union; found 'i32'", - ); + }); - cases.add( - "field access of slices", + cases.add("field access of slices", \\export fn entry() void { \\ var slice: []i32 = undefined; \\ const info = @typeOf(slice).unknown; \\} - , + , &[_][]const u8{ "tmp.zig:3:32: error: type '[]i32' does not support field access", - ); + }); - cases.add( - "peer cast then implicit cast const pointer to mutable C pointer", + cases.add("peer cast then implicit cast const pointer to mutable C pointer", \\export fn func() void { \\ var strValue: [*c]u8 = undefined; \\ strValue = strValue orelse ""; \\} - , + , &[_][]const u8{ "tmp.zig:3:32: error: expected type '[*c]u8', found '*const [0:0]u8'", "tmp.zig:3:32: note: cast discards const qualifier", - ); + }); - cases.add( - "overflow in enum value allocation", + cases.add("overflow in enum value allocation", \\const Moo = enum(u8) { \\ Last = 255, \\ Over, @@ -924,32 +878,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\pub fn main() void { \\ var y = Moo.Last; \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: enumeration value 256 too large for type 'u8'", - ); + }); - cases.add( - "attempt to cast enum literal to error", + cases.add("attempt to cast enum literal to error", \\export fn entry() void { \\ switch (error.Hi) { \\ .Hi => {}, \\ } \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: expected type 'error{Hi}', found '(enum literal)'", - ); + }); - cases.add( - "@sizeOf bad type", + cases.add("@sizeOf bad type", \\export fn entry() usize { \\ return @sizeOf(@typeOf(null)); \\} - , + , &[_][]const u8{ "tmp.zig:2:20: error: no size available for type '(null)'", - ); + }); - cases.add( - "generic function where return type is self-referenced", + cases.add("generic function where return type is self-referenced", \\fn Foo(comptime T: type) Foo(T) { \\ return struct{ x: T }; \\} @@ -958,22 +909,20 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ .x = 1 \\ }; \\} - , + , &[_][]const u8{ "tmp.zig:1:29: error: evaluation exceeded 1000 backwards branches", "tmp.zig:5:18: note: referenced here", - ); + }); - cases.add( - "@ptrToInt 0 to non optional pointer", + cases.add("@ptrToInt 0 to non optional pointer", \\export fn entry() void { \\ var b = @intToPtr(*i32, 0); \\} - , + , &[_][]const u8{ "tmp.zig:2:13: error: pointer type '*i32' does not allow address zero", - ); + }); - cases.add( - "cast enum literal to enum but it doesn't match", + cases.add("cast enum literal to enum but it doesn't match", \\const Foo = enum { \\ a, \\ b, @@ -981,34 +930,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ const x: Foo = .c; \\} - , + , &[_][]const u8{ "tmp.zig:6:20: error: enum 'Foo' has no field named 'c'", "tmp.zig:1:13: note: 'Foo' declared here", - ); + }); - cases.add( - "discarding error value", + cases.add("discarding error value", \\export fn entry() void { \\ _ = foo(); \\} \\fn foo() !void { \\ return error.OutOfMemory; \\} - , + , &[_][]const u8{ "tmp.zig:2:12: error: error is discarded", - ); + }); - cases.add( - "volatile on global assembly", + cases.add("volatile on global assembly", \\comptime { \\ asm volatile (""); \\} - , + , &[_][]const u8{ "tmp.zig:2:9: error: volatile is meaningless on global assembly", - ); + }); - cases.add( - "invalid multiple dereferences", + cases.add("invalid multiple dereferences", \\export fn a() void { \\ var box = Box{ .field = 0 }; \\ box.*.field = 1; @@ -1021,20 +967,18 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\pub const Box = struct { \\ field: i32, \\}; - , + , &[_][]const u8{ "tmp.zig:3:8: error: attempt to dereference non-pointer type 'Box'", "tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box'", - ); + }); - cases.add( - "usingnamespace with wrong type", + cases.add("usingnamespace with wrong type", \\usingnamespace void; - , + , &[_][]const u8{ "tmp.zig:1:1: error: expected struct, enum, or union; found 'void'", - ); + }); - cases.add( - "ignored expression in while continuation", + cases.add("ignored expression in while continuation", \\export fn a() void { \\ while (true) : (bad()) {} \\} @@ -1049,96 +993,86 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn bad() anyerror!void { \\ return error.Bad; \\} - , + , &[_][]const u8{ "tmp.zig:2:24: error: expression value is ignored", "tmp.zig:6:25: error: expression value is ignored", "tmp.zig:10:25: error: expression value is ignored", - ); + }); - cases.add( - "empty while loop body", + cases.add("empty while loop body", \\export fn a() void { \\ while(true); \\} - , + , &[_][]const u8{ "tmp.zig:2:16: error: expected loop body, found ';'", - ); + }); - cases.add( - "empty for loop body", + cases.add("empty for loop body", \\export fn a() void { \\ for(undefined) |x|; \\} - , + , &[_][]const u8{ "tmp.zig:2:23: error: expected loop body, found ';'", - ); + }); - cases.add( - "empty if body", + cases.add("empty if body", \\export fn a() void { \\ if(true); \\} - , + , &[_][]const u8{ "tmp.zig:2:13: error: expected if body, found ';'", - ); + }); - cases.add( - "import outside package path", + cases.add("import outside package path", \\comptime{ \\ _ = @import("../a.zig"); \\} - , + , &[_][]const u8{ "tmp.zig:2:9: error: import of file outside package path: '../a.zig'", - ); + }); - cases.add( - "bogus compile var", + cases.add("bogus compile var", \\const x = @import("builtin").bogus; \\export fn entry() usize { return @sizeOf(@typeOf(x)); } - , + , &[_][]const u8{ "tmp.zig:1:29: error: container 'builtin' has no member called 'bogus'", - ); + }); - cases.add( - "wrong panic signature, runtime function", + cases.add("wrong panic signature, runtime function", \\test "" {} \\ \\pub fn panic() void {} \\ - , + , &[_][]const u8{ "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn() void'", - ); + }); - cases.add( - "wrong panic signature, generic function", + cases.add("wrong panic signature, generic function", \\pub fn panic(comptime msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { \\ while (true) {} \\} - , + , &[_][]const u8{ "error: expected type 'fn([]const u8, ?*std.builtin.StackTrace) noreturn', found 'fn([]const u8,var)var'", "note: only one of the functions is generic", - ); + }); - cases.add( - "direct struct loop", + cases.add("direct struct loop", \\const A = struct { a : A, }; \\export fn entry() usize { return @sizeOf(A); } - , + , &[_][]const u8{ "tmp.zig:1:11: error: struct 'A' depends on itself", - ); + }); - cases.add( - "indirect struct loop", + cases.add("indirect struct loop", \\const A = struct { b : B, }; \\const B = struct { c : C, }; \\const C = struct { a : A, }; \\export fn entry() usize { return @sizeOf(A); } - , + , &[_][]const u8{ "tmp.zig:1:11: error: struct 'A' depends on itself", - ); + }); - cases.add( - "instantiating an undefined value for an invalid struct that contains itself", + cases.add("instantiating an undefined value for an invalid struct that contains itself", \\const Foo = struct { \\ x: Foo, \\}; @@ -1148,13 +1082,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() usize { \\ return @sizeOf(@typeOf(foo.x)); \\} - , + , &[_][]const u8{ "tmp.zig:1:13: error: struct 'Foo' depends on itself", "tmp.zig:8:28: note: referenced here", - ); + }); - cases.add( - "@typeInfo causing depend on itself compile error", + cases.add("@typeInfo causing depend on itself compile error", \\const start = struct { \\ fn crash() bug() { \\ return bug; @@ -1166,14 +1099,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ var boom = start.crash(); \\} - , + , &[_][]const u8{ "tmp.zig:7:9: error: dependency loop detected", "tmp.zig:2:19: note: referenced here", "tmp.zig:10:21: note: referenced here", - ); + }); - cases.add( - "enum field value references enum", + cases.add("enum field value references enum", \\pub const Foo = extern enum { \\ A = Foo.B, \\ C = D, @@ -1181,25 +1113,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ var s: Foo = Foo.E; \\} - , + , &[_][]const u8{ "tmp.zig:1:17: error: enum 'Foo' depends on itself", - ); + }); - cases.add( - "top level decl dependency loop", + cases.add("top level decl dependency loop", \\const a : @typeOf(b) = 0; \\const b : @typeOf(a) = 0; \\export fn entry() void { \\ const c = a + b; \\} - , + , &[_][]const u8{ "tmp.zig:2:19: error: dependency loop detected", "tmp.zig:1:19: note: referenced here", "tmp.zig:4:15: note: referenced here", - ); + }); - cases.addTest( - "not an enum type", + cases.addTest("not an enum type", \\export fn entry() void { \\ var self: Error = undefined; \\ switch (self) { @@ -1213,58 +1143,53 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\}; \\const InvalidToken = struct {}; \\const ExpectedVarDeclOrFn = struct {}; - , + , &[_][]const u8{ "tmp.zig:4:9: error: expected type '@TagType(Error)', found 'type'", - ); + }); - cases.addTest( - "binary OR operator on error sets", + cases.addTest("binary OR operator on error sets", \\pub const A = error.A; \\pub const AB = A | error.B; \\export fn entry() void { \\ var x: AB = undefined; \\} - , + , &[_][]const u8{ "tmp.zig:2:18: error: invalid operands to binary expression: 'error{A}' and 'error{B}'", - ); + }); if (builtin.os == builtin.Os.linux) { - cases.addTest( - "implicit dependency on libc", + cases.addTest("implicit dependency on libc", \\extern "c" fn exit(u8) void; \\export fn entry() void { \\ exit(0); \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: dependency on library c must be explicitly specified in the build command", - ); + }); - cases.addTest( - "libc headers note", + cases.addTest("libc headers note", \\const c = @cImport(@cInclude("stdio.h")); \\export fn entry() void { \\ _ = c.printf("hello, world!\n"); \\} - , + , &[_][]const u8{ "tmp.zig:1:11: error: C import failed", "tmp.zig:1:11: note: libc headers not available; compilation does not link against libc", - ); + }); } - cases.addTest( - "comptime vector overflow shows the index", + cases.addTest("comptime vector overflow shows the index", \\comptime { \\ var a: @Vector(4, u8) = [_]u8{ 1, 2, 255, 4 }; \\ var b: @Vector(4, u8) = [_]u8{ 5, 6, 1, 8 }; \\ var x = a + b; \\} - , + , &[_][]const u8{ "tmp.zig:4:15: error: operation caused overflow", "tmp.zig:4:15: note: when computing vector element at index 2", - ); + }); - cases.addTest( - "packed struct with fields of not allowed types", + cases.addTest("packed struct with fields of not allowed types", \\const A = packed struct { \\ x: anyerror, \\}; @@ -1318,7 +1243,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ A, \\ B, \\}; - , + , &[_][]const u8{ "tmp.zig:2:5: error: type 'anyerror' not allowed in packed struct; no guaranteed in-memory representation", "tmp.zig:5:5: error: array of 'u24' not allowed in packed struct due to padding bits", "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 { "tmp.zig:17:5: error: type '?anyerror' not allowed in packed struct; no guaranteed in-memory representation", "tmp.zig:20:5: error: type 'Enum' not allowed in packed struct; no guaranteed in-memory representation", "tmp.zig:50:14: note: enum declaration does not specify an integer tag type", - ); + }); cases.addCase(x: { - var tc = cases.create( - "deduplicate undeclared identifier", + var tc = cases.create("deduplicate undeclared identifier", \\export fn a() void { \\ x += 1; \\} \\export fn b() void { \\ x += 1; \\} - , + , &[_][]const u8{ "tmp.zig:2:5: error: use of undeclared identifier 'x'", - ); + }); tc.expect_exact = true; break :x tc; }); - cases.add( - "export generic function", + cases.add("export generic function", \\export fn foo(num: var) i32 { \\ return 0; \\} - , + , &[_][]const u8{ "tmp.zig:1:15: error: parameter of type 'var' not allowed in function with calling convention 'ccc'", - ); + }); - cases.add( - "C pointer to c_void", + cases.add("C pointer to c_void", \\export fn a() void { \\ var x: *c_void = undefined; \\ var y: [*c]c_void = x; \\} - , + , &[_][]const u8{ "tmp.zig:3:16: error: C pointers cannot point opaque types", - ); + }); - cases.add( - "directly embedding opaque type in struct and union", + cases.add("directly embedding opaque type in struct and union", \\const O = @OpaqueType(); \\const Foo = struct { \\ o: O, @@ -1380,13 +1301,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn b() void { \\ var bar: Bar = undefined; \\} - , + , &[_][]const u8{ "tmp.zig:3:8: error: opaque types have unknown size and therefore cannot be directly embedded in structs", "tmp.zig:7:10: error: opaque types have unknown size and therefore cannot be directly embedded in unions", - ); + }); - cases.add( - "implicit cast between C pointer and Zig pointer - bad const/align/child", + cases.add("implicit cast between C pointer and Zig pointer - bad const/align/child", \\export fn a() void { \\ var x: [*c]u8 = undefined; \\ var y: *align(4) u8 = x; @@ -1411,7 +1331,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var y: *u8 = undefined; \\ var x: [*c]u32 = y; \\} - , + , &[_][]const u8{ "tmp.zig:3:27: error: cast increases pointer alignment", "tmp.zig:7:18: error: cast discards const qualifier", "tmp.zig:11:19: error: expected type '*u32', found '[*c]u8'", @@ -1419,30 +1339,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { "tmp.zig:15:22: error: cast increases pointer alignment", "tmp.zig:19:21: error: cast discards const qualifier", "tmp.zig:23:22: error: expected type '[*c]u32', found '*u8'", - ); + }); - cases.add( - "implicit casting null c pointer to zig pointer", + cases.add("implicit casting null c pointer to zig pointer", \\comptime { \\ var c_ptr: [*c]u8 = 0; \\ var zig_ptr: *u8 = c_ptr; \\} - , + , &[_][]const u8{ "tmp.zig:3:24: error: null pointer casted to type '*u8'", - ); + }); - cases.add( - "implicit casting undefined c pointer to zig pointer", + cases.add("implicit casting undefined c pointer to zig pointer", \\comptime { \\ var c_ptr: [*c]u8 = undefined; \\ var zig_ptr: *u8 = c_ptr; \\} - , + , &[_][]const u8{ "tmp.zig:3:24: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "implicit casting C pointers which would mess up null semantics", + cases.add("implicit casting C pointers which would mess up null semantics", \\export fn entry() void { \\ var slice: []const u8 = "aoeu"; \\ const opt_many_ptr: [*]const u8 = slice.ptr; @@ -1457,17 +1374,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var ptr_opt_many_ptr = &opt_many_ptr; \\ var c_ptr: [*c][*c]const u8 = ptr_opt_many_ptr; \\} - , + , &[_][]const u8{ "tmp.zig:6:24: error: expected type '*const [*]const u8', found '[*c]const [*c]const u8'", "tmp.zig:6:24: note: pointer type child '[*c]const u8' cannot cast into pointer type child '[*]const u8'", "tmp.zig:6:24: note: '[*c]const u8' could have null values which are illegal in type '[*]const u8'", "tmp.zig:13:35: error: expected type '[*c][*c]const u8', found '*[*]u8'", "tmp.zig:13:35: note: pointer type child '[*]u8' cannot cast into pointer type child '[*c]const u8'", "tmp.zig:13:35: note: mutable '[*c]const u8' allows illegal null values stored to type '[*]u8'", - ); + }); - cases.add( - "implicit casting too big integers to C pointers", + cases.add("implicit casting too big integers to C pointers", \\export fn a() void { \\ var ptr: [*c]u8 = (1 << 64) + 1; \\} @@ -1475,25 +1391,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var x: @IntType(false, 65) = 0x1234; \\ var ptr: [*c]u8 = x; \\} - , + , &[_][]const u8{ "tmp.zig:2:33: error: integer value 18446744073709551617 cannot be coerced to type 'usize'", "tmp.zig:6:23: error: integer type 'u65' too big for implicit @intToPtr to type '[*c]u8'", - ); + }); - cases.add( - "C pointer pointing to non C ABI compatible type or has align attr", + cases.add("C pointer pointing to non C ABI compatible type or has align attr", \\const Foo = struct {}; \\export fn a() void { \\ const T = [*c]Foo; \\ var t: T = undefined; \\} - , + , &[_][]const u8{ "tmp.zig:3:19: error: C pointers cannot point to non-C-ABI-compatible type 'Foo'", - ); + }); cases.addCase(x: { - var tc = cases.create( - "compile log statement warning deduplication in generic fn", + var tc = cases.create("compile log statement warning deduplication in generic fn", \\export fn entry() void { \\ inner(1); \\ inner(2); @@ -1502,111 +1416,100 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ comptime var i = 0; \\ inline while (i < n) : (i += 1) { @compileLog("!@#$"); } \\} - , + , &[_][]const u8{ "tmp.zig:7:39: error: found compile log statement", - ); + }); tc.expect_exact = true; break :x tc; }); - cases.add( - "assign to invalid dereference", + cases.add("assign to invalid dereference", \\export fn entry() void { \\ 'a'.* = 1; \\} - , + , &[_][]const u8{ "tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int'", - ); + }); - cases.add( - "take slice of invalid dereference", + cases.add("take slice of invalid dereference", \\export fn entry() void { \\ const x = 'a'.*[0..]; \\} - , + , &[_][]const u8{ "tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int'", - ); + }); - cases.add( - "@truncate undefined value", + cases.add("@truncate undefined value", \\export fn entry() void { \\ var z = @truncate(u8, @as(u16, undefined)); \\} - , + , &[_][]const u8{ "tmp.zig:2:27: error: use of undefined value here causes undefined behavior", - ); + }); - cases.addTest( - "return invalid type from test", + cases.addTest("return invalid type from test", \\test "example" { return 1; } - , + , &[_][]const u8{ "tmp.zig:1:25: error: integer value 1 cannot be coerced to type 'void'", - ); + }); - cases.add( - "threadlocal qualifier on const", + cases.add("threadlocal qualifier on const", \\threadlocal const x: i32 = 1234; \\export fn entry() i32 { \\ return x; \\} - , + , &[_][]const u8{ "tmp.zig:1:13: error: threadlocal variable cannot be constant", - ); + }); - cases.add( - "@bitCast same size but bit count mismatch", + cases.add("@bitCast same size but bit count mismatch", \\export fn entry(byte: u8) void { \\ var oops = @bitCast(u7, byte); \\} - , + , &[_][]const u8{ "tmp.zig:2:25: error: destination type 'u7' has 7 bits but source type 'u8' has 8 bits", - ); + }); - cases.add( - "@bitCast with different sizes inside an expression", + cases.add("@bitCast with different sizes inside an expression", \\export fn entry() void { \\ var foo = (@bitCast(u8, @as(f32, 1.0)) == 0xf); \\} - , + , &[_][]const u8{ "tmp.zig:2:25: error: destination type 'u8' has size 1 but source type 'f32' has size 4", - ); + }); - cases.add( - "attempted `&&`", + cases.add("attempted `&&`", \\export fn entry(a: bool, b: bool) i32 { \\ if (a && b) { \\ return 1234; \\ } \\ return 5678; \\} - , + , &[_][]const u8{ "tmp.zig:2:12: error: `&&` is invalid. Note that `and` is boolean AND", - ); + }); - cases.add( - "attempted `||` on boolean values", + cases.add("attempted `||` on boolean values", \\export fn entry(a: bool, b: bool) i32 { \\ if (a || b) { \\ return 1234; \\ } \\ return 5678; \\} - , + , &[_][]const u8{ "tmp.zig:2:9: error: expected error set type, found 'bool'", "tmp.zig:2:11: note: `||` merges error sets; `or` performs boolean OR", - ); + }); - cases.add( - "compile log a pointer to an opaque value", + cases.add("compile log a pointer to an opaque value", \\export fn entry() void { \\ @compileLog(@ptrCast(*const c_void, &entry)); \\} - , + , &[_][]const u8{ "tmp.zig:2:5: error: found compile log statement", - ); + }); - cases.add( - "duplicate boolean switch value", + cases.add("duplicate boolean switch value", \\comptime { \\ const x = switch (true) { \\ true => false, @@ -1621,13 +1524,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ false => true, \\ }; \\} - , + , &[_][]const u8{ "tmp.zig:5:9: error: duplicate switch value", "tmp.zig:12:9: error: duplicate switch value", - ); + }); - cases.add( - "missing boolean switch value", + cases.add("missing boolean switch value", \\comptime { \\ const x = switch (true) { \\ true => false, @@ -1638,37 +1540,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ false => true, \\ }; \\} - , + , &[_][]const u8{ "tmp.zig:2:15: error: switch must handle all possibilities", "tmp.zig:7:15: error: switch must handle all possibilities", - ); + }); - cases.add( - "reading past end of pointer casted array", + cases.add("reading past end of pointer casted array", \\comptime { \\ const array: [4]u8 = "aoeu".*; \\ const slice = array[1..]; \\ const int_ptr = @ptrCast(*const u24, slice.ptr); \\ const deref = int_ptr.*; \\} - , + , &[_][]const u8{ "tmp.zig:5:26: error: attempt to read 4 bytes from [4]u8 at index 1 which is 3 bytes", - ); + }); - cases.add( - "error note for function parameter incompatibility", + cases.add("error note for function parameter incompatibility", \\fn do_the_thing(func: fn (arg: i32) void) void {} \\fn bar(arg: bool) void {} \\export fn entry() void { \\ do_the_thing(bar); \\} - , + , &[_][]const u8{ "tmp.zig:4:18: error: expected type 'fn(i32) void', found 'fn(bool) void", "tmp.zig:4:18: note: parameter 0: 'bool' cannot cast into 'i32'", - ); + }); - cases.add( - "cast negative value to unsigned integer", + cases.add("cast negative value to unsigned integer", \\comptime { \\ const value: i32 = -1; \\ const unsigned = @intCast(u32, value); @@ -1677,13 +1576,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ const value: i32 = -1; \\ const unsigned: u32 = value; \\} - , + , &[_][]const u8{ "tmp.zig:3:36: error: cannot cast negative value -1 to unsigned integer type 'u32'", "tmp.zig:7:27: error: cannot cast negative value -1 to unsigned integer type 'u32'", - ); + }); - cases.add( - "integer cast truncates bits", + cases.add("integer cast truncates bits", \\export fn entry1() void { \\ const spartan_count: u16 = 300; \\ const byte = @intCast(u8, spartan_count); @@ -1700,50 +1598,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var signed: i8 = -1; \\ var unsigned: u64 = signed; \\} - , + , &[_][]const u8{ "tmp.zig:3:31: error: integer value 300 cannot be coerced to type 'u8'", "tmp.zig:7:22: error: integer value 300 cannot be coerced to type 'u8'", "tmp.zig:11:20: error: expected type 'u8', found 'u16'", "tmp.zig:11:20: note: unsigned 8-bit int cannot represent all possible unsigned 16-bit values", "tmp.zig:15:25: error: expected type 'u64', found 'i8'", "tmp.zig:15:25: note: unsigned 64-bit int cannot represent all possible signed 8-bit values", - ); + }); - cases.add( - "comptime implicit cast f64 to f32", + cases.add("comptime implicit cast f64 to f32", \\export fn entry() void { \\ const x: f64 = 16777217; \\ const y: f32 = x; \\} - , + , &[_][]const u8{ "tmp.zig:3:20: error: cast of value 16777217.000000 to type 'f32' loses information", - ); + }); - cases.add( - "implicit cast from f64 to f32", + cases.add("implicit cast from f64 to f32", \\var x: f64 = 1.0; \\var y: f32 = x; \\ \\export fn entry() usize { return @sizeOf(@typeOf(y)); } - , + , &[_][]const u8{ "tmp.zig:2:14: error: expected type 'f32', found 'f64'", - ); + }); - cases.add( - "exceeded maximum bit width of integer", + cases.add("exceeded maximum bit width of integer", \\export fn entry1() void { \\ const T = @IntType(false, 65536); \\} \\export fn entry2() void { \\ var x: i65536 = 1; \\} - , + , &[_][]const u8{ "tmp.zig:2:31: error: integer value 65536 cannot be coerced to type 'u16'", "tmp.zig:5:12: error: primitive integer type 'i65536' exceeds maximum bit width of 65535", - ); + }); - cases.add( - "compile error when evaluating return type of inferred error set", + cases.add("compile error when evaluating return type of inferred error set", \\const Car = struct { \\ foo: *SymbolThatDoesNotExist, \\ pub fn init() !Car {} @@ -1751,24 +1645,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ const car = Car.init(); \\} - , + , &[_][]const u8{ "tmp.zig:2:11: error: use of undeclared identifier 'SymbolThatDoesNotExist'", - ); + }); - cases.add( - "don't implicit cast double pointer to *c_void", + cases.add("don't implicit cast double pointer to *c_void", \\export fn entry() void { \\ var a: u32 = 1; \\ var ptr: *c_void = &a; \\ var b: *u32 = @ptrCast(*u32, ptr); \\ var ptr2: *c_void = &b; \\} - , + , &[_][]const u8{ "tmp.zig:5:26: error: expected type '*c_void', found '**u32'", - ); + }); - cases.add( - "runtime index into comptime type slice", + cases.add("runtime index into comptime type slice", \\const Struct = struct { \\ a: u32, \\}; @@ -1779,12 +1671,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ const index = getIndex(); \\ const field = @typeInfo(Struct).Struct.fields[index]; \\} - , + , &[_][]const u8{ "tmp.zig:9:51: error: values of type 'std.builtin.StructField' must be comptime known, but index value is runtime known", - ); + }); - cases.add( - "compile log statement inside function which must be comptime evaluated", + cases.add("compile log statement inside function which must be comptime evaluated", \\fn Foo(comptime T: type) type { \\ @compileLog(@typeName(T)); \\ return T; @@ -1793,80 +1684,73 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ _ = Foo(i32); \\ _ = @typeName(Foo(i32)); \\} - , + , &[_][]const u8{ "tmp.zig:2:5: error: found compile log statement", - ); + }); - cases.add( - "comptime slice of an undefined slice", + cases.add("comptime slice of an undefined slice", \\comptime { \\ var a: []u8 = undefined; \\ var b = a[0..10]; \\} - , + , &[_][]const u8{ "tmp.zig:3:14: error: slice of undefined", - ); + }); - cases.add( - "implicit cast const array to mutable slice", + cases.add("implicit cast const array to mutable slice", \\export fn entry() void { \\ const buffer: [1]u8 = [_]u8{8}; \\ const sliceA: []u8 = &buffer; \\} - , + , &[_][]const u8{ "tmp.zig:3:27: error: expected type '[]u8', found '*const [1]u8'", - ); + }); - cases.add( - "deref slice and get len field", + cases.add("deref slice and get len field", \\export fn entry() void { \\ var a: []u8 = undefined; \\ _ = a.*.len; \\} - , + , &[_][]const u8{ "tmp.zig:3:10: error: attempt to dereference non-pointer type '[]u8'", - ); + }); - cases.add( - "@ptrCast a 0 bit type to a non- 0 bit type", + cases.add("@ptrCast a 0 bit type to a non- 0 bit type", \\export fn entry() bool { \\ var x: u0 = 0; \\ const p = @ptrCast(?*u0, &x); \\ return p == null; \\} - , + , &[_][]const u8{ "tmp.zig:3:15: error: '*u0' and '?*u0' do not have the same in-memory representation", "tmp.zig:3:31: note: '*u0' has no in-memory bits", "tmp.zig:3:24: note: '?*u0' has in-memory bits", - ); + }); - cases.add( - "comparing a non-optional pointer against null", + cases.add("comparing a non-optional pointer against null", \\export fn entry() void { \\ var x: i32 = 1; \\ _ = &x == null; \\} - , + , &[_][]const u8{ "tmp.zig:3:12: error: comparison of '*i32' with null", - ); + }); - cases.add( - "non error sets used in merge error sets operator", + cases.add("non error sets used in merge error sets operator", \\export fn foo() void { \\ const Errors = u8 || u16; \\} \\export fn bar() void { \\ const Errors = error{} || u16; \\} - , + , &[_][]const u8{ "tmp.zig:2:20: error: expected error set type, found type 'u8'", "tmp.zig:2:23: note: `||` merges error sets; `or` performs boolean OR", "tmp.zig:5:31: error: expected error set type, found type 'u16'", "tmp.zig:5:28: note: `||` merges error sets; `or` performs boolean OR", - ); + }); - cases.add( - "variable initialization compile error then referenced", + cases.add("variable initialization compile error then referenced", \\fn Undeclared() type { \\ return T; \\} @@ -1879,23 +1763,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ const S = Gen(); \\} - , + , &[_][]const u8{ "tmp.zig:2:12: error: use of undeclared identifier 'T'", - ); + }); - cases.add( - "refer to the type of a generic function", + cases.add("refer to the type of a generic function", \\export fn entry() void { \\ const Func = fn (type) void; \\ const f: Func = undefined; \\ f(i32); \\} - , + , &[_][]const u8{ "tmp.zig:4:5: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "accessing runtime parameter from outer function", + cases.add("accessing runtime parameter from outer function", \\fn outer(y: u32) fn (u32) u32 { \\ const st = struct { \\ fn get(z: u32) u32 { @@ -1908,53 +1790,48 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var func = outer(10); \\ var x = func(3); \\} - , + , &[_][]const u8{ "tmp.zig:4:24: error: 'y' not accessible from inner function", "tmp.zig:3:28: note: crossed function definition here", "tmp.zig:1:10: note: declared here", - ); + }); - cases.add( - "non int passed to @intToFloat", + cases.add("non int passed to @intToFloat", \\export fn entry() void { \\ const x = @intToFloat(f32, 1.1); \\} - , + , &[_][]const u8{ "tmp.zig:2:32: error: expected int type, found 'comptime_float'", - ); + }); - cases.add( - "non float passed to @floatToInt", + cases.add("non float passed to @floatToInt", \\export fn entry() void { \\ const x = @floatToInt(i32, @as(i32, 54)); \\} - , + , &[_][]const u8{ "tmp.zig:2:32: error: expected float type, found 'i32'", - ); + }); - cases.add( - "out of range comptime_int passed to @floatToInt", + cases.add("out of range comptime_int passed to @floatToInt", \\export fn entry() void { \\ const x = @floatToInt(i8, 200); \\} - , + , &[_][]const u8{ "tmp.zig:2:31: error: integer value 200 cannot be coerced to type 'i8'", - ); + }); - cases.add( - "load too many bytes from comptime reinterpreted pointer", + cases.add("load too many bytes from comptime reinterpreted pointer", \\export fn entry() void { \\ const float: f32 = 5.99999999999994648725e-01; \\ const float_ptr = &float; \\ const int_ptr = @ptrCast(*const i64, float_ptr); \\ const int_val = int_ptr.*; \\} - , + , &[_][]const u8{ "tmp.zig:5:28: error: attempt to read 8 bytes from pointer to f32 which is 4 bytes", - ); + }); - cases.add( - "invalid type used in array type", + cases.add("invalid type used in array type", \\const Item = struct { \\ field: SomeNonexistentType, \\}; @@ -1962,12 +1839,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ const a = items[0]; \\} - , + , &[_][]const u8{ "tmp.zig:2:12: error: use of undeclared identifier 'SomeNonexistentType'", - ); + }); - cases.add( - "comptime continue inside runtime catch", + cases.add("comptime continue inside runtime catch", \\export fn entry(c: bool) void { \\ const ints = [_]u8{ 1, 2 }; \\ inline for (ints) |_| { @@ -1977,13 +1853,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn bad() !void { \\ return error.Bad; \\} - , + , &[_][]const u8{ "tmp.zig:4:25: error: comptime control flow inside runtime block", "tmp.zig:4:15: note: runtime block created here", - ); + }); - cases.add( - "comptime continue inside runtime switch", + cases.add("comptime continue inside runtime switch", \\export fn entry() void { \\ var p: i32 = undefined; \\ comptime var q = true; @@ -1995,13 +1870,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ q = false; \\ } \\} - , + , &[_][]const u8{ "tmp.zig:6:19: error: comptime control flow inside runtime block", "tmp.zig:5:9: note: runtime block created here", - ); + }); - cases.add( - "comptime continue inside runtime while error", + cases.add("comptime continue inside runtime while error", \\export fn entry() void { \\ var p: anyerror!usize = undefined; \\ comptime var q = true; @@ -2012,13 +1886,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ q = false; \\ } \\} - , + , &[_][]const u8{ "tmp.zig:6:13: error: comptime control flow inside runtime block", "tmp.zig:5:9: note: runtime block created here", - ); + }); - cases.add( - "comptime continue inside runtime while optional", + cases.add("comptime continue inside runtime while optional", \\export fn entry() void { \\ var p: ?usize = undefined; \\ comptime var q = true; @@ -2027,13 +1900,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ q = false; \\ } \\} - , + , &[_][]const u8{ "tmp.zig:5:23: error: comptime control flow inside runtime block", "tmp.zig:5:9: note: runtime block created here", - ); + }); - cases.add( - "comptime continue inside runtime while bool", + cases.add("comptime continue inside runtime while bool", \\export fn entry() void { \\ var p: usize = undefined; \\ comptime var q = true; @@ -2042,13 +1914,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ q = false; \\ } \\} - , + , &[_][]const u8{ "tmp.zig:5:25: error: comptime control flow inside runtime block", "tmp.zig:5:9: note: runtime block created here", - ); + }); - cases.add( - "comptime continue inside runtime if error", + cases.add("comptime continue inside runtime if error", \\export fn entry() void { \\ var p: anyerror!i32 = undefined; \\ comptime var q = true; @@ -2057,13 +1928,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ q = false; \\ } \\} - , + , &[_][]const u8{ "tmp.zig:5:20: error: comptime control flow inside runtime block", "tmp.zig:5:9: note: runtime block created here", - ); + }); - cases.add( - "comptime continue inside runtime if optional", + cases.add("comptime continue inside runtime if optional", \\export fn entry() void { \\ var p: ?i32 = undefined; \\ comptime var q = true; @@ -2072,13 +1942,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ q = false; \\ } \\} - , + , &[_][]const u8{ "tmp.zig:5:20: error: comptime control flow inside runtime block", "tmp.zig:5:9: note: runtime block created here", - ); + }); - cases.add( - "comptime continue inside runtime if bool", + cases.add("comptime continue inside runtime if bool", \\export fn entry() void { \\ var p: usize = undefined; \\ comptime var q = true; @@ -2087,13 +1956,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ q = false; \\ } \\} - , + , &[_][]const u8{ "tmp.zig:5:22: error: comptime control flow inside runtime block", "tmp.zig:5:9: note: runtime block created here", - ); + }); - cases.add( - "switch with invalid expression parameter", + cases.add("switch with invalid expression parameter", \\export fn entry() void { \\ Test(i32); \\} @@ -2104,43 +1972,39 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ else => unreachable, \\ }; \\} - , + , &[_][]const u8{ "tmp.zig:7:17: error: switch on type 'type' provides no expression parameter", - ); + }); - cases.add( - "function protoype with no body", + cases.add("function protoype with no body", \\fn foo() void; \\export fn entry() void { \\ foo(); \\} - , + , &[_][]const u8{ "tmp.zig:1:1: error: non-extern function has no body", - ); + }); - cases.add( - "@frame() called outside of function definition", + cases.add("@frame() called outside of function definition", \\var handle_undef: anyframe = undefined; \\var handle_dummy: anyframe = @frame(); \\export fn entry() bool { \\ return handle_undef == handle_dummy; \\} - , + , &[_][]const u8{ "tmp.zig:2:30: error: @frame() called outside of function definition", - ); + }); - cases.add( - "`_` is not a declarable symbol", + cases.add("`_` is not a declarable symbol", \\export fn f1() usize { \\ var _: usize = 2; \\ return _; \\} - , + , &[_][]const u8{ "tmp.zig:2:5: error: `_` is not a declarable symbol", - ); + }); - cases.add( - "`_` should not be usable inside for", + cases.add("`_` should not be usable inside for", \\export fn returns() void { \\ for ([_]void{}) |_, i| { \\ for ([_]void{}) |_, j| { @@ -2148,12 +2012,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ } \\ } \\} - , + , &[_][]const u8{ "tmp.zig:4:20: error: `_` may only be used to assign things to", - ); + }); - cases.add( - "`_` should not be usable inside while", + cases.add("`_` should not be usable inside while", \\export fn returns() void { \\ while (optionalReturn()) |_| { \\ while (optionalReturn()) |_| { @@ -2164,12 +2027,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn optionalReturn() ?u32 { \\ return 1; \\} - , + , &[_][]const u8{ "tmp.zig:4:20: error: `_` may only be used to assign things to", - ); + }); - cases.add( - "`_` should not be usable inside while else", + cases.add("`_` should not be usable inside while else", \\export fn returns() void { \\ while (optionalReturnError()) |_| { \\ while (optionalReturnError()) |_| { @@ -2182,12 +2044,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn optionalReturnError() !?u32 { \\ return error.optionalReturnError; \\} - , + , &[_][]const u8{ "tmp.zig:6:17: error: `_` may only be used to assign things to", - ); + }); - cases.add( - "while loop body expression ignored", + cases.add("while loop body expression ignored", \\fn returns() usize { \\ return 2; \\} @@ -2202,25 +2063,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var x: anyerror!i32 = error.Bad; \\ while (x) |_| returns() else |_| unreachable; \\} - , + , &[_][]const u8{ "tmp.zig:5:25: error: expression value is ignored", "tmp.zig:9:26: error: expression value is ignored", "tmp.zig:13:26: error: expression value is ignored", - ); + }); - cases.add( - "missing parameter name of generic function", + cases.add("missing parameter name of generic function", \\fn dump(var) void {} \\export fn entry() void { \\ var a: u8 = 9; \\ dump(a); \\} - , + , &[_][]const u8{ "tmp.zig:1:9: error: missing parameter name", - ); + }); - cases.add( - "non-inline for loop on a type that requires comptime", + cases.add("non-inline for loop on a type that requires comptime", \\const Foo = struct { \\ name: []const u8, \\ T: type, @@ -2229,23 +2088,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ const xx: [2]Foo = undefined; \\ for (xx) |f| {} \\} - , + , &[_][]const u8{ "tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known", - ); + }); - cases.add( - "generic fn as parameter without comptime keyword", + cases.add("generic fn as parameter without comptime keyword", \\fn f(_: fn (var) void) void {} \\fn g(_: var) void {} \\export fn entry() void { \\ f(g); \\} - , + , &[_][]const u8{ "tmp.zig:1:9: error: parameter of type 'fn(var)var' must be declared comptime", - ); + }); - cases.add( - "optional pointer to void in extern struct", + cases.add("optional pointer to void in extern struct", \\const Foo = extern struct { \\ x: ?*const void, \\}; @@ -2254,12 +2111,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ y: i32, \\}; \\export fn entry(bar: *Bar) void {} - , + , &[_][]const u8{ "tmp.zig:2:5: error: extern structs cannot contain fields of type '?*const void'", - ); + }); - cases.add( - "use of comptime-known undefined function value", + cases.add("use of comptime-known undefined function value", \\const Cmd = struct { \\ exec: fn () void, \\}; @@ -2267,12 +2123,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ const command = Cmd{ .exec = undefined }; \\ command.exec(); \\} - , + , &[_][]const u8{ "tmp.zig:6:12: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "use of comptime-known undefined function value", + cases.add("use of comptime-known undefined function value", \\const Cmd = struct { \\ exec: fn () void, \\}; @@ -2280,41 +2135,37 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ const command = Cmd{ .exec = undefined }; \\ command.exec(); \\} - , + , &[_][]const u8{ "tmp.zig:6:12: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "bad @alignCast at comptime", + cases.add("bad @alignCast at comptime", \\comptime { \\ const ptr = @intToPtr(*i32, 0x1); \\ const aligned = @alignCast(4, ptr); \\} - , + , &[_][]const u8{ "tmp.zig:3:35: error: pointer address 0x1 is not aligned to 4 bytes", - ); + }); - cases.add( - "@ptrToInt on *void", + cases.add("@ptrToInt on *void", \\export fn entry() bool { \\ return @ptrToInt(&{}) == @ptrToInt(&{}); \\} - , + , &[_][]const u8{ "tmp.zig:2:23: error: pointer to size 0 type has no address", - ); + }); - cases.add( - "@popCount - non-integer", + cases.add("@popCount - non-integer", \\export fn entry(x: f32) u32 { \\ return @popCount(f32, x); \\} - , + , &[_][]const u8{ "tmp.zig:2:22: error: expected integer type, found 'f32'", - ); + }); cases.addCase(x: { - const tc = cases.create( - "wrong same named struct", + const tc = cases.create("wrong same named struct", \\const a = @import("a.zig"); \\const b = @import("b.zig"); \\ @@ -2324,12 +2175,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\} \\ \\fn bar(x: *b.Foo) void {} - , + , &[_][]const u8{ "tmp.zig:6:10: error: expected type '*b.Foo', found '*a.Foo'", "tmp.zig:6:10: note: pointer type child 'a.Foo' cannot cast into pointer type child 'b.Foo'", "a.zig:1:17: note: a.Foo declared here", "b.zig:1:17: note: b.Foo declared here", - ); + }); tc.addSourceFile("a.zig", \\pub const Foo = struct { @@ -2346,8 +2197,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { break :x tc; }); - cases.add( - "@floatToInt comptime safety", + cases.add("@floatToInt comptime safety", \\comptime { \\ _ = @floatToInt(i8, @as(f32, -129.1)); \\} @@ -2357,23 +2207,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\comptime { \\ _ = @floatToInt(u8, @as(f32, 256.1)); \\} - , + , &[_][]const u8{ "tmp.zig:2:9: error: integer value '-129' cannot be stored in type 'i8'", "tmp.zig:5:9: error: integer value '-1' cannot be stored in type 'u8'", "tmp.zig:8:9: error: integer value '256' cannot be stored in type 'u8'", - ); + }); - cases.add( - "use c_void as return type of fn ptr", + cases.add("use c_void as return type of fn ptr", \\export fn entry() void { \\ const a: fn () c_void = undefined; \\} - , + , &[_][]const u8{ "tmp.zig:2:20: error: return type cannot be opaque", - ); + }); - cases.add( - "use implicit casts to assign null to non-nullable pointer", + cases.add("use implicit casts to assign null to non-nullable pointer", \\export fn entry() void { \\ var x: i32 = 1234; \\ var p: *i32 = &x; @@ -2381,30 +2229,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ pp.* = null; \\ var y = p.*; \\} - , + , &[_][]const u8{ "tmp.zig:4:23: error: expected type '*?*i32', found '**i32'", - ); + }); - cases.add( - "attempted implicit cast from T to [*]const T", + cases.add("attempted implicit cast from T to [*]const T", \\export fn entry() void { \\ const x: [*]const bool = true; \\} - , + , &[_][]const u8{ "tmp.zig:2:30: error: expected type '[*]const bool', found 'bool'", - ); + }); - cases.add( - "dereference unknown length pointer", + cases.add("dereference unknown length pointer", \\export fn entry(x: [*]i32) i32 { \\ return x.*; \\} - , + , &[_][]const u8{ "tmp.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32'", - ); + }); - cases.add( - "field access of unknown length pointer", + cases.add("field access of unknown length pointer", \\const Foo = extern struct { \\ a: i32, \\}; @@ -2412,19 +2257,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry(foo: [*]Foo) void { \\ foo.a += 1; \\} - , + , &[_][]const u8{ "tmp.zig:6:8: error: type '[*]Foo' does not support field access", - ); + }); - cases.add( - "unknown length pointer to opaque", + cases.add("unknown length pointer to opaque", \\export const T = [*]@OpaqueType(); - , + , &[_][]const u8{ "tmp.zig:1:21: error: unknown-length pointer to opaque", - ); + }); - cases.add( - "error when evaluating return type", + cases.add("error when evaluating return type", \\const Foo = struct { \\ map: @as(i32, i32), \\ @@ -2435,30 +2278,27 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ var rule_set = try Foo.init(); \\} - , + , &[_][]const u8{ "tmp.zig:2:10: error: expected type 'i32', found 'type'", - ); + }); - cases.add( - "slicing single-item pointer", + cases.add("slicing single-item pointer", \\export fn entry(ptr: *i32) void { \\ const slice = ptr[0..2]; \\} - , + , &[_][]const u8{ "tmp.zig:2:22: error: slice of single-item pointer", - ); + }); - cases.add( - "indexing single-item pointer", + cases.add("indexing single-item pointer", \\export fn entry(ptr: *i32) i32 { \\ return ptr[1]; \\} - , + , &[_][]const u8{ "tmp.zig:2:15: error: index of single-item pointer", - ); + }); - cases.add( - "nested error set mismatch", + cases.add("nested error set mismatch", \\const NextError = error{NextError}; \\const OtherError = error{OutOfMemory}; \\ @@ -2469,15 +2309,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn foo() ?OtherError!i32 { \\ return null; \\} - , + , &[_][]const u8{ "tmp.zig:5:34: error: expected type '?NextError!i32', found '?OtherError!i32'", "tmp.zig:5:34: note: optional type child 'OtherError!i32' cannot cast into optional type child 'NextError!i32'", "tmp.zig:5:34: note: error set 'OtherError' cannot cast into error set 'NextError'", "tmp.zig:2:26: note: 'error.OutOfMemory' not a member of destination error set", - ); + }); - cases.add( - "invalid deref on switch target", + cases.add("invalid deref on switch target", \\comptime { \\ var tile = Tile.Empty; \\ switch (tile.*) { @@ -2489,19 +2328,17 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ Empty, \\ Filled, \\}; - , + , &[_][]const u8{ "tmp.zig:3:17: error: attempt to dereference non-pointer type 'Tile'", - ); + }); - cases.add( - "invalid field access in comptime", + cases.add("invalid field access in comptime", \\comptime { var x = doesnt_exist.whatever; } - , + , &[_][]const u8{ "tmp.zig:1:20: error: use of undeclared identifier 'doesnt_exist'", - ); + }); - cases.add( - "suspend inside suspend block", + cases.add("suspend inside suspend block", \\export fn entry() void { \\ _ = async foo(); \\} @@ -2511,34 +2348,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ } \\ } \\} - , + , &[_][]const u8{ "tmp.zig:6:9: error: cannot suspend inside suspend block", "tmp.zig:5:5: note: other suspend block here", - ); + }); - cases.add( - "assign inline fn to non-comptime var", + cases.add("assign inline fn to non-comptime var", \\export fn entry() void { \\ var a = b; \\} \\inline fn b() void { } - , + , &[_][]const u8{ "tmp.zig:2:5: error: functions marked inline must be stored in const or comptime var", "tmp.zig:4:1: note: declared here", - ); + }); - cases.add( - "wrong type passed to @panic", + cases.add("wrong type passed to @panic", \\export fn entry() void { \\ var e = error.Foo; \\ @panic(e); \\} - , + , &[_][]const u8{ "tmp.zig:3:12: error: expected type '[]const u8', found 'error{Foo}'", - ); + }); - cases.add( - "@tagName used on union with no associated enum tag", + cases.add("@tagName used on union with no associated enum tag", \\const FloatInt = extern union { \\ Float: f32, \\ Int: i32, @@ -2547,54 +2381,49 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var fi = FloatInt{.Float = 123.45}; \\ var tagName = @tagName(fi); \\} - , + , &[_][]const u8{ "tmp.zig:7:19: error: union has no associated enum", "tmp.zig:1:18: note: declared here", - ); + }); - cases.add( - "returning error from void async function", + cases.add("returning error from void async function", \\export fn entry() void { \\ _ = async amain(); \\} \\async fn amain() void { \\ return error.ShouldBeCompileError; \\} - , + , &[_][]const u8{ "tmp.zig:5:17: error: expected type 'void', found 'error{ShouldBeCompileError}'", - ); + }); - cases.add( - "var makes structs required to be comptime known", + cases.add("var makes structs required to be comptime known", \\export fn entry() void { \\ const S = struct{v: var}; \\ var s = S{.v=@as(i32, 10)}; \\} - , + , &[_][]const u8{ "tmp.zig:3:4: error: variable of type 'S' must be const or comptime", - ); + }); - cases.add( - "@ptrCast discards const qualifier", + cases.add("@ptrCast discards const qualifier", \\export fn entry() void { \\ const x: i32 = 1234; \\ const y = @ptrCast(*i32, &x); \\} - , + , &[_][]const u8{ "tmp.zig:3:15: error: cast discards const qualifier", - ); + }); - cases.add( - "comptime slice of undefined pointer non-zero len", + cases.add("comptime slice of undefined pointer non-zero len", \\export fn entry() void { \\ const slice = @as([*]i32, undefined)[0..1]; \\} - , + , &[_][]const u8{ "tmp.zig:2:41: error: non-zero length slice of undefined pointer", - ); + }); - cases.add( - "type checking function pointers", + cases.add("type checking function pointers", \\fn a(b: fn (*const u8) void) void { \\ b('a'); \\} @@ -2602,12 +2431,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ a(c); \\} - , + , &[_][]const u8{ "tmp.zig:6:7: error: expected type 'fn(*const u8) void', found 'fn(u8) void'", - ); + }); - cases.add( - "no else prong on switch on global error set", + cases.add("no else prong on switch on global error set", \\export fn entry() void { \\ foo(error.A); \\} @@ -2616,23 +2444,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ error.A => {}, \\ } \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: else prong required when switching on type 'anyerror'", - ); + }); - cases.add( - "inferred error set with no returned error", + cases.add("inferred error set with no returned error", \\export fn entry() void { \\ foo() catch unreachable; \\} \\fn foo() !void { \\} - , + , &[_][]const u8{ "tmp.zig:4:11: error: function with inferred error set must return at least one possible error", - ); + }); - cases.add( - "error not handled in switch", + cases.add("error not handled in switch", \\export fn entry() void { \\ foo(452) catch |err| switch (err) { \\ error.Foo => {}, @@ -2646,13 +2472,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ else => {}, \\ } \\} - , + , &[_][]const u8{ "tmp.zig:2:26: error: error.Baz not handled in switch", "tmp.zig:2:26: error: error.Bar not handled in switch", - ); + }); - cases.add( - "duplicate error in switch", + cases.add("duplicate error in switch", \\export fn entry() void { \\ foo(452) catch |err| switch (err) { \\ error.Foo => {}, @@ -2668,10 +2493,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ else => {}, \\ } \\} - , + , &[_][]const u8{ "tmp.zig:5:14: error: duplicate switch value: '@typeOf(foo).ReturnType.ErrorSet.Foo'", "tmp.zig:3:14: note: other value is here", - ); + }); cases.add("invalid cast from integral type to enum", \\const E = enum(usize) { One, Two }; @@ -2685,10 +2510,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ E.One => {}, \\ } \\} - , "tmp.zig:9:10: error: expected type 'usize', found 'E'"); + , &[_][]const u8{ + "tmp.zig:9:10: error: expected type 'usize', found 'E'", + }); - cases.add( - "range operator in switch used on error set", + cases.add("range operator in switch used on error set", \\export fn entry() void { \\ try foo(452) catch |err| switch (err) { \\ error.A ... error.B => {}, @@ -2702,41 +2528,37 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ else => {}, \\ } \\} - , + , &[_][]const u8{ "tmp.zig:3:17: error: operator not allowed for errors", - ); + }); - cases.add( - "inferring error set of function pointer", + cases.add("inferring error set of function pointer", \\comptime { \\ const z: ?fn()!void = null; \\} - , + , &[_][]const u8{ "tmp.zig:2:15: error: inferring error set of return type valid only for function definitions", - ); + }); - cases.add( - "access non-existent member of error set", + cases.add("access non-existent member of error set", \\const Foo = error{A}; \\comptime { \\ const z = Foo.Bar; \\} - , + , &[_][]const u8{ "tmp.zig:3:18: error: no error named 'Bar' in 'Foo'", - ); + }); - cases.add( - "error union operator with non error set LHS", + cases.add("error union operator with non error set LHS", \\comptime { \\ const z = i32!i32; \\ var x: z = undefined; \\} - , + , &[_][]const u8{ "tmp.zig:2:15: error: expected error set type, found type 'i32'", - ); + }); - cases.add( - "error equality but sets have no common members", + cases.add("error equality but sets have no common members", \\const Set1 = error{A, C}; \\const Set2 = error{B, D}; \\export fn entry() void { @@ -2747,33 +2569,30 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ \\ } \\} - , + , &[_][]const u8{ "tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors", - ); + }); - cases.add( - "only equality binary operator allowed for error sets", + cases.add("only equality binary operator allowed for error sets", \\comptime { \\ const z = error.A > error.B; \\} - , + , &[_][]const u8{ "tmp.zig:2:23: error: operator not allowed for errors", - ); + }); - cases.add( - "explicit error set cast known at comptime violates error sets", + cases.add("explicit error set cast known at comptime violates error sets", \\const Set1 = error {A, B}; \\const Set2 = error {A, C}; \\comptime { \\ var x = Set1.B; \\ var y = @errSetCast(Set2, x); \\} - , + , &[_][]const u8{ "tmp.zig:5:13: error: error.B not a member of error set 'Set2'", - ); + }); - cases.add( - "cast error union of global error set to error union of smaller error set", + cases.add("cast error union of global error set to error union of smaller error set", \\const SmallErrorSet = error{A}; \\export fn entry() void { \\ var x: SmallErrorSet!i32 = foo(); @@ -2781,14 +2600,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn foo() anyerror!i32 { \\ return error.B; \\} - , + , &[_][]const u8{ "tmp.zig:3:35: error: expected type 'SmallErrorSet!i32', found 'anyerror!i32'", "tmp.zig:3:35: note: error set 'anyerror' cannot cast into error set 'SmallErrorSet'", "tmp.zig:3:35: note: cannot cast global error set into smaller set", - ); + }); - cases.add( - "cast global error set to error set", + cases.add("cast global error set to error set", \\const SmallErrorSet = error{A}; \\export fn entry() void { \\ var x: SmallErrorSet = foo(); @@ -2796,24 +2614,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn foo() anyerror { \\ return error.B; \\} - , + , &[_][]const u8{ "tmp.zig:3:31: error: expected type 'SmallErrorSet', found 'anyerror'", "tmp.zig:3:31: note: cannot cast global error set into smaller set", - ); - cases.add( - "recursive inferred error set", + }); + cases.add("recursive inferred error set", \\export fn entry() void { \\ foo() catch unreachable; \\} \\fn foo() !void { \\ try foo(); \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: cannot resolve inferred error set '@typeOf(foo).ReturnType.ErrorSet': function 'foo' not fully analyzed yet", - ); + }); - cases.add( - "implicit cast of error set not a subset", + cases.add("implicit cast of error set not a subset", \\const Set1 = error{A, B}; \\const Set2 = error{A, C}; \\export fn entry() void { @@ -2822,13 +2638,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn foo(set1: Set1) void { \\ var x: Set2 = set1; \\} - , + , &[_][]const u8{ "tmp.zig:7:19: error: expected type 'Set2', found 'Set1'", "tmp.zig:1:23: note: 'error.B' not a member of destination error set", - ); + }); - cases.add( - "int to err global invalid number", + cases.add("int to err global invalid number", \\const Set1 = error{ \\ A, \\ B, @@ -2837,12 +2652,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var x: u16 = 3; \\ var y = @intToError(x); \\} - , + , &[_][]const u8{ "tmp.zig:7:13: error: integer value 3 represents no error", - ); + }); - cases.add( - "int to err non global invalid number", + cases.add("int to err non global invalid number", \\const Set1 = error{ \\ A, \\ B, @@ -2855,21 +2669,19 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var x = @errorToInt(Set1.B); \\ var y = @errSetCast(Set2, @intToError(x)); \\} - , + , &[_][]const u8{ "tmp.zig:11:13: error: error.B not a member of error set 'Set2'", - ); + }); - cases.add( - "@memberCount of error", + cases.add("@memberCount of error", \\comptime { \\ _ = @memberCount(anyerror); \\} - , + , &[_][]const u8{ "tmp.zig:2:9: error: global error set member count not available at comptime", - ); + }); - cases.add( - "duplicate error value in error set", + cases.add("duplicate error value in error set", \\const Foo = error { \\ Bar, \\ Bar, @@ -2877,32 +2689,29 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ const a: Foo = undefined; \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: duplicate error: 'Bar'", "tmp.zig:2:5: note: other error here", - ); + }); - cases.add( - "cast negative integer literal to usize", + cases.add("cast negative integer literal to usize", \\export fn entry() void { \\ const x = @as(usize, -10); \\} - , + , &[_][]const u8{ "tmp.zig:2:26: error: cannot cast negative value -10 to unsigned integer type 'usize'", - ); + }); - cases.add( - "use invalid number literal as array index", + cases.add("use invalid number literal as array index", \\var v = 25; \\export fn entry() void { \\ var arr: [v]u8 = undefined; \\} - , + , &[_][]const u8{ "tmp.zig:1:1: error: unable to infer variable type", - ); + }); - cases.add( - "duplicate struct field", + cases.add("duplicate struct field", \\const Foo = struct { \\ Bar: i32, \\ Bar: usize, @@ -2910,13 +2719,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ const a: Foo = undefined; \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: duplicate struct field: 'Bar'", "tmp.zig:2:5: note: other field here", - ); + }); - cases.add( - "duplicate union field", + cases.add("duplicate union field", \\const Foo = union { \\ Bar: i32, \\ Bar: usize, @@ -2924,13 +2732,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ const a: Foo = undefined; \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: duplicate union field: 'Bar'", "tmp.zig:2:5: note: other field here", - ); + }); - cases.add( - "duplicate enum field", + cases.add("duplicate enum field", \\const Foo = enum { \\ Bar, \\ Bar, @@ -2939,110 +2746,99 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ const a: Foo = undefined; \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: duplicate enum field: 'Bar'", "tmp.zig:2:5: note: other field here", - ); + }); - cases.add( - "calling function with naked calling convention", + cases.add("calling function with naked calling convention", \\export fn entry() void { \\ foo(); \\} \\nakedcc fn foo() void { } - , + , &[_][]const u8{ "tmp.zig:2:5: error: unable to call function with naked calling convention", "tmp.zig:4:1: note: declared here", - ); + }); - cases.add( - "function with invalid return type", + cases.add("function with invalid return type", \\export fn foo() boid {} - , + , &[_][]const u8{ "tmp.zig:1:17: error: use of undeclared identifier 'boid'", - ); + }); - cases.add( - "function with non-extern non-packed enum parameter", + cases.add("function with non-extern non-packed enum parameter", \\const Foo = enum { A, B, C }; \\export fn entry(foo: Foo) void { } - , + , &[_][]const u8{ "tmp.zig:2:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'", - ); + }); - cases.add( - "function with non-extern non-packed struct parameter", + cases.add("function with non-extern non-packed struct parameter", \\const Foo = struct { \\ A: i32, \\ B: f32, \\ C: bool, \\}; \\export fn entry(foo: Foo) void { } - , + , &[_][]const u8{ "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'", - ); + }); - cases.add( - "function with non-extern non-packed union parameter", + cases.add("function with non-extern non-packed union parameter", \\const Foo = union { \\ A: i32, \\ B: f32, \\ C: bool, \\}; \\export fn entry(foo: Foo) void { } - , + , &[_][]const u8{ "tmp.zig:6:22: error: parameter of type 'Foo' not allowed in function with calling convention 'ccc'", - ); + }); - cases.add( - "switch on enum with 1 field with no prongs", + cases.add("switch on enum with 1 field with no prongs", \\const Foo = enum { M }; \\ \\export fn entry() void { \\ var f = Foo.M; \\ switch (f) {} \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: enumeration value 'Foo.M' not handled in switch", - ); + }); - cases.add( - "shift by negative comptime integer", + cases.add("shift by negative comptime integer", \\comptime { \\ var a = 1 >> -1; \\} - , + , &[_][]const u8{ "tmp.zig:2:18: error: shift by negative value -1", - ); + }); - cases.add( - "@panic called at compile time", + cases.add("@panic called at compile time", \\export fn entry() void { \\ comptime { \\ @panic("aoeu",); \\ } \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: encountered @panic at compile-time", - ); + }); - cases.add( - "wrong return type for main", + cases.add("wrong return type for main", \\pub fn main() f32 { } - , + , &[_][]const u8{ "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'", - ); + }); - cases.add( - "double ?? on main return value", + cases.add("double ?? on main return value", \\pub fn main() ??void { \\} - , + , &[_][]const u8{ "error: expected return type of main to be 'void', '!void', 'noreturn', 'u8', or '!u8'", - ); + }); - cases.add( - "bad identifier in function with struct defined inside function which references local const", + cases.add("bad identifier in function with struct defined inside function which references local const", \\export fn entry() void { \\ const BlockKind = u32; \\ @@ -3052,12 +2848,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ \\ bogus; \\} - , + , &[_][]const u8{ "tmp.zig:8:5: error: use of undeclared identifier 'bogus'", - ); + }); - cases.add( - "labeled break not found", + cases.add("labeled break not found", \\export fn entry() void { \\ blah: while (true) { \\ while (true) { @@ -3065,12 +2860,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ } \\ } \\} - , + , &[_][]const u8{ "tmp.zig:4:13: error: label not found: 'outer'", - ); + }); - cases.add( - "labeled continue not found", + cases.add("labeled continue not found", \\export fn entry() void { \\ var i: usize = 0; \\ blah: while (i < 10) : (i += 1) { @@ -3079,12 +2873,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ } \\ } \\} - , + , &[_][]const u8{ "tmp.zig:5:13: error: labeled loop not found: 'outer'", - ); + }); - cases.add( - "attempt to use 0 bit type in extern fn", + cases.add("attempt to use 0 bit type in extern fn", \\extern fn foo(ptr: extern fn(*void) void) void; \\ \\export fn entry() void { @@ -3095,476 +2888,431 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry2() void { \\ bar(&{}); \\} - , + , &[_][]const u8{ "tmp.zig:1:30: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'", "tmp.zig:7:18: error: parameter of type '*void' has 0 bits; not allowed in function with calling convention 'ccc'", - ); + }); - cases.add( - "implicit semicolon - block statement", + cases.add("implicit semicolon - block statement", \\export fn entry() void { \\ {} \\ var good = {}; \\ ({}) \\ var bad = {}; \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: expected token ';', found 'var'", - ); + }); - cases.add( - "implicit semicolon - block expr", + cases.add("implicit semicolon - block expr", \\export fn entry() void { \\ _ = {}; \\ var good = {}; \\ _ = {} \\ var bad = {}; \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: expected token ';', found 'var'", - ); + }); - cases.add( - "implicit semicolon - comptime statement", + cases.add("implicit semicolon - comptime statement", \\export fn entry() void { \\ comptime {} \\ var good = {}; \\ comptime ({}) \\ var bad = {}; \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: expected token ';', found 'var'", - ); + }); - cases.add( - "implicit semicolon - comptime expression", + cases.add("implicit semicolon - comptime expression", \\export fn entry() void { \\ _ = comptime {}; \\ var good = {}; \\ _ = comptime {} \\ var bad = {}; \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: expected token ';', found 'var'", - ); + }); - cases.add( - "implicit semicolon - defer", + cases.add("implicit semicolon - defer", \\export fn entry() void { \\ defer {} \\ var good = {}; \\ defer ({}) \\ var bad = {}; \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: expected token ';', found 'var'", - ); + }); - cases.add( - "implicit semicolon - if statement", + cases.add("implicit semicolon - if statement", \\export fn entry() void { \\ if(true) {} \\ var good = {}; \\ if(true) ({}) \\ var bad = {}; \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: expected token ';', found 'var'", - ); + }); - cases.add( - "implicit semicolon - if expression", + cases.add("implicit semicolon - if expression", \\export fn entry() void { \\ _ = if(true) {}; \\ var good = {}; \\ _ = if(true) {} \\ var bad = {}; \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: expected token ';', found 'var'", - ); + }); - cases.add( - "implicit semicolon - if-else statement", + cases.add("implicit semicolon - if-else statement", \\export fn entry() void { \\ if(true) {} else {} \\ var good = {}; \\ if(true) ({}) else ({}) \\ var bad = {}; \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: expected token ';', found 'var'", - ); + }); - cases.add( - "implicit semicolon - if-else expression", + cases.add("implicit semicolon - if-else expression", \\export fn entry() void { \\ _ = if(true) {} else {}; \\ var good = {}; \\ _ = if(true) {} else {} \\ var bad = {}; \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: expected token ';', found 'var'", - ); + }); - cases.add( - "implicit semicolon - if-else-if statement", + cases.add("implicit semicolon - if-else-if statement", \\export fn entry() void { \\ if(true) {} else if(true) {} \\ var good = {}; \\ if(true) ({}) else if(true) ({}) \\ var bad = {}; \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: expected token ';', found 'var'", - ); + }); - cases.add( - "implicit semicolon - if-else-if expression", + cases.add("implicit semicolon - if-else-if expression", \\export fn entry() void { \\ _ = if(true) {} else if(true) {}; \\ var good = {}; \\ _ = if(true) {} else if(true) {} \\ var bad = {}; \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: expected token ';', found 'var'", - ); + }); - cases.add( - "implicit semicolon - if-else-if-else statement", + cases.add("implicit semicolon - if-else-if-else statement", \\export fn entry() void { \\ if(true) {} else if(true) {} else {} \\ var good = {}; \\ if(true) ({}) else if(true) ({}) else ({}) \\ var bad = {}; \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: expected token ';', found 'var'", - ); + }); - cases.add( - "implicit semicolon - if-else-if-else expression", + cases.add("implicit semicolon - if-else-if-else expression", \\export fn entry() void { \\ _ = if(true) {} else if(true) {} else {}; \\ var good = {}; \\ _ = if(true) {} else if(true) {} else {} \\ var bad = {}; \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: expected token ';', found 'var'", - ); + }); - cases.add( - "implicit semicolon - test statement", + cases.add("implicit semicolon - test statement", \\export fn entry() void { \\ if (foo()) |_| {} \\ var good = {}; \\ if (foo()) |_| ({}) \\ var bad = {}; \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: expected token ';', found 'var'", - ); + }); - cases.add( - "implicit semicolon - test expression", + cases.add("implicit semicolon - test expression", \\export fn entry() void { \\ _ = if (foo()) |_| {}; \\ var good = {}; \\ _ = if (foo()) |_| {} \\ var bad = {}; \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: expected token ';', found 'var'", - ); + }); - cases.add( - "implicit semicolon - while statement", + cases.add("implicit semicolon - while statement", \\export fn entry() void { \\ while(true) {} \\ var good = {}; \\ while(true) ({}) \\ var bad = {}; \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: expected token ';', found 'var'", - ); + }); - cases.add( - "implicit semicolon - while expression", + cases.add("implicit semicolon - while expression", \\export fn entry() void { \\ _ = while(true) {}; \\ var good = {}; \\ _ = while(true) {} \\ var bad = {}; \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: expected token ';', found 'var'", - ); + }); - cases.add( - "implicit semicolon - while-continue statement", + cases.add("implicit semicolon - while-continue statement", \\export fn entry() void { \\ while(true):({}) {} \\ var good = {}; \\ while(true):({}) ({}) \\ var bad = {}; \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: expected token ';', found 'var'", - ); + }); - cases.add( - "implicit semicolon - while-continue expression", + cases.add("implicit semicolon - while-continue expression", \\export fn entry() void { \\ _ = while(true):({}) {}; \\ var good = {}; \\ _ = while(true):({}) {} \\ var bad = {}; \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: expected token ';', found 'var'", - ); + }); - cases.add( - "implicit semicolon - for statement", + cases.add("implicit semicolon - for statement", \\export fn entry() void { \\ for(foo()) |_| {} \\ var good = {}; \\ for(foo()) |_| ({}) \\ var bad = {}; \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: expected token ';', found 'var'", - ); + }); - cases.add( - "implicit semicolon - for expression", + cases.add("implicit semicolon - for expression", \\export fn entry() void { \\ _ = for(foo()) |_| {}; \\ var good = {}; \\ _ = for(foo()) |_| {} \\ var bad = {}; \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: expected token ';', found 'var'", - ); + }); - cases.add( - "multiple function definitions", + cases.add("multiple function definitions", \\fn a() void {} \\fn a() void {} \\export fn entry() void { a(); } - , + , &[_][]const u8{ "tmp.zig:2:1: error: redefinition of 'a'", - ); + }); - cases.add( - "unreachable with return", + cases.add("unreachable with return", \\fn a() noreturn {return;} \\export fn entry() void { a(); } - , + , &[_][]const u8{ "tmp.zig:1:18: error: expected type 'noreturn', found 'void'", - ); + }); - cases.add( - "control reaches end of non-void function", + cases.add("control reaches end of non-void function", \\fn a() i32 {} \\export fn entry() void { _ = a(); } - , + , &[_][]const u8{ "tmp.zig:1:12: error: expected type 'i32', found 'void'", - ); + }); - cases.add( - "undefined function call", + cases.add("undefined function call", \\export fn a() void { \\ b(); \\} - , + , &[_][]const u8{ "tmp.zig:2:5: error: use of undeclared identifier 'b'", - ); + }); - cases.add( - "wrong number of arguments", + cases.add("wrong number of arguments", \\export fn a() void { \\ b(1); \\} \\fn b(a: i32, b: i32, c: i32) void { } - , + , &[_][]const u8{ "tmp.zig:2:6: error: expected 3 arguments, found 1", - ); + }); - cases.add( - "invalid type", + cases.add("invalid type", \\fn a() bogus {} \\export fn entry() void { _ = a(); } - , + , &[_][]const u8{ "tmp.zig:1:8: error: use of undeclared identifier 'bogus'", - ); + }); - cases.add( - "pointer to noreturn", + cases.add("pointer to noreturn", \\fn a() *noreturn {} \\export fn entry() void { _ = a(); } - , + , &[_][]const u8{ "tmp.zig:1:9: error: pointer to noreturn not allowed", - ); + }); - cases.add( - "unreachable code", + cases.add("unreachable code", \\export fn a() void { \\ return; \\ b(); \\} \\ \\fn b() void {} - , + , &[_][]const u8{ "tmp.zig:3:6: error: unreachable code", - ); + }); - cases.add( - "bad import", + cases.add("bad import", \\const bogus = @import("bogus-does-not-exist.zig",); \\export fn entry() void { bogus.bogo(); } - , + , &[_][]const u8{ "tmp.zig:1:15: error: unable to find 'bogus-does-not-exist.zig'", - ); + }); - cases.add( - "undeclared identifier", + cases.add("undeclared identifier", \\export fn a() void { \\ return \\ b + \\ c; \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: use of undeclared identifier 'b'", - ); + }); - cases.add( - "parameter redeclaration", + cases.add("parameter redeclaration", \\fn f(a : i32, a : i32) void { \\} \\export fn entry() void { f(1, 2); } - , + , &[_][]const u8{ "tmp.zig:1:15: error: redeclaration of variable 'a'", - ); + }); - cases.add( - "local variable redeclaration", + cases.add("local variable redeclaration", \\export fn f() void { \\ const a : i32 = 0; \\ const a = 0; \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: redeclaration of variable 'a'", - ); + }); - cases.add( - "local variable redeclares parameter", + cases.add("local variable redeclares parameter", \\fn f(a : i32) void { \\ const a = 0; \\} \\export fn entry() void { f(1); } - , + , &[_][]const u8{ "tmp.zig:2:5: error: redeclaration of variable 'a'", - ); + }); - cases.add( - "variable has wrong type", + cases.add("variable has wrong type", \\export fn f() i32 { \\ const a = "a"; \\ return a; \\} - , + , &[_][]const u8{ "tmp.zig:3:12: error: expected type 'i32', found '*const [1:0]u8'", - ); + }); - cases.add( - "if condition is bool, not int", + cases.add("if condition is bool, not int", \\export fn f() void { \\ if (0) {} \\} - , + , &[_][]const u8{ "tmp.zig:2:9: error: expected type 'bool', found 'comptime_int'", - ); + }); - cases.add( - "assign unreachable", + cases.add("assign unreachable", \\export fn f() void { \\ const a = return; \\} - , + , &[_][]const u8{ "tmp.zig:2:5: error: unreachable code", - ); + }); - cases.add( - "unreachable variable", + cases.add("unreachable variable", \\export fn f() void { \\ const a: noreturn = {}; \\} - , + , &[_][]const u8{ "tmp.zig:2:25: error: expected type 'noreturn', found 'void'", - ); + }); - cases.add( - "unreachable parameter", + cases.add("unreachable parameter", \\fn f(a: noreturn) void {} \\export fn entry() void { f(); } - , + , &[_][]const u8{ "tmp.zig:1:9: error: parameter of type 'noreturn' not allowed", - ); + }); - cases.add( - "bad assignment target", + cases.add("bad assignment target", \\export fn f() void { \\ 3 = 3; \\} - , + , &[_][]const u8{ "tmp.zig:2:9: error: cannot assign to constant", - ); + }); - cases.add( - "assign to constant variable", + cases.add("assign to constant variable", \\export fn f() void { \\ const a = 3; \\ a = 4; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: cannot assign to constant", - ); + }); - cases.add( - "use of undeclared identifier", + cases.add("use of undeclared identifier", \\export fn f() void { \\ b = 3; \\} - , + , &[_][]const u8{ "tmp.zig:2:5: error: use of undeclared identifier 'b'", - ); + }); - cases.add( - "const is a statement, not an expression", + cases.add("const is a statement, not an expression", \\export fn f() void { \\ (const a = 0); \\} - , + , &[_][]const u8{ "tmp.zig:2:6: error: invalid token: 'const'", - ); + }); - cases.add( - "array access of undeclared identifier", + cases.add("array access of undeclared identifier", \\export fn f() void { \\ i[i] = i[i]; \\} - , + , &[_][]const u8{ "tmp.zig:2:5: error: use of undeclared identifier 'i'", - ); + }); - cases.add( - "array access of non array", + cases.add("array access of non array", \\export fn f() void { \\ var bad : bool = undefined; \\ bad[bad] = bad[bad]; @@ -3573,13 +3321,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var bad : bool = undefined; \\ _ = bad[bad]; \\} - , + , &[_][]const u8{ "tmp.zig:3:8: error: array access of non-array type 'bool'", "tmp.zig:7:12: error: array access of non-array type 'bool'", - ); + }); - cases.add( - "array access with non integer index", + cases.add("array access with non integer index", \\export fn f() void { \\ var array = "aoeu"; \\ var bad = false; @@ -3590,24 +3337,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var bad = false; \\ _ = array[bad]; \\} - , + , &[_][]const u8{ "tmp.zig:4:11: error: expected type 'usize', found 'bool'", "tmp.zig:9:15: error: expected type 'usize', found 'bool'", - ); + }); - cases.add( - "write to const global variable", + cases.add("write to const global variable", \\const x : i32 = 99; \\fn f() void { \\ x = 1; \\} \\export fn entry() void { f(); } - , + , &[_][]const u8{ "tmp.zig:3:9: error: cannot assign to constant", - ); + }); - cases.add( - "missing else clause", + cases.add("missing else clause", \\fn f(b: bool) void { \\ const x : i32 = if (b) h: { break :h 1; }; \\} @@ -3615,13 +3360,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ const y = if (b) h: { break :h @as(i32, 1); }; \\} \\export fn entry() void { f(true); g(true); } - , + , &[_][]const u8{ "tmp.zig:2:21: error: expected type 'i32', found 'void'", "tmp.zig:5:15: error: incompatible types: 'i32' and 'void'", - ); + }); - cases.add( - "invalid struct field", + cases.add("invalid struct field", \\const A = struct { x : i32, }; \\export fn f() void { \\ var a : A = undefined; @@ -3632,38 +3376,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var a : A = undefined; \\ const y = a.bar; \\} - , + , &[_][]const u8{ "tmp.zig:4:6: error: no member named 'foo' in struct 'A'", "tmp.zig:9:16: error: no member named 'bar' in struct 'A'", - ); + }); - cases.add( - "redefinition of struct", + cases.add("redefinition of struct", \\const A = struct { x : i32, }; \\const A = struct { y : i32, }; - , + , &[_][]const u8{ "tmp.zig:2:1: error: redefinition of 'A'", - ); + }); - cases.add( - "redefinition of enums", + cases.add("redefinition of enums", \\const A = enum {}; \\const A = enum {}; - , + , &[_][]const u8{ "tmp.zig:2:1: error: redefinition of 'A'", - ); + }); - cases.add( - "redefinition of global variables", + cases.add("redefinition of global variables", \\var a : i32 = 1; \\var a : i32 = 2; - , + , &[_][]const u8{ "tmp.zig:2:1: error: redefinition of 'a'", "tmp.zig:1:1: note: previous definition is here", - ); + }); - cases.add( - "duplicate field in struct value expression", + cases.add("duplicate field in struct value expression", \\const A = struct { \\ x : i32, \\ y : i32, @@ -3677,12 +3417,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ .z = 4, \\ }; \\} - , + , &[_][]const u8{ "tmp.zig:11:9: error: duplicate field", - ); + }); - cases.add( - "missing field in struct value expression", + cases.add("missing field in struct value expression", \\const A = struct { \\ x : i32, \\ y : i32, @@ -3696,12 +3435,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ .y = 2, \\ }; \\} - , + , &[_][]const u8{ "tmp.zig:9:17: error: missing field: 'x'", - ); + }); - cases.add( - "invalid field in struct value expression", + cases.add("invalid field in struct value expression", \\const A = struct { \\ x : i32, \\ y : i32, @@ -3714,86 +3452,77 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ .foo = 42, \\ }; \\} - , + , &[_][]const u8{ "tmp.zig:10:9: error: no member named 'foo' in struct 'A'", - ); + }); - cases.add( - "invalid break expression", + cases.add("invalid break expression", \\export fn f() void { \\ break; \\} - , + , &[_][]const u8{ "tmp.zig:2:5: error: break expression outside loop", - ); + }); - cases.add( - "invalid continue expression", + cases.add("invalid continue expression", \\export fn f() void { \\ continue; \\} - , + , &[_][]const u8{ "tmp.zig:2:5: error: continue expression outside loop", - ); + }); - cases.add( - "invalid maybe type", + cases.add("invalid maybe type", \\export fn f() void { \\ if (true) |x| { } \\} - , + , &[_][]const u8{ "tmp.zig:2:9: error: expected optional type, found 'bool'", - ); + }); - cases.add( - "cast unreachable", + cases.add("cast unreachable", \\fn f() i32 { \\ return @as(i32, return 1); \\} \\export fn entry() void { _ = f(); } - , + , &[_][]const u8{ "tmp.zig:2:12: error: unreachable code", - ); + }); - cases.add( - "invalid builtin fn", + cases.add("invalid builtin fn", \\fn f() @bogus(foo) { \\} \\export fn entry() void { _ = f(); } - , + , &[_][]const u8{ "tmp.zig:1:8: error: invalid builtin function: 'bogus'", - ); + }); - cases.add( - "noalias on non pointer param", + cases.add("noalias on non pointer param", \\fn f(noalias x: i32) void {} \\export fn entry() void { f(1234); } - , + , &[_][]const u8{ "tmp.zig:1:6: error: noalias on non-pointer parameter", - ); + }); - cases.add( - "struct init syntax for array", + cases.add("struct init syntax for array", \\const foo = [3]u16{ .x = 1024 }; \\comptime { \\ _ = foo; \\} - , + , &[_][]const u8{ "tmp.zig:1:21: error: type '[3]u16' does not support struct initialization syntax", - ); + }); - cases.add( - "type variables must be constant", + cases.add("type variables must be constant", \\var foo = u8; \\export fn entry() foo { \\ return 1; \\} - , + , &[_][]const u8{ "tmp.zig:1:1: error: variable of type 'type' must be constant", - ); + }); - cases.add( - "variables shadowing types", + cases.add("variables shadowing types", \\const Foo = struct {}; \\const Bar = struct {}; \\ @@ -3804,15 +3533,14 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ f(1234); \\} - , + , &[_][]const u8{ "tmp.zig:4:6: error: redefinition of 'Foo'", "tmp.zig:1:1: note: previous definition is here", "tmp.zig:5:5: error: redefinition of 'Bar'", "tmp.zig:2:1: note: previous definition is here", - ); + }); - cases.add( - "switch expression - missing enumeration prong", + cases.add("switch expression - missing enumeration prong", \\const Number = enum { \\ One, \\ Two, @@ -3828,12 +3556,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\} \\ \\export fn entry() usize { return @sizeOf(@typeOf(f)); } - , + , &[_][]const u8{ "tmp.zig:8:5: error: enumeration value 'Number.Four' not handled in switch", - ); + }); - cases.add( - "switch expression - duplicate enumeration prong", + cases.add("switch expression - duplicate enumeration prong", \\const Number = enum { \\ One, \\ Two, @@ -3851,13 +3578,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\} \\ \\export fn entry() usize { return @sizeOf(@typeOf(f)); } - , + , &[_][]const u8{ "tmp.zig:13:15: error: duplicate switch value", "tmp.zig:10:15: note: other value is here", - ); + }); - cases.add( - "switch expression - duplicate enumeration prong when else present", + cases.add("switch expression - duplicate enumeration prong when else present", \\const Number = enum { \\ One, \\ Two, @@ -3876,13 +3602,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\} \\ \\export fn entry() usize { return @sizeOf(@typeOf(f)); } - , + , &[_][]const u8{ "tmp.zig:13:15: error: duplicate switch value", "tmp.zig:10:15: note: other value is here", - ); + }); - cases.add( - "switch expression - multiple else prongs", + cases.add("switch expression - multiple else prongs", \\fn f(x: u32) void { \\ const value: bool = switch (x) { \\ 1234 => false, @@ -3893,24 +3618,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ f(1234); \\} - , + , &[_][]const u8{ "tmp.zig:5:9: error: multiple else prongs in switch expression", - ); + }); - cases.add( - "switch expression - non exhaustive integer prongs", + cases.add("switch expression - non exhaustive integer prongs", \\fn foo(x: u8) void { \\ switch (x) { \\ 0 => {}, \\ } \\} \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } - , + , &[_][]const u8{ "tmp.zig:2:5: error: switch must handle all possibilities", - ); + }); - cases.add( - "switch expression - duplicate or overlapping integer value", + cases.add("switch expression - duplicate or overlapping integer value", \\fn foo(x: u8) u8 { \\ return switch (x) { \\ 0 ... 100 => @as(u8, 0), @@ -3920,13 +3643,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ }; \\} \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } - , + , &[_][]const u8{ "tmp.zig:6:9: error: duplicate switch value", "tmp.zig:5:14: note: previous value is here", - ); + }); - cases.add( - "switch expression - switch on pointer type with no else", + cases.add("switch expression - switch on pointer type with no else", \\fn foo(x: *u8) void { \\ switch (x) { \\ &y => {}, @@ -3934,82 +3656,74 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\} \\const y: u8 = 100; \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } - , + , &[_][]const u8{ "tmp.zig:2:5: error: else prong required when switching on type '*u8'", - ); + }); - cases.add( - "global variable initializer must be constant expression", + cases.add("global variable initializer must be constant expression", \\extern fn foo() i32; \\const x = foo(); \\export fn entry() i32 { return x; } - , + , &[_][]const u8{ "tmp.zig:2:11: error: unable to evaluate constant expression", - ); + }); - cases.add( - "array concatenation with wrong type", + cases.add("array concatenation with wrong type", \\const src = "aoeu"; \\const derp: usize = 1234; \\const a = derp ++ "foo"; \\ \\export fn entry() usize { return @sizeOf(@typeOf(a)); } - , + , &[_][]const u8{ "tmp.zig:3:11: error: expected array, found 'usize'", - ); + }); - cases.add( - "non compile time array concatenation", + cases.add("non compile time array concatenation", \\fn f() []u8 { \\ return s ++ "foo"; \\} \\var s: [10]u8 = undefined; \\export fn entry() usize { return @sizeOf(@typeOf(f)); } - , + , &[_][]const u8{ "tmp.zig:2:12: error: unable to evaluate constant expression", - ); + }); - cases.add( - "@cImport with bogus include", + cases.add("@cImport with bogus include", \\const c = @cImport(@cInclude("bogus.h")); \\export fn entry() usize { return @sizeOf(@typeOf(c.bogo)); } - , + , &[_][]const u8{ "tmp.zig:1:11: error: C import failed", ".h:1:10: note: 'bogus.h' file not found", - ); + }); - cases.add( - "address of number literal", + cases.add("address of number literal", \\const x = 3; \\const y = &x; \\fn foo() *const i32 { return y; } \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } - , + , &[_][]const u8{ "tmp.zig:3:30: error: expected type '*const i32', found '*const comptime_int'", - ); + }); - cases.add( - "integer overflow error", + cases.add("integer overflow error", \\const x : u8 = 300; \\export fn entry() usize { return @sizeOf(@typeOf(x)); } - , + , &[_][]const u8{ "tmp.zig:1:16: error: integer value 300 cannot be coerced to type 'u8'", - ); + }); - cases.add( - "invalid shift amount error", + cases.add("invalid shift amount error", \\const x : u8 = 2; \\fn f() u16 { \\ return x << 8; \\} \\export fn entry() u16 { return f(); } - , + , &[_][]const u8{ "tmp.zig:3:14: error: RHS of shift is too large for LHS type", "tmp.zig:3:17: note: value 8 cannot fit into type u3", - ); + }); - cases.add( - "missing function call param", + cases.add("missing function call param", \\const Foo = struct { \\ a: i32, \\ b: i32, @@ -4033,60 +3747,54 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\} \\ \\export fn entry() usize { return @sizeOf(@typeOf(f)); } - , + , &[_][]const u8{ "tmp.zig:20:34: error: expected 1 arguments, found 0", - ); + }); - cases.add( - "missing function name", + cases.add("missing function name", \\fn () void {} \\export fn entry() usize { return @sizeOf(@typeOf(f)); } - , + , &[_][]const u8{ "tmp.zig:1:1: error: missing function name", - ); + }); - cases.add( - "missing param name", + cases.add("missing param name", \\fn f(i32) void {} \\export fn entry() usize { return @sizeOf(@typeOf(f)); } - , + , &[_][]const u8{ "tmp.zig:1:6: error: missing parameter name", - ); + }); - cases.add( - "wrong function type", + cases.add("wrong function type", \\const fns = [_]fn() void { a, b, c }; \\fn a() i32 {return 0;} \\fn b() i32 {return 1;} \\fn c() i32 {return 2;} \\export fn entry() usize { return @sizeOf(@typeOf(fns)); } - , + , &[_][]const u8{ "tmp.zig:1:28: error: expected type 'fn() void', found 'fn() i32'", - ); + }); - cases.add( - "extern function pointer mismatch", + cases.add("extern function pointer mismatch", \\const fns = [_](fn(i32)i32) { a, b, c }; \\pub fn a(x: i32) i32 {return x + 0;} \\pub fn b(x: i32) i32 {return x + 1;} \\export fn c(x: i32) i32 {return x + 2;} \\ \\export fn entry() usize { return @sizeOf(@typeOf(fns)); } - , + , &[_][]const u8{ "tmp.zig:1:37: error: expected type 'fn(i32) i32', found 'extern fn(i32) i32'", - ); + }); - cases.add( - "colliding invalid top level functions", + cases.add("colliding invalid top level functions", \\fn func() bogus {} \\fn func() bogus {} \\export fn entry() usize { return @sizeOf(@typeOf(func)); } - , + , &[_][]const u8{ "tmp.zig:2:1: error: redefinition of 'func'", - ); + }); - cases.add( - "non constant expression in array size", + cases.add("non constant expression in array size", \\const Foo = struct { \\ y: [get()]u8, \\}; @@ -4094,25 +3802,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn get() usize { return global_var; } \\ \\export fn entry() usize { return @sizeOf(@typeOf(Foo)); } - , + , &[_][]const u8{ "tmp.zig:5:25: error: unable to evaluate constant expression", "tmp.zig:2:12: note: referenced here", - ); + }); - cases.add( - "addition with non numbers", + cases.add("addition with non numbers", \\const Foo = struct { \\ field: i32, \\}; \\const x = Foo {.field = 1} + Foo {.field = 2}; \\ \\export fn entry() usize { return @sizeOf(@typeOf(x)); } - , + , &[_][]const u8{ "tmp.zig:4:28: error: invalid operands to binary expression: 'Foo' and 'Foo'", - ); + }); - cases.add( - "division by zero", + cases.add("division by zero", \\const lit_int_x = 1 / 0; \\const lit_float_x = 1.0 / 0.0; \\const int_x = @as(u32, 1) / @as(u32, 0); @@ -4122,522 +3828,471 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry2() usize { return @sizeOf(@typeOf(lit_float_x)); } \\export fn entry3() usize { return @sizeOf(@typeOf(int_x)); } \\export fn entry4() usize { return @sizeOf(@typeOf(float_x)); } - , + , &[_][]const u8{ "tmp.zig:1:21: error: division by zero", "tmp.zig:2:25: error: division by zero", "tmp.zig:3:27: error: division by zero", "tmp.zig:4:31: error: division by zero", - ); + }); - cases.add( - "normal string with newline", + cases.add("normal string with newline", \\const foo = "a \\b"; \\ \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } - , + , &[_][]const u8{ "tmp.zig:1:15: error: newline not allowed in string literal", - ); + }); - cases.add( - "invalid comparison for function pointers", + cases.add("invalid comparison for function pointers", \\fn foo() void {} \\const invalid = foo > foo; \\ \\export fn entry() usize { return @sizeOf(@typeOf(invalid)); } - , + , &[_][]const u8{ "tmp.zig:2:21: error: operator not allowed for type 'fn() void'", - ); + }); - cases.add( - "generic function instance with non-constant expression", + cases.add("generic function instance with non-constant expression", \\fn foo(comptime x: i32, y: i32) i32 { return x + y; } \\fn test1(a: i32, b: i32) i32 { \\ return foo(a, b); \\} \\ \\export fn entry() usize { return @sizeOf(@typeOf(test1)); } - , + , &[_][]const u8{ "tmp.zig:3:16: error: unable to evaluate constant expression", - ); + }); - cases.add( - "assign null to non-optional pointer", + cases.add("assign null to non-optional pointer", \\const a: *u8 = null; \\ \\export fn entry() usize { return @sizeOf(@typeOf(a)); } - , + , &[_][]const u8{ "tmp.zig:1:16: error: expected type '*u8', found '(null)'", - ); + }); - cases.add( - "indexing an array of size zero", + cases.add("indexing an array of size zero", \\const array = [_]u8{}; \\export fn foo() void { \\ const pointer = &array[0]; \\} - , + , &[_][]const u8{ "tmp.zig:3:27: error: index 0 outside array of size 0", - ); + }); - cases.add( - "compile time division by zero", + cases.add("compile time division by zero", \\const y = foo(0); \\fn foo(x: u32) u32 { \\ return 1 / x; \\} \\ \\export fn entry() usize { return @sizeOf(@typeOf(y)); } - , + , &[_][]const u8{ "tmp.zig:3:14: error: division by zero", "tmp.zig:1:14: note: referenced here", - ); + }); - cases.add( - "branch on undefined value", + cases.add("branch on undefined value", \\const x = if (undefined) true else false; \\ \\export fn entry() usize { return @sizeOf(@typeOf(x)); } - , + , &[_][]const u8{ "tmp.zig:1:15: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "div on undefined value", + cases.add("div on undefined value", \\comptime { \\ var a: i64 = undefined; \\ _ = a / a; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "div assign on undefined value", + cases.add("div assign on undefined value", \\comptime { \\ var a: i64 = undefined; \\ a /= a; \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "mod on undefined value", + cases.add("mod on undefined value", \\comptime { \\ var a: i64 = undefined; \\ _ = a % a; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "mod assign on undefined value", + cases.add("mod assign on undefined value", \\comptime { \\ var a: i64 = undefined; \\ a %= a; \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "add on undefined value", + cases.add("add on undefined value", \\comptime { \\ var a: i64 = undefined; \\ _ = a + a; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "add assign on undefined value", + cases.add("add assign on undefined value", \\comptime { \\ var a: i64 = undefined; \\ a += a; \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "add wrap on undefined value", + cases.add("add wrap on undefined value", \\comptime { \\ var a: i64 = undefined; \\ _ = a +% a; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "add wrap assign on undefined value", + cases.add("add wrap assign on undefined value", \\comptime { \\ var a: i64 = undefined; \\ a +%= a; \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "sub on undefined value", + cases.add("sub on undefined value", \\comptime { \\ var a: i64 = undefined; \\ _ = a - a; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "sub assign on undefined value", + cases.add("sub assign on undefined value", \\comptime { \\ var a: i64 = undefined; \\ a -= a; \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "sub wrap on undefined value", + cases.add("sub wrap on undefined value", \\comptime { \\ var a: i64 = undefined; \\ _ = a -% a; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "sub wrap assign on undefined value", + cases.add("sub wrap assign on undefined value", \\comptime { \\ var a: i64 = undefined; \\ a -%= a; \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "mult on undefined value", + cases.add("mult on undefined value", \\comptime { \\ var a: i64 = undefined; \\ _ = a * a; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "mult assign on undefined value", + cases.add("mult assign on undefined value", \\comptime { \\ var a: i64 = undefined; \\ a *= a; \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "mult wrap on undefined value", + cases.add("mult wrap on undefined value", \\comptime { \\ var a: i64 = undefined; \\ _ = a *% a; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "mult wrap assign on undefined value", + cases.add("mult wrap assign on undefined value", \\comptime { \\ var a: i64 = undefined; \\ a *%= a; \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "shift left on undefined value", + cases.add("shift left on undefined value", \\comptime { \\ var a: i64 = undefined; \\ _ = a << 2; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "shift left assign on undefined value", + cases.add("shift left assign on undefined value", \\comptime { \\ var a: i64 = undefined; \\ a <<= 2; \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "shift right on undefined value", + cases.add("shift right on undefined value", \\comptime { \\ var a: i64 = undefined; \\ _ = a >> 2; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "shift left assign on undefined value", + cases.add("shift left assign on undefined value", \\comptime { \\ var a: i64 = undefined; \\ a >>= 2; \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "bin and on undefined value", + cases.add("bin and on undefined value", \\comptime { \\ var a: i64 = undefined; \\ _ = a & a; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "bin and assign on undefined value", + cases.add("bin and assign on undefined value", \\comptime { \\ var a: i64 = undefined; \\ a &= a; \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "bin or on undefined value", + cases.add("bin or on undefined value", \\comptime { \\ var a: i64 = undefined; \\ _ = a | a; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "bin or assign on undefined value", + cases.add("bin or assign on undefined value", \\comptime { \\ var a: i64 = undefined; \\ a |= a; \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "bin xor on undefined value", + cases.add("bin xor on undefined value", \\comptime { \\ var a: i64 = undefined; \\ _ = a ^ a; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "bin xor assign on undefined value", + cases.add("bin xor assign on undefined value", \\comptime { \\ var a: i64 = undefined; \\ a ^= a; \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "equal on undefined value", + cases.add("equal on undefined value", \\comptime { \\ var a: i64 = undefined; \\ _ = a == a; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "not equal on undefined value", + cases.add("not equal on undefined value", \\comptime { \\ var a: i64 = undefined; \\ _ = a != a; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "greater than on undefined value", + cases.add("greater than on undefined value", \\comptime { \\ var a: i64 = undefined; \\ _ = a > a; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "greater than equal on undefined value", + cases.add("greater than equal on undefined value", \\comptime { \\ var a: i64 = undefined; \\ _ = a >= a; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "less than on undefined value", + cases.add("less than on undefined value", \\comptime { \\ var a: i64 = undefined; \\ _ = a < a; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "less than equal on undefined value", + cases.add("less than equal on undefined value", \\comptime { \\ var a: i64 = undefined; \\ _ = a <= a; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "and on undefined value", + cases.add("and on undefined value", \\comptime { \\ var a: bool = undefined; \\ _ = a and a; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "or on undefined value", + cases.add("or on undefined value", \\comptime { \\ var a: bool = undefined; \\ _ = a or a; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "negate on undefined value", + cases.add("negate on undefined value", \\comptime { \\ var a: i64 = undefined; \\ _ = -a; \\} - , + , &[_][]const u8{ "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "negate wrap on undefined value", + cases.add("negate wrap on undefined value", \\comptime { \\ var a: i64 = undefined; \\ _ = -%a; \\} - , + , &[_][]const u8{ "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "bin not on undefined value", + cases.add("bin not on undefined value", \\comptime { \\ var a: i64 = undefined; \\ _ = ~a; \\} - , + , &[_][]const u8{ "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "bool not on undefined value", + cases.add("bool not on undefined value", \\comptime { \\ var a: bool = undefined; \\ _ = !a; \\} - , + , &[_][]const u8{ "tmp.zig:3:10: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "orelse on undefined value", + cases.add("orelse on undefined value", \\comptime { \\ var a: ?bool = undefined; \\ _ = a orelse false; \\} - , + , &[_][]const u8{ "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "catch on undefined value", + cases.add("catch on undefined value", \\comptime { \\ var a: anyerror!bool = undefined; \\ _ = a catch |err| false; \\} - , + , &[_][]const u8{ "tmp.zig:3:11: error: use of undefined value here causes undefined behavior", - ); + }); - cases.add( - "deref on undefined value", + cases.add("deref on undefined value", \\comptime { \\ var a: *u8 = undefined; \\ _ = a.*; \\} - , + , &[_][]const u8{ "tmp.zig:3:9: error: attempt to dereference undefined value", - ); + }); - cases.add( - "endless loop in function evaluation", + cases.add("endless loop in function evaluation", \\const seventh_fib_number = fibbonaci(7); \\fn fibbonaci(x: i32) i32 { \\ return fibbonaci(x - 1) + fibbonaci(x - 2); \\} \\ \\export fn entry() usize { return @sizeOf(@typeOf(seventh_fib_number)); } - , + , &[_][]const u8{ "tmp.zig:3:21: error: evaluation exceeded 1000 backwards branches", "tmp.zig:1:37: note: referenced here", "tmp.zig:6:50: note: referenced here", - ); + }); - cases.add( - "@embedFile with bogus file", + cases.add("@embedFile with bogus file", \\const resource = @embedFile("bogus.txt",); \\ \\export fn entry() usize { return @sizeOf(@typeOf(resource)); } - , + , &[_][]const u8{ "tmp.zig:1:29: error: unable to find '", "bogus.txt'", - ); + }); - cases.add( - "non-const expression in struct literal outside function", + cases.add("non-const expression in struct literal outside function", \\const Foo = struct { \\ x: i32, \\}; @@ -4645,12 +4300,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\extern fn get_it() i32; \\ \\export fn entry() usize { return @sizeOf(@typeOf(a)); } - , + , &[_][]const u8{ "tmp.zig:4:21: error: unable to evaluate constant expression", - ); + }); - cases.add( - "non-const expression function call with struct return value outside function", + cases.add("non-const expression function call with struct return value outside function", \\const Foo = struct { \\ x: i32, \\}; @@ -4662,25 +4316,23 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\var global_side_effect = false; \\ \\export fn entry() usize { return @sizeOf(@typeOf(a)); } - , + , &[_][]const u8{ "tmp.zig:6:26: error: unable to evaluate constant expression", "tmp.zig:4:17: note: referenced here", - ); + }); - cases.add( - "undeclared identifier error should mark fn as impure", + cases.add("undeclared identifier error should mark fn as impure", \\export fn foo() void { \\ test_a_thing(); \\} \\fn test_a_thing() void { \\ bad_fn_call(); \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: use of undeclared identifier 'bad_fn_call'", - ); + }); - cases.add( - "illegal comparison of types", + cases.add("illegal comparison of types", \\fn bad_eql_1(a: []u8, b: []u8) bool { \\ return a == b; \\} @@ -4694,13 +4346,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ \\export fn entry1() usize { return @sizeOf(@typeOf(bad_eql_1)); } \\export fn entry2() usize { return @sizeOf(@typeOf(bad_eql_2)); } - , + , &[_][]const u8{ "tmp.zig:2:14: error: operator not allowed for type '[]u8'", "tmp.zig:9:16: error: operator not allowed for type 'EnumWithData'", - ); + }); - cases.add( - "non-const switch number literal", + cases.add("non-const switch number literal", \\export fn foo() void { \\ const x = switch (bar()) { \\ 1, 2 => 1, @@ -4711,109 +4362,100 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn bar() i32 { \\ return 2; \\} - , + , &[_][]const u8{ "tmp.zig:5:17: error: cannot store runtime value in type 'comptime_int'", - ); + }); - cases.add( - "atomic orderings of cmpxchg - failure stricter than success", + cases.add("atomic orderings of cmpxchg - failure stricter than success", \\const AtomicOrder = @import("builtin").AtomicOrder; \\export fn f() void { \\ var x: i32 = 1234; \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {} \\} - , + , &[_][]const u8{ "tmp.zig:4:81: error: failure atomic ordering must be no stricter than success", - ); + }); - cases.add( - "atomic orderings of cmpxchg - success Monotonic or stricter", + cases.add("atomic orderings of cmpxchg - success Monotonic or stricter", \\const AtomicOrder = @import("builtin").AtomicOrder; \\export fn f() void { \\ var x: i32 = 1234; \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {} \\} - , + , &[_][]const u8{ "tmp.zig:4:58: error: success atomic ordering must be Monotonic or stricter", - ); + }); - cases.add( - "negation overflow in function evaluation", + cases.add("negation overflow in function evaluation", \\const y = neg(-128); \\fn neg(x: i8) i8 { \\ return -x; \\} \\ \\export fn entry() usize { return @sizeOf(@typeOf(y)); } - , + , &[_][]const u8{ "tmp.zig:3:12: error: negation caused overflow", "tmp.zig:1:14: note: referenced here", - ); + }); - cases.add( - "add overflow in function evaluation", + cases.add("add overflow in function evaluation", \\const y = add(65530, 10); \\fn add(a: u16, b: u16) u16 { \\ return a + b; \\} \\ \\export fn entry() usize { return @sizeOf(@typeOf(y)); } - , + , &[_][]const u8{ "tmp.zig:3:14: error: operation caused overflow", "tmp.zig:1:14: note: referenced here", - ); + }); - cases.add( - "sub overflow in function evaluation", + cases.add("sub overflow in function evaluation", \\const y = sub(10, 20); \\fn sub(a: u16, b: u16) u16 { \\ return a - b; \\} \\ \\export fn entry() usize { return @sizeOf(@typeOf(y)); } - , + , &[_][]const u8{ "tmp.zig:3:14: error: operation caused overflow", "tmp.zig:1:14: note: referenced here", - ); + }); - cases.add( - "mul overflow in function evaluation", + cases.add("mul overflow in function evaluation", \\const y = mul(300, 6000); \\fn mul(a: u16, b: u16) u16 { \\ return a * b; \\} \\ \\export fn entry() usize { return @sizeOf(@typeOf(y)); } - , + , &[_][]const u8{ "tmp.zig:3:14: error: operation caused overflow", "tmp.zig:1:14: note: referenced here", - ); + }); - cases.add( - "truncate sign mismatch", + cases.add("truncate sign mismatch", \\fn f() i8 { \\ var x: u32 = 10; \\ return @truncate(i8, x); \\} \\ \\export fn entry() usize { return @sizeOf(@typeOf(f)); } - , + , &[_][]const u8{ "tmp.zig:3:26: error: expected signed integer type, found 'u32'", - ); + }); - cases.add( - "try in function with non error return type", + cases.add("try in function with non error return type", \\export fn f() void { \\ try something(); \\} \\fn something() anyerror!void { } - , + , &[_][]const u8{ "tmp.zig:2:5: error: expected type 'void', found 'anyerror'", "tmp.zig:1:15: note: return type declared here", - ); + }); - cases.add( - "invalid pointer for var type", + cases.add("invalid pointer for var type", \\extern fn ext() usize; \\var bytes: [ext()]u8 = undefined; \\export fn f() void { @@ -4821,43 +4463,39 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ b.* = @as(u8, i); \\ } \\} - , + , &[_][]const u8{ "tmp.zig:2:13: error: unable to evaluate constant expression", - ); + }); - cases.add( - "export function with comptime parameter", + cases.add("export function with comptime parameter", \\export fn foo(comptime x: i32, y: i32) i32{ \\ return x + y; \\} - , + , &[_][]const u8{ "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'", - ); + }); - cases.add( - "extern function with comptime parameter", + cases.add("extern function with comptime parameter", \\extern fn foo(comptime x: i32, y: i32) i32; \\fn f() i32 { \\ return foo(1, 2); \\} \\export fn entry() usize { return @sizeOf(@typeOf(f)); } - , + , &[_][]const u8{ "tmp.zig:1:15: error: comptime parameter not allowed in function with calling convention 'ccc'", - ); + }); - cases.add( - "convert fixed size array to slice with invalid size", + cases.add("convert fixed size array to slice with invalid size", \\export fn f() void { \\ var array: [5]u8 = undefined; \\ var foo = @bytesToSlice(u32, &array)[0]; \\} - , + , &[_][]const u8{ "tmp.zig:3:15: error: unable to convert [5]u8 to []align(1) u32: size mismatch", "tmp.zig:3:29: note: u32 has size 4; remaining bytes: 1", - ); + }); - cases.add( - "non-pure function returns type", + cases.add("non-pure function returns type", \\var a: u32 = 0; \\pub fn List(comptime T: type) type { \\ a += 1; @@ -4876,24 +4514,22 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var list: List(i32) = undefined; \\ list.length = 10; \\} - , + , &[_][]const u8{ "tmp.zig:3:7: error: unable to evaluate constant expression", "tmp.zig:16:19: note: referenced here", - ); + }); - cases.add( - "bogus method call on slice", + cases.add("bogus method call on slice", \\var self = "aoeu"; \\fn f(m: []const u8) void { \\ m.copy(u8, self[0..], m); \\} \\export fn entry() usize { return @sizeOf(@typeOf(f)); } - , + , &[_][]const u8{ "tmp.zig:3:6: error: no member named 'copy' in '[]const u8'", - ); + }); - cases.add( - "wrong number of arguments for method fn call", + cases.add("wrong number of arguments for method fn call", \\const Foo = struct { \\ fn method(self: *const Foo, a: i32) void {} \\}; @@ -4902,39 +4538,35 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ foo.method(1, 2); \\} \\export fn entry() usize { return @sizeOf(@typeOf(f)); } - , + , &[_][]const u8{ "tmp.zig:6:15: error: expected 2 arguments, found 3", - ); + }); - cases.add( - "assign through constant pointer", + cases.add("assign through constant pointer", \\export fn f() void { \\ var cstr = "Hat"; \\ cstr[0] = 'W'; \\} - , + , &[_][]const u8{ "tmp.zig:3:13: error: cannot assign to constant", - ); + }); - cases.add( - "assign through constant slice", + cases.add("assign through constant slice", \\export fn f() void { \\ var cstr: []const u8 = "Hat"; \\ cstr[0] = 'W'; \\} - , + , &[_][]const u8{ "tmp.zig:3:13: error: cannot assign to constant", - ); + }); - cases.add( - "main function with bogus args type", + cases.add("main function with bogus args type", \\pub fn main(args: [][]bogus) !void {} - , + , &[_][]const u8{ "tmp.zig:1:23: error: use of undeclared identifier 'bogus'", - ); + }); - cases.add( - "misspelled type with pointer only reference", + cases.add("misspelled type with pointer only reference", \\const JasonHM = u8; \\const JasonList = *JsonNode; \\ @@ -4965,12 +4597,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\} \\ \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } - , + , &[_][]const u8{ "tmp.zig:5:16: error: use of undeclared identifier 'JsonList'", - ); + }); - cases.add( - "method call with first arg type primitive", + cases.add("method call with first arg type primitive", \\const Foo = struct { \\ x: i32, \\ @@ -4986,12 +4617,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ \\ derp.init(); \\} - , + , &[_][]const u8{ "tmp.zig:14:5: error: expected type 'i32', found 'Foo'", - ); + }); - cases.add( - "method call with first arg type wrong container", + cases.add("method call with first arg type wrong container", \\pub const List = struct { \\ len: usize, \\ allocator: *Allocator, @@ -5016,33 +4646,31 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var x = List.init(&global_allocator); \\ x.init(); \\} - , + , &[_][]const u8{ "tmp.zig:23:5: error: expected type '*Allocator', found '*List'", - ); + }); - cases.add( - "binary not on number literal", + cases.add("binary not on number literal", \\const TINY_QUANTUM_SHIFT = 4; \\const TINY_QUANTUM_SIZE = 1 << TINY_QUANTUM_SHIFT; \\var block_aligned_stuff: usize = (4 + TINY_QUANTUM_SIZE) & ~(TINY_QUANTUM_SIZE - 1); \\ \\export fn entry() usize { return @sizeOf(@typeOf(block_aligned_stuff)); } - , + , &[_][]const u8{ "tmp.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'", - ); + }); cases.addCase(x: { - const tc = cases.create( - "multiple files with private function error", + const tc = cases.create("multiple files with private function error", \\const foo = @import("foo.zig",); \\ \\export fn callPrivFunction() void { \\ foo.privateFunction(); \\} - , + , &[_][]const u8{ "tmp.zig:4:8: error: 'privateFunction' is private", "foo.zig:1:1: note: declared here", - ); + }); tc.addSourceFile("foo.zig", \\fn privateFunction() void { } @@ -5051,18 +4679,16 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { break :x tc; }); - cases.add( - "container init with non-type", + cases.add("container init with non-type", \\const zero: i32 = 0; \\const a = zero{1}; \\ \\export fn entry() usize { return @sizeOf(@typeOf(a)); } - , + , &[_][]const u8{ "tmp.zig:2:11: error: expected type 'type', found 'i32'", - ); + }); - cases.add( - "assign to constant field", + cases.add("assign to constant field", \\const Foo = struct { \\ field: i32, \\}; @@ -5070,12 +4696,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ const f = Foo {.field = 1234,}; \\ f.field = 0; \\} - , + , &[_][]const u8{ "tmp.zig:6:15: error: cannot assign to constant", - ); + }); - cases.add( - "return from defer expression", + cases.add("return from defer expression", \\pub fn testTrickyDefer() !void { \\ defer canFail() catch {}; \\ @@ -5091,72 +4716,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\} \\ \\export fn entry() usize { return @sizeOf(@typeOf(testTrickyDefer)); } - , + , &[_][]const u8{ "tmp.zig:4:11: error: cannot return from defer expression", - ); + }); - cases.add( - "attempt to access var args out of bounds", - \\fn add(args: ...) i32 { - \\ return args[0] + args[1]; - \\} - \\ - \\fn foo() i32 { - \\ return add(@as(i32, 1234)); - \\} - \\ - \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } - , - "tmp.zig:2:26: error: index 1 outside argument list of size 1", - "tmp.zig:6:15: note: called from here", - ); - - cases.add( - "pass integer literal to var args", - \\fn add(args: ...) i32 { - \\ var sum = @as(i32, 0); - \\ {comptime var i: usize = 0; inline while (i < args.len) : (i += 1) { - \\ sum += args[i]; - \\ }} - \\ return sum; - \\} - \\ - \\fn bar() i32 { - \\ return add(1, 2, 3, 4); - \\} - \\ - \\export fn entry() usize { return @sizeOf(@typeOf(bar)); } - , - "tmp.zig:10:16: error: compiler bug: integer and float literals in var args function must be casted", - ); - - cases.add( - "assign too big number to u16", + cases.add("assign too big number to u16", \\export fn foo() void { \\ var vga_mem: u16 = 0xB8000; \\} - , + , &[_][]const u8{ "tmp.zig:2:24: error: integer value 753664 cannot be coerced to type 'u16'", - ); + }); - cases.add( - "global variable alignment non power of 2", + cases.add("global variable alignment non power of 2", \\const some_data: [100]u8 align(3) = undefined; \\export fn entry() usize { return @sizeOf(@typeOf(some_data)); } - , + , &[_][]const u8{ "tmp.zig:1:32: error: alignment value 3 is not a power of 2", - ); + }); - cases.add( - "function alignment non power of 2", + cases.add("function alignment non power of 2", \\extern fn foo() align(3) void; \\export fn entry() void { return foo(); } - , + , &[_][]const u8{ "tmp.zig:1:23: error: alignment value 3 is not a power of 2", - ); + }); - cases.add( - "compile log", + cases.add("compile log", \\export fn foo() void { \\ comptime bar(12, "hi",); \\} @@ -5165,14 +4751,13 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ @compileLog("a", a, "b", b); \\ @compileLog("end",); \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: found compile log statement", "tmp.zig:6:5: error: found compile log statement", "tmp.zig:7:5: error: found compile log statement", - ); + }); - cases.add( - "casting bit offset pointer to regular pointer", + cases.add("casting bit offset pointer to regular pointer", \\const BitField = packed struct { \\ a: u3, \\ b: u3, @@ -5188,12 +4773,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\} \\ \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } - , + , &[_][]const u8{ "tmp.zig:8:26: error: expected type '*const u3', found '*align(:3:1) const u3'", - ); + }); - cases.add( - "referring to a struct that is invalid", + cases.add("referring to a struct that is invalid", \\const UsbDeviceRequest = struct { \\ Type: u8, \\}; @@ -5205,13 +4789,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn assert(ok: bool) void { \\ if (!ok) unreachable; \\} - , + , &[_][]const u8{ "tmp.zig:10:14: error: unable to evaluate constant expression", "tmp.zig:6:20: note: referenced here", - ); + }); - cases.add( - "control flow uses comptime var at runtime", + cases.add("control flow uses comptime var at runtime", \\export fn foo() void { \\ comptime var i = 0; \\ while (i < 5) : (i += 1) { @@ -5220,79 +4803,71 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\} \\ \\fn bar() void { } - , + , &[_][]const u8{ "tmp.zig:3:5: error: control flow attempts to use compile-time variable at runtime", "tmp.zig:3:24: note: compile-time variable assigned here", - ); + }); - cases.add( - "ignored return value", + cases.add("ignored return value", \\export fn foo() void { \\ bar(); \\} \\fn bar() i32 { return 0; } - , + , &[_][]const u8{ "tmp.zig:2:8: error: expression value is ignored", - ); + }); - cases.add( - "ignored assert-err-ok return value", + cases.add("ignored assert-err-ok return value", \\export fn foo() void { \\ bar() catch unreachable; \\} \\fn bar() anyerror!i32 { return 0; } - , + , &[_][]const u8{ "tmp.zig:2:11: error: expression value is ignored", - ); + }); - cases.add( - "ignored statement value", + cases.add("ignored statement value", \\export fn foo() void { \\ 1; \\} - , + , &[_][]const u8{ "tmp.zig:2:5: error: expression value is ignored", - ); + }); - cases.add( - "ignored comptime statement value", + cases.add("ignored comptime statement value", \\export fn foo() void { \\ comptime {1;} \\} - , + , &[_][]const u8{ "tmp.zig:2:15: error: expression value is ignored", - ); + }); - cases.add( - "ignored comptime value", + cases.add("ignored comptime value", \\export fn foo() void { \\ comptime 1; \\} - , + , &[_][]const u8{ "tmp.zig:2:5: error: expression value is ignored", - ); + }); - cases.add( - "ignored defered statement value", + cases.add("ignored defered statement value", \\export fn foo() void { \\ defer {1;} \\} - , + , &[_][]const u8{ "tmp.zig:2:12: error: expression value is ignored", - ); + }); - cases.add( - "ignored defered function call", + cases.add("ignored defered function call", \\export fn foo() void { \\ defer bar(); \\} \\fn bar() anyerror!i32 { return 0; } - , + , &[_][]const u8{ "tmp.zig:2:14: error: expression value is ignored", - ); + }); - cases.add( - "dereference an array", + cases.add("dereference an array", \\var s_buffer: [10]u8 = undefined; \\pub fn pass(in: []u8) []u8 { \\ var out = &s_buffer; @@ -5301,12 +4876,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\} \\ \\export fn entry() usize { return @sizeOf(@typeOf(pass)); } - , + , &[_][]const u8{ "tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8'", - ); + }); - cases.add( - "pass const ptr to mutable ptr fn", + cases.add("pass const ptr to mutable ptr fn", \\fn foo() bool { \\ const a = @as([]const u8, "a",); \\ const b = &a; @@ -5317,22 +4891,21 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\} \\ \\export fn entry() usize { return @sizeOf(@typeOf(foo)); } - , + , &[_][]const u8{ "tmp.zig:4:19: error: expected type '*[]const u8', found '*const []const u8'", - ); + }); cases.addCase(x: { - const tc = cases.create( - "export collision", + const tc = cases.create("export collision", \\const foo = @import("foo.zig",); \\ \\export fn bar() usize { \\ return foo.baz; \\} - , + , &[_][]const u8{ "foo.zig:1:1: error: exported symbol collision: 'bar'", "tmp.zig:3:1: note: other symbol here", - ); + }); tc.addSourceFile("foo.zig", \\export fn bar() void {} @@ -5342,28 +4915,25 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { break :x tc; }); - cases.add( - "implicit cast from array to mutable slice", + cases.add("implicit cast from array to mutable slice", \\var global_array: [10]i32 = undefined; \\fn foo(param: []i32) void {} \\export fn entry() void { \\ foo(global_array); \\} - , + , &[_][]const u8{ "tmp.zig:4:9: error: expected type '[]i32', found '[10]i32'", - ); + }); - cases.add( - "ptrcast to non-pointer", + cases.add("ptrcast to non-pointer", \\export fn entry(a: *i32) usize { \\ return @ptrCast(usize, a); \\} - , + , &[_][]const u8{ "tmp.zig:2:21: error: expected pointer, found 'usize'", - ); + }); - cases.add( - "asm at compile time", + cases.add("asm at compile time", \\comptime { \\ doSomeAsm(); \\} @@ -5375,66 +4945,60 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ \\.set aoeu, derp; \\ ); \\} - , + , &[_][]const u8{ "tmp.zig:6:5: error: unable to evaluate constant expression", - ); + }); - cases.add( - "invalid member of builtin enum", + cases.add("invalid member of builtin enum", \\const builtin = @import("builtin",); \\export fn entry() void { \\ const foo = builtin.Arch.x86; \\} - , + , &[_][]const u8{ "tmp.zig:3:29: error: container 'std.target.Arch' has no member called 'x86'", - ); + }); - cases.add( - "int to ptr of 0 bits", + cases.add("int to ptr of 0 bits", \\export fn foo() void { \\ var x: usize = 0x1000; \\ var y: *void = @intToPtr(*void, x); \\} - , + , &[_][]const u8{ "tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information", - ); + }); - cases.add( - "@fieldParentPtr - non struct", + cases.add("@fieldParentPtr - non struct", \\const Foo = i32; \\export fn foo(a: *i32) *Foo { \\ return @fieldParentPtr(Foo, "a", a); \\} - , + , &[_][]const u8{ "tmp.zig:3:28: error: expected struct type, found 'i32'", - ); + }); - cases.add( - "@fieldParentPtr - bad field name", + cases.add("@fieldParentPtr - bad field name", \\const Foo = extern struct { \\ derp: i32, \\}; \\export fn foo(a: *i32) *Foo { \\ return @fieldParentPtr(Foo, "a", a); \\} - , + , &[_][]const u8{ "tmp.zig:5:33: error: struct 'Foo' has no field 'a'", - ); + }); - cases.add( - "@fieldParentPtr - field pointer is not pointer", + cases.add("@fieldParentPtr - field pointer is not pointer", \\const Foo = extern struct { \\ a: i32, \\}; \\export fn foo(a: i32) *Foo { \\ return @fieldParentPtr(Foo, "a", a); \\} - , + , &[_][]const u8{ "tmp.zig:5:38: error: expected pointer, found 'i32'", - ); + }); - cases.add( - "@fieldParentPtr - comptime field ptr not based on struct", + cases.add("@fieldParentPtr - comptime field ptr not based on struct", \\const Foo = struct { \\ a: i32, \\ b: i32, @@ -5445,12 +5009,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ const field_ptr = @intToPtr(*i32, 0x1234); \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr); \\} - , + , &[_][]const u8{ "tmp.zig:9:55: error: pointer value not based on parent struct", - ); + }); - cases.add( - "@fieldParentPtr - comptime wrong field index", + cases.add("@fieldParentPtr - comptime wrong field index", \\const Foo = struct { \\ a: i32, \\ b: i32, @@ -5460,80 +5023,72 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\comptime { \\ const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a); \\} - , + , &[_][]const u8{ "tmp.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo'", - ); + }); - cases.add( - "@byteOffsetOf - non struct", + cases.add("@byteOffsetOf - non struct", \\const Foo = i32; \\export fn foo() usize { \\ return @byteOffsetOf(Foo, "a",); \\} - , + , &[_][]const u8{ "tmp.zig:3:26: error: expected struct type, found 'i32'", - ); + }); - cases.add( - "@byteOffsetOf - bad field name", + cases.add("@byteOffsetOf - bad field name", \\const Foo = struct { \\ derp: i32, \\}; \\export fn foo() usize { \\ return @byteOffsetOf(Foo, "a",); \\} - , + , &[_][]const u8{ "tmp.zig:5:31: error: struct 'Foo' has no field 'a'", - ); + }); - cases.addExe( - "missing main fn in executable", + cases.addExe("missing main fn in executable", \\ - , + , &[_][]const u8{ "error: root source file has no member called 'main'", - ); + }); - cases.addExe( - "private main fn", + cases.addExe("private main fn", \\fn main() void {} - , + , &[_][]const u8{ "error: 'main' is private", "tmp.zig:1:1: note: declared here", - ); + }); - cases.add( - "setting a section on a local variable", + cases.add("setting a section on a local variable", \\export fn entry() i32 { \\ var foo: i32 linksection(".text2") = 1234; \\ return foo; \\} - , + , &[_][]const u8{ "tmp.zig:2:30: error: cannot set section of local variable 'foo'", - ); + }); - cases.add( - "returning address of local variable - simple", + cases.add("returning address of local variable - simple", \\export fn foo() *i32 { \\ var a: i32 = undefined; \\ return &a; \\} - , + , &[_][]const u8{ "tmp.zig:3:13: error: function returns address of local variable", - ); + }); - cases.add( - "returning address of local variable - phi", + cases.add("returning address of local variable - phi", \\export fn foo(c: bool) *i32 { \\ var a: i32 = undefined; \\ var b: i32 = undefined; \\ return if (c) &a else &b; \\} - , + , &[_][]const u8{ "tmp.zig:4:12: error: function returns address of local variable", - ); + }); - cases.add( - "inner struct member shadowing outer struct member", + cases.add("inner struct member shadowing outer struct member", \\fn A() type { \\ return struct { \\ b: B(), @@ -5553,73 +5108,66 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn assert(ok: bool) void { \\ if (!ok) unreachable; \\} - , + , &[_][]const u8{ "tmp.zig:9:17: error: redefinition of 'Self'", "tmp.zig:5:9: note: previous definition is here", - ); + }); - cases.add( - "while expected bool, got optional", + cases.add("while expected bool, got optional", \\export fn foo() void { \\ while (bar()) {} \\} \\fn bar() ?i32 { return 1; } - , + , &[_][]const u8{ "tmp.zig:2:15: error: expected type 'bool', found '?i32'", - ); + }); - cases.add( - "while expected bool, got error union", + cases.add("while expected bool, got error union", \\export fn foo() void { \\ while (bar()) {} \\} \\fn bar() anyerror!i32 { return 1; } - , + , &[_][]const u8{ "tmp.zig:2:15: error: expected type 'bool', found 'anyerror!i32'", - ); + }); - cases.add( - "while expected optional, got bool", + cases.add("while expected optional, got bool", \\export fn foo() void { \\ while (bar()) |x| {} \\} \\fn bar() bool { return true; } - , + , &[_][]const u8{ "tmp.zig:2:15: error: expected optional type, found 'bool'", - ); + }); - cases.add( - "while expected optional, got error union", + cases.add("while expected optional, got error union", \\export fn foo() void { \\ while (bar()) |x| {} \\} \\fn bar() anyerror!i32 { return 1; } - , + , &[_][]const u8{ "tmp.zig:2:15: error: expected optional type, found 'anyerror!i32'", - ); + }); - cases.add( - "while expected error union, got bool", + cases.add("while expected error union, got bool", \\export fn foo() void { \\ while (bar()) |x| {} else |err| {} \\} \\fn bar() bool { return true; } - , + , &[_][]const u8{ "tmp.zig:2:15: error: expected error union type, found 'bool'", - ); + }); - cases.add( - "while expected error union, got optional", + cases.add("while expected error union, got optional", \\export fn foo() void { \\ while (bar()) |x| {} else |err| {} \\} \\fn bar() ?i32 { return 1; } - , + , &[_][]const u8{ "tmp.zig:2:15: error: expected error union type, found '?i32'", - ); + }); - cases.add( - "inline fn calls itself indirectly", + cases.add("inline fn calls itself indirectly", \\export fn foo() void { \\ bar(); \\} @@ -5632,94 +5180,85 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ quux(); \\} \\extern fn quux() void; - , + , &[_][]const u8{ "tmp.zig:4:1: error: unable to inline function", - ); + }); - cases.add( - "save reference to inline function", + cases.add("save reference to inline function", \\export fn foo() void { \\ quux(@ptrToInt(bar)); \\} \\inline fn bar() void { } \\extern fn quux(usize) void; - , + , &[_][]const u8{ "tmp.zig:4:1: error: unable to inline function", - ); + }); - cases.add( - "signed integer division", + cases.add("signed integer division", \\export fn foo(a: i32, b: i32) i32 { \\ return a / b; \\} - , + , &[_][]const u8{ "tmp.zig:2:14: error: division with 'i32' and 'i32': signed integers must use @divTrunc, @divFloor, or @divExact", - ); + }); - cases.add( - "signed integer remainder division", + cases.add("signed integer remainder division", \\export fn foo(a: i32, b: i32) i32 { \\ return a % b; \\} - , + , &[_][]const u8{ "tmp.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod", - ); + }); - cases.add( - "compile-time division by zero", + cases.add("compile-time division by zero", \\comptime { \\ const a: i32 = 1; \\ const b: i32 = 0; \\ const c = a / b; \\} - , + , &[_][]const u8{ "tmp.zig:4:17: error: division by zero", - ); + }); - cases.add( - "compile-time remainder division by zero", + cases.add("compile-time remainder division by zero", \\comptime { \\ const a: i32 = 1; \\ const b: i32 = 0; \\ const c = a % b; \\} - , + , &[_][]const u8{ "tmp.zig:4:17: error: division by zero", - ); + }); - cases.add( - "@setRuntimeSafety twice for same scope", + cases.add("@setRuntimeSafety twice for same scope", \\export fn foo() void { \\ @setRuntimeSafety(false); \\ @setRuntimeSafety(false); \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: runtime safety set twice for same scope", "tmp.zig:2:5: note: first set here", - ); + }); - cases.add( - "@setFloatMode twice for same scope", + cases.add("@setFloatMode twice for same scope", \\export fn foo() void { \\ @setFloatMode(@import("builtin").FloatMode.Optimized); \\ @setFloatMode(@import("builtin").FloatMode.Optimized); \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: float mode set twice for same scope", "tmp.zig:2:5: note: first set here", - ); + }); - cases.add( - "array access of type", + cases.add("array access of type", \\export fn foo() void { \\ var b: u8[40] = undefined; \\} - , + , &[_][]const u8{ "tmp.zig:2:14: error: array access of non-array type 'type'", - ); + }); - cases.add( - "cannot break out of defer expression", + cases.add("cannot break out of defer expression", \\export fn foo() void { \\ while (true) { \\ defer { @@ -5727,12 +5266,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ } \\ } \\} - , + , &[_][]const u8{ "tmp.zig:4:13: error: cannot break out of defer expression", - ); + }); - cases.add( - "cannot continue out of defer expression", + cases.add("cannot continue out of defer expression", \\export fn foo() void { \\ while (true) { \\ defer { @@ -5740,26 +5278,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ } \\ } \\} - , + , &[_][]const u8{ "tmp.zig:4:13: error: cannot continue out of defer expression", - ); + }); - cases.add( - "calling a var args function only known at runtime", - \\var foos = [_]fn(...) void { foo1, foo2 }; - \\ - \\fn foo1(args: ...) void {} - \\fn foo2(args: ...) void {} - \\ - \\pub fn main() !void { - \\ foos[0](); - \\} - , - "tmp.zig:7:9: error: calling a generic function requires compile-time known function value", - ); - - cases.add( - "calling a generic function only known at runtime", + cases.add("calling a generic function only known at runtime", \\var foos = [_]fn(var) void { foo1, foo2 }; \\ \\fn foo1(arg: var) void {} @@ -5768,12 +5291,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\pub fn main() !void { \\ foos[0](true); \\} - , + , &[_][]const u8{ "tmp.zig:7:9: error: calling a generic function requires compile-time known function value", - ); + }); - cases.add( - "@compileError shows traceback of references that caused it", + cases.add("@compileError shows traceback of references that caused it", \\const foo = @compileError("aoeu",); \\ \\const bar = baz + foo; @@ -5782,96 +5304,86 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() i32 { \\ return bar; \\} - , + , &[_][]const u8{ "tmp.zig:1:13: error: aoeu", "tmp.zig:3:19: note: referenced here", "tmp.zig:7:12: note: referenced here", - ); + }); - cases.add( - "float literal too large error", + cases.add("float literal too large error", \\comptime { \\ const a = 0x1.0p18495; \\} - , + , &[_][]const u8{ "tmp.zig:2:15: error: float literal out of range of any type", - ); + }); - cases.add( - "float literal too small error (denormal)", + cases.add("float literal too small error (denormal)", \\comptime { \\ const a = 0x1.0p-19000; \\} - , + , &[_][]const u8{ "tmp.zig:2:15: error: float literal out of range of any type", - ); + }); - cases.add( - "explicit cast float literal to integer when there is a fraction component", + cases.add("explicit cast float literal to integer when there is a fraction component", \\export fn entry() i32 { \\ return @as(i32, 12.34); \\} - , + , &[_][]const u8{ "tmp.zig:2:21: error: fractional component prevents float value 12.340000 from being casted to type 'i32'", - ); + }); - cases.add( - "non pointer given to @ptrToInt", + cases.add("non pointer given to @ptrToInt", \\export fn entry(x: i32) usize { \\ return @ptrToInt(x); \\} - , + , &[_][]const u8{ "tmp.zig:2:22: error: expected pointer, found 'i32'", - ); + }); - cases.add( - "@shlExact shifts out 1 bits", + cases.add("@shlExact shifts out 1 bits", \\comptime { \\ const x = @shlExact(@as(u8, 0b01010101), 2); \\} - , + , &[_][]const u8{ "tmp.zig:2:15: error: operation caused overflow", - ); + }); - cases.add( - "@shrExact shifts out 1 bits", + cases.add("@shrExact shifts out 1 bits", \\comptime { \\ const x = @shrExact(@as(u8, 0b10101010), 2); \\} - , + , &[_][]const u8{ "tmp.zig:2:15: error: exact shift shifted out 1 bits", - ); + }); - cases.add( - "shifting without int type or comptime known", + cases.add("shifting without int type or comptime known", \\export fn entry(x: u8) u8 { \\ return 0x11 << x; \\} - , + , &[_][]const u8{ "tmp.zig:2:17: error: LHS of shift must be an integer type, or RHS must be compile-time known", - ); + }); - cases.add( - "shifting RHS is log2 of LHS int bit width", + cases.add("shifting RHS is log2 of LHS int bit width", \\export fn entry(x: u8, y: u8) u8 { \\ return x << y; \\} - , + , &[_][]const u8{ "tmp.zig:2:17: error: expected type 'u3', found 'u8'", - ); + }); - cases.add( - "globally shadowing a primitive type", + cases.add("globally shadowing a primitive type", \\const u16 = @intType(false, 8); \\export fn entry() void { \\ const a: u16 = 300; \\} - , + , &[_][]const u8{ "tmp.zig:1:1: error: declaration shadows primitive type 'u16'", - ); + }); - cases.add( - "implicitly increasing pointer alignment", + cases.add("implicitly increasing pointer alignment", \\const Foo = packed struct { \\ a: u8, \\ b: u32, @@ -5885,12 +5397,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn bar(x: *u32) void { \\ x.* += 1; \\} - , + , &[_][]const u8{ "tmp.zig:8:13: error: expected type '*u32', found '*align(1) u32'", - ); + }); - cases.add( - "implicitly increasing slice alignment", + cases.add("implicitly increasing slice alignment", \\const Foo = packed struct { \\ a: u8, \\ b: u32, @@ -5905,36 +5416,33 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn bar(x: []u32) void { \\ x[0] += 1; \\} - , + , &[_][]const u8{ "tmp.zig:9:26: error: cast increases pointer alignment", "tmp.zig:9:26: note: '*align(1) u32' has alignment 1", "tmp.zig:9:26: note: '*[1]u32' has alignment 4", - ); + }); - cases.add( - "increase pointer alignment in @ptrCast", + cases.add("increase pointer alignment in @ptrCast", \\export fn entry() u32 { \\ var bytes: [4]u8 = [_]u8{0x01, 0x02, 0x03, 0x04}; \\ const ptr = @ptrCast(*u32, &bytes[0]); \\ return ptr.*; \\} - , + , &[_][]const u8{ "tmp.zig:3:17: error: cast increases pointer alignment", "tmp.zig:3:38: note: '*u8' has alignment 1", "tmp.zig:3:26: note: '*u32' has alignment 4", - ); + }); - cases.add( - "@alignCast expects pointer or slice", + cases.add("@alignCast expects pointer or slice", \\export fn entry() void { \\ @alignCast(4, @as(u32, 3)); \\} - , + , &[_][]const u8{ "tmp.zig:2:19: error: expected pointer or slice, found 'u32'", - ); + }); - cases.add( - "passing an under-aligned function pointer", + cases.add("passing an under-aligned function pointer", \\export fn entry() void { \\ testImplicitlyDecreaseFnAlign(alignedSmall, 1234); \\} @@ -5942,45 +5450,41 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ if (ptr() != answer) unreachable; \\} \\fn alignedSmall() align(4) i32 { return 1234; } - , + , &[_][]const u8{ "tmp.zig:2:35: error: expected type 'fn() align(8) i32', found 'fn() align(4) i32'", - ); + }); - cases.add( - "passing a not-aligned-enough pointer to cmpxchg", + cases.add("passing a not-aligned-enough pointer to cmpxchg", \\const AtomicOrder = @import("builtin").AtomicOrder; \\export fn entry() bool { \\ var x: i32 align(1) = 1234; \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {} \\ return x == 5678; \\} - , + , &[_][]const u8{ "tmp.zig:4:32: error: expected type '*i32', found '*align(1) i32'", - ); + }); - cases.add( - "wrong size to an array literal", + cases.add("wrong size to an array literal", \\comptime { \\ const array = [2]u8{1, 2, 3}; \\} - , + , &[_][]const u8{ "tmp.zig:2:31: error: index 2 outside array of size 2", - ); + }); - cases.add( - "wrong pointer coerced to pointer to @OpaqueType()", + cases.add("wrong pointer coerced to pointer to @OpaqueType()", \\const Derp = @OpaqueType(); \\extern fn bar(d: *Derp) void; \\export fn foo() void { \\ var x = @as(u8, 1); \\ bar(@ptrCast(*c_void, &x)); \\} - , + , &[_][]const u8{ "tmp.zig:5:9: error: expected type '*Derp', found '*c_void'", - ); + }); - cases.add( - "non-const variables of things that require const variables", + cases.add("non-const variables of things that require const variables", \\export fn entry1() void { \\ var m2 = &2; \\} @@ -6012,7 +5516,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\const Foo = struct { \\ fn bar(self: *const Foo) void {} \\}; - , + , &[_][]const u8{ "tmp.zig:2:4: error: variable of type '*comptime_int' must be const or comptime", "tmp.zig:5:4: error: variable of type '(undefined)' must be const or comptime", "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 { "tmp.zig:20:4: error: variable of type 'type' must be const or comptime", "tmp.zig:23:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime", "tmp.zig:26:22: error: unreachable code", - ); + }); - cases.add( - "wrong types given to atomic order args in cmpxchg", + cases.add("wrong types given to atomic order args in cmpxchg", \\export fn entry() void { \\ var x: i32 = 1234; \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, @as(u32, 1234), @as(u32, 1234))) {} \\} - , + , &[_][]const u8{ "tmp.zig:3:47: error: expected type 'std.builtin.AtomicOrder', found 'u32'", - ); + }); - cases.add( - "wrong types given to @export", + cases.add("wrong types given to @export", \\extern fn entry() void { } \\comptime { \\ @export("entry", entry, @as(u32, 1234)); \\} - , + , &[_][]const u8{ "tmp.zig:3:29: error: expected type 'std.builtin.GlobalLinkage', found 'u32'", - ); + }); - cases.add( - "struct with invalid field", + cases.add("struct with invalid field", \\const std = @import("std",); \\const Allocator = std.mem.Allocator; \\const ArrayList = std.ArrayList; @@ -6069,62 +5570,56 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ .weight = HeaderWeight.H1, \\ }; \\} - , + , &[_][]const u8{ "tmp.zig:14:17: error: use of undeclared identifier 'HeaderValue'", - ); + }); - cases.add( - "@setAlignStack outside function", + cases.add("@setAlignStack outside function", \\comptime { \\ @setAlignStack(16); \\} - , + , &[_][]const u8{ "tmp.zig:2:5: error: @setAlignStack outside function", - ); + }); - cases.add( - "@setAlignStack in naked function", + cases.add("@setAlignStack in naked function", \\export nakedcc fn entry() void { \\ @setAlignStack(16); \\} - , + , &[_][]const u8{ "tmp.zig:2:5: error: @setAlignStack in naked function", - ); + }); - cases.add( - "@setAlignStack in inline function", + cases.add("@setAlignStack in inline function", \\export fn entry() void { \\ foo(); \\} \\inline fn foo() void { \\ @setAlignStack(16); \\} - , + , &[_][]const u8{ "tmp.zig:5:5: error: @setAlignStack in inline function", - ); + }); - cases.add( - "@setAlignStack set twice", + cases.add("@setAlignStack set twice", \\export fn entry() void { \\ @setAlignStack(16); \\ @setAlignStack(16); \\} - , + , &[_][]const u8{ "tmp.zig:3:5: error: alignstack set twice", "tmp.zig:2:5: note: first set here", - ); + }); - cases.add( - "@setAlignStack too big", + cases.add("@setAlignStack too big", \\export fn entry() void { \\ @setAlignStack(511 + 1); \\} - , + , &[_][]const u8{ "tmp.zig:2:5: error: attempt to @setAlignStack(512); maximum is 256", - ); + }); - cases.add( - "storing runtime value in compile time variable then using it", + cases.add("storing runtime value in compile time variable then using it", \\const Mode = @import("builtin").Mode; \\ \\fn Free(comptime filename: []const u8) TestCase { @@ -6166,12 +5661,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ } \\ } \\} - , + , &[_][]const u8{ "tmp.zig:37:29: error: cannot store runtime value in compile time variable", - ); + }); - cases.add( - "field access of opaque type", + cases.add("field access of opaque type", \\const MyType = @OpaqueType(); \\ \\export fn entry() bool { @@ -6182,163 +5676,143 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn bar(x: *MyType) bool { \\ return x.blah; \\} - , + , &[_][]const u8{ "tmp.zig:9:13: error: type '*MyType' does not support field access", - ); + }); - cases.add( - "carriage return special case", - "fn test() bool {\r\n" ++ - " true\r\n" ++ - "}\r\n", + cases.add("carriage return special case", "fn test() bool {\r\n" ++ + " true\r\n" ++ + "}\r\n", &[_][]const u8{ "tmp.zig:1:17: error: invalid carriage return, only '\\n' line endings are supported", - ); + }); - cases.add( - "invalid legacy unicode escape", + cases.add("invalid legacy unicode escape", \\export fn entry() void { \\ const a = '\U1234'; \\} - , + , &[_][]const u8{ "tmp.zig:2:17: error: invalid character: 'U'", - ); + }); - cases.add( - "invalid empty unicode escape", + cases.add("invalid empty unicode escape", \\export fn entry() void { \\ const a = '\u{}'; \\} - , + , &[_][]const u8{ "tmp.zig:2:19: error: empty unicode escape sequence", - ); + }); - cases.add( - "non-printable invalid character", - "\xff\xfe" ++ - \\fn test() bool {\r - \\ true\r - \\} - , + cases.add("non-printable invalid character", "\xff\xfe" ++ + \\fn test() bool {\r + \\ true\r + \\} + , &[_][]const u8{ "tmp.zig:1:1: error: invalid character: '\\xff'", - ); + }); - cases.add( - "non-printable invalid character with escape alternative", - "fn test() bool {\n" ++ - "\ttrue\n" ++ - "}\n", + cases.add("non-printable invalid character with escape alternative", "fn test() bool {\n" ++ + "\ttrue\n" ++ + "}\n", &[_][]const u8{ "tmp.zig:2:1: error: invalid character: '\\t'", - ); + }); - cases.add( - "@ArgType given non function parameter", + cases.add("@ArgType given non function parameter", \\comptime { \\ _ = @ArgType(i32, 3); \\} - , + , &[_][]const u8{ "tmp.zig:2:18: error: expected function, found 'i32'", - ); + }); - cases.add( - "@ArgType arg index out of bounds", + cases.add("@ArgType arg index out of bounds", \\comptime { \\ _ = @ArgType(@typeOf(add), 2); \\} \\fn add(a: i32, b: i32) i32 { return a + b; } - , + , &[_][]const u8{ "tmp.zig:2:32: error: arg index 2 out of bounds; 'fn(i32, i32) i32' has 2 arguments", - ); + }); - cases.add( - "@memberType on unsupported type", + cases.add("@memberType on unsupported type", \\comptime { \\ _ = @memberType(i32, 0); \\} - , + , &[_][]const u8{ "tmp.zig:2:21: error: type 'i32' does not support @memberType", - ); + }); - cases.add( - "@memberType on enum", + cases.add("@memberType on enum", \\comptime { \\ _ = @memberType(Foo, 0); \\} \\const Foo = enum {A,}; - , + , &[_][]const u8{ "tmp.zig:2:21: error: type 'Foo' does not support @memberType", - ); + }); - cases.add( - "@memberType struct out of bounds", + cases.add("@memberType struct out of bounds", \\comptime { \\ _ = @memberType(Foo, 0); \\} \\const Foo = struct {}; - , + , &[_][]const u8{ "tmp.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members", - ); + }); - cases.add( - "@memberType union out of bounds", + cases.add("@memberType union out of bounds", \\comptime { \\ _ = @memberType(Foo, 1); \\} \\const Foo = union {A: void,}; - , + , &[_][]const u8{ "tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members", - ); + }); - cases.add( - "@memberName on unsupported type", + cases.add("@memberName on unsupported type", \\comptime { \\ _ = @memberName(i32, 0); \\} - , + , &[_][]const u8{ "tmp.zig:2:21: error: type 'i32' does not support @memberName", - ); + }); - cases.add( - "@memberName struct out of bounds", + cases.add("@memberName struct out of bounds", \\comptime { \\ _ = @memberName(Foo, 0); \\} \\const Foo = struct {}; - , + , &[_][]const u8{ "tmp.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members", - ); + }); - cases.add( - "@memberName enum out of bounds", + cases.add("@memberName enum out of bounds", \\comptime { \\ _ = @memberName(Foo, 1); \\} \\const Foo = enum {A,}; - , + , &[_][]const u8{ "tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members", - ); + }); - cases.add( - "@memberName union out of bounds", + cases.add("@memberName union out of bounds", \\comptime { \\ _ = @memberName(Foo, 1); \\} \\const Foo = union {A:i32,}; - , + , &[_][]const u8{ "tmp.zig:2:26: error: member index 1 out of bounds; 'Foo' has 1 members", - ); + }); - cases.add( - "calling var args extern function, passing array instead of pointer", + cases.add("calling var args extern function, passing array instead of pointer", \\export fn entry() void { \\ foo("hello".*,); \\} \\pub extern fn foo(format: *const u8, ...) void; - , + , &[_][]const u8{ "tmp.zig:2:16: error: expected type '*const u8', found '[5:0]u8'", - ); + }); - cases.add( - "constant inside comptime function has compile error", + cases.add("constant inside comptime function has compile error", \\const ContextAllocator = MemoryPool(usize); \\ \\pub fn MemoryPool(comptime T: type) type { @@ -6352,11 +5826,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ var allocator: ContextAllocator = undefined; \\} - , + , &[_][]const u8{ "tmp.zig:4:25: error: aoeu", "tmp.zig:1:36: note: referenced here", "tmp.zig:12:20: note: referenced here", - ); + }); cases.add("specify enum tag type that is too small", \\const Small = enum (u2) { @@ -6370,10 +5844,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ var x = Small.One; \\} - , "tmp.zig:6:5: error: enumeration value 4 too large for type 'u2'"); + , &[_][]const u8{ + "tmp.zig:6:5: error: enumeration value 4 too large for type 'u2'", + }); - cases.add( - "specify non-integer enum tag type", + cases.add("specify non-integer enum tag type", \\const Small = enum (f32) { \\ One, \\ Two, @@ -6383,12 +5858,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ var x = Small.One; \\} - , + , &[_][]const u8{ "tmp.zig:1:21: error: expected integer, found 'f32'", - ); + }); - cases.add( - "implicitly casting enum to tag type", + cases.add("implicitly casting enum to tag type", \\const Small = enum(u2) { \\ One, \\ Two, @@ -6399,12 +5873,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ var x: u2 = Small.Two; \\} - , + , &[_][]const u8{ "tmp.zig:9:22: error: expected type 'u2', found 'Small'", - ); + }); - cases.add( - "explicitly casting non tag type to enum", + cases.add("explicitly casting non tag type to enum", \\const Small = enum(u2) { \\ One, \\ Two, @@ -6416,45 +5889,41 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var y = @as(u3, 3); \\ var x = @intToEnum(Small, y); \\} - , + , &[_][]const u8{ "tmp.zig:10:31: error: expected type 'u2', found 'u3'", - ); + }); - cases.add( - "union fields with value assignments", + cases.add("union fields with value assignments", \\const MultipleChoice = union { \\ A: i32 = 20, \\}; \\export fn entry() void { \\ var x: MultipleChoice = undefined; \\} - , + , &[_][]const u8{ "tmp.zig:2:14: error: untagged union field assignment", "tmp.zig:1:24: note: consider 'union(enum)' here", - ); + }); - cases.add( - "enum with 0 fields", + cases.add("enum with 0 fields", \\const Foo = enum {}; \\export fn entry() usize { \\ return @sizeOf(Foo); \\} - , + , &[_][]const u8{ "tmp.zig:1:13: error: enums must have 1 or more fields", - ); + }); - cases.add( - "union with 0 fields", + cases.add("union with 0 fields", \\const Foo = union {}; \\export fn entry() usize { \\ return @sizeOf(Foo); \\} - , + , &[_][]const u8{ "tmp.zig:1:13: error: unions must have 1 or more fields", - ); + }); - cases.add( - "enum value already taken", + cases.add("enum value already taken", \\const MultipleChoice = enum(u32) { \\ A = 20, \\ B = 40, @@ -6465,13 +5934,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ var x = MultipleChoice.C; \\} - , + , &[_][]const u8{ "tmp.zig:6:5: error: enum tag value 60 already taken", "tmp.zig:4:5: note: other occurrence here", - ); + }); - cases.add( - "union with specified enum omits field", + cases.add("union with specified enum omits field", \\const Letter = enum { \\ A, \\ B, @@ -6484,50 +5952,46 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() usize { \\ return @sizeOf(Payload); \\} - , + , &[_][]const u8{ "tmp.zig:6:17: error: enum field missing: 'C'", "tmp.zig:4:5: note: declared here", - ); + }); - cases.add( - "@TagType when union has no attached enum", + cases.add("@TagType when union has no attached enum", \\const Foo = union { \\ A: i32, \\}; \\export fn entry() void { \\ const x = @TagType(Foo); \\} - , + , &[_][]const u8{ "tmp.zig:5:24: error: union 'Foo' has no tag", "tmp.zig:1:13: note: consider 'union(enum)' here", - ); + }); - cases.add( - "non-integer tag type to automatic union enum", + cases.add("non-integer tag type to automatic union enum", \\const Foo = union(enum(f32)) { \\ A: i32, \\}; \\export fn entry() void { \\ const x = @TagType(Foo); \\} - , + , &[_][]const u8{ "tmp.zig:1:24: error: expected integer tag type, found 'f32'", - ); + }); - cases.add( - "non-enum tag type passed to union", + cases.add("non-enum tag type passed to union", \\const Foo = union(u32) { \\ A: i32, \\}; \\export fn entry() void { \\ const x = @TagType(Foo); \\} - , + , &[_][]const u8{ "tmp.zig:1:19: error: expected enum tag type, found 'u32'", - ); + }); - cases.add( - "union auto-enum value already taken", + cases.add("union auto-enum value already taken", \\const MultipleChoice = union(enum(u32)) { \\ A = 20, \\ B = 40, @@ -6538,13 +6002,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ var x = MultipleChoice { .C = {} }; \\} - , + , &[_][]const u8{ "tmp.zig:6:9: error: enum tag value 60 already taken", "tmp.zig:4:9: note: other occurrence here", - ); + }); - cases.add( - "union enum field does not match enum", + cases.add("union enum field does not match enum", \\const Letter = enum { \\ A, \\ B, @@ -6559,13 +6022,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ var a = Payload {.A = 1234}; \\} - , + , &[_][]const u8{ "tmp.zig:10:5: error: enum field not found: 'D'", "tmp.zig:1:16: note: enum declared here", - ); + }); - cases.add( - "field type supplied in an enum", + cases.add("field type supplied in an enum", \\const Letter = enum { \\ A: void, \\ B, @@ -6574,37 +6036,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ var b = Letter.B; \\} - , + , &[_][]const u8{ "tmp.zig:2:8: error: structs and unions, not enums, support field types", "tmp.zig:1:16: note: consider 'union(enum)' here", - ); + }); - cases.add( - "struct field missing type", + cases.add("struct field missing type", \\const Letter = struct { \\ A, \\}; \\export fn entry() void { \\ var a = Letter { .A = {} }; \\} - , + , &[_][]const u8{ "tmp.zig:2:5: error: struct field missing type", - ); + }); - cases.add( - "extern union field missing type", + cases.add("extern union field missing type", \\const Letter = extern union { \\ A, \\}; \\export fn entry() void { \\ var a = Letter { .A = {} }; \\} - , + , &[_][]const u8{ "tmp.zig:2:5: error: union field missing type", - ); + }); - cases.add( - "extern union given enum tag type", + cases.add("extern union given enum tag type", \\const Letter = enum { \\ A, \\ B, @@ -6618,12 +6077,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ var a = Payload { .A = 1234 }; \\} - , + , &[_][]const u8{ "tmp.zig:6:30: error: extern union does not support enum tag type", - ); + }); - cases.add( - "packed union given enum tag type", + cases.add("packed union given enum tag type", \\const Letter = enum { \\ A, \\ B, @@ -6637,12 +6095,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ var a = Payload { .A = 1234 }; \\} - , + , &[_][]const u8{ "tmp.zig:6:30: error: packed union does not support enum tag type", - ); + }); - cases.add( - "packed union with automatic layout field", + cases.add("packed union with automatic layout field", \\const Foo = struct { \\ a: u32, \\ b: f32, @@ -6654,12 +6111,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ var a = Payload { .B = true }; \\} - , + , &[_][]const u8{ "tmp.zig:6:5: error: non-packed, non-extern struct 'Foo' not allowed in packed union; no guaranteed in-memory representation", - ); + }); - cases.add( - "switch on union with no attached enum", + cases.add("switch on union with no attached enum", \\const Payload = union { \\ A: i32, \\ B: f64, @@ -6675,13 +6131,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ else => unreachable, \\ } \\} - , + , &[_][]const u8{ "tmp.zig:11:14: error: switch on union which has no attached enum", "tmp.zig:1:17: note: consider 'union(enum)' here", - ); + }); - cases.add( - "enum in field count range but not matching tag", + cases.add("enum in field count range but not matching tag", \\const Foo = enum(u32) { \\ A = 10, \\ B = 11, @@ -6689,13 +6144,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ var x = @intToEnum(Foo, 0); \\} - , + , &[_][]const u8{ "tmp.zig:6:13: error: enum 'Foo' has no tag matching integer value 0", "tmp.zig:1:13: note: 'Foo' declared here", - ); + }); - cases.add( - "comptime cast enum to union but field has payload", + cases.add("comptime cast enum to union but field has payload", \\const Letter = enum { A, B, C }; \\const Value = union(Letter) { \\ A: i32, @@ -6705,13 +6159,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\export fn entry() void { \\ var x: Value = Letter.A; \\} - , + , &[_][]const u8{ "tmp.zig:8:26: error: cast to union 'Value' must initialize 'i32' field 'A'", "tmp.zig:3:5: note: field 'A' declared here", - ); + }); - cases.add( - "runtime cast to union which has non-void fields", + cases.add("runtime cast to union which has non-void fields", \\const Letter = enum { A, B, C }; \\const Value = union(Letter) { \\ A: i32, @@ -6724,37 +6177,34 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\fn foo(l: Letter) void { \\ var x: Value = l; \\} - , + , &[_][]const u8{ "tmp.zig:11:20: error: runtime cast to union 'Value' which has non-void fields", "tmp.zig:3:5: note: field 'A' has type 'i32'", - ); + }); - cases.add( - "taking byte offset of void field in struct", + cases.add("taking byte offset of void field in struct", \\const Empty = struct { \\ val: void, \\}; \\export fn foo() void { \\ const fieldOffset = @byteOffsetOf(Empty, "val",); \\} - , + , &[_][]const u8{ "tmp.zig:5:46: error: zero-bit field 'val' in struct 'Empty' has no offset", - ); + }); - cases.add( - "taking bit offset of void field in struct", + cases.add("taking bit offset of void field in struct", \\const Empty = struct { \\ val: void, \\}; \\export fn foo() void { \\ const fieldOffset = @bitOffsetOf(Empty, "val",); \\} - , + , &[_][]const u8{ "tmp.zig:5:45: error: zero-bit field 'val' in struct 'Empty' has no offset", - ); + }); - cases.add( - "invalid union field access in comptime", + cases.add("invalid union field access in comptime", \\const Foo = union { \\ Bar: u8, \\ Baz: void, @@ -6763,60 +6213,54 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var foo = Foo {.Baz = {}}; \\ const bar_val = foo.Bar; \\} - , + , &[_][]const u8{ "tmp.zig:7:24: error: accessing union field 'Bar' while field 'Baz' is set", - ); + }); - cases.add( - "getting return type of generic function", + cases.add("getting return type of generic function", \\fn generic(a: var) void {} \\comptime { \\ _ = @typeOf(generic).ReturnType; \\} - , + , &[_][]const u8{ "tmp.zig:3:25: error: ReturnType has not been resolved because 'fn(var)var' is generic", - ); + }); - cases.add( - "getting @ArgType of generic function", + cases.add("getting @ArgType of generic function", \\fn generic(a: var) void {} \\comptime { \\ _ = @ArgType(@typeOf(generic), 0); \\} - , + , &[_][]const u8{ "tmp.zig:3:36: error: @ArgType could not resolve the type of arg 0 because 'fn(var)var' is generic", - ); + }); - cases.add( - "unsupported modifier at start of asm output constraint", + cases.add("unsupported modifier at start of asm output constraint", \\export fn foo() void { \\ var bar: u32 = 3; \\ asm volatile ("" : [baz]"+r"(bar) : : ""); \\} - , + , &[_][]const u8{ "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", - ); + }); - cases.add( - "comptime_int in asm input", + cases.add("comptime_int in asm input", \\export fn foo() void { \\ asm volatile ("" : : [bar]"r"(3) : ""); \\} - , + , &[_][]const u8{ "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_int", - ); + }); - cases.add( - "comptime_float in asm input", + cases.add("comptime_float in asm input", \\export fn foo() void { \\ asm volatile ("" : : [bar]"r"(3.17) : ""); \\} - , + , &[_][]const u8{ "tmp.zig:2:35: error: expected sized integer or sized float, found comptime_float", - ); + }); - cases.add( - "runtime assignment to comptime struct type", + cases.add("runtime assignment to comptime struct type", \\const Foo = struct { \\ Bar: u8, \\ Baz: type, @@ -6825,12 +6269,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var x: u8 = 0; \\ const foo = Foo { .Bar = x, .Baz = u8 }; \\} - , + , &[_][]const u8{ "tmp.zig:7:23: error: unable to evaluate constant expression", - ); + }); - cases.add( - "runtime assignment to comptime union type", + cases.add("runtime assignment to comptime union type", \\const Foo = union { \\ Bar: u8, \\ Baz: type, @@ -6839,42 +6282,39 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var x: u8 = 0; \\ const foo = Foo { .Bar = x }; \\} - , + , &[_][]const u8{ "tmp.zig:7:23: error: unable to evaluate constant expression", - ); + }); - cases.addTest( - "@shuffle with selected index past first vector length", + cases.addTest("@shuffle with selected index past first vector length", \\export fn entry() void { \\ const v: @Vector(4, u32) = [4]u32{ 10, 11, 12, 13 }; \\ const x: @Vector(4, u32) = [4]u32{ 14, 15, 16, 17 }; \\ var z = @shuffle(u32, v, x, [8]i32{ 0, 1, 2, 3, 7, 6, 5, 4 }); \\} - , + , &[_][]const u8{ "tmp.zig:4:39: error: mask index '4' has out-of-bounds selection", "tmp.zig:4:27: note: selected index '7' out of bounds of @Vector(4, u32)", "tmp.zig:4:30: note: selections from the second vector are specified with negative numbers", - ); + }); - cases.addTest( - "nested vectors", + cases.addTest("nested vectors", \\export fn entry() void { \\ const V = @Vector(4, @Vector(4, u8)); \\ var v: V = undefined; \\} - , + , &[_][]const u8{ "tmp.zig:2:26: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid", - ); + }); - cases.addTest( - "bad @splat type", + cases.addTest("bad @splat type", \\export fn entry() void { \\ const c = 4; \\ var v = @splat(4, c); \\} - , + , &[_][]const u8{ "tmp.zig:3:23: error: vector element type must be integer, float, bool, or pointer; 'comptime_int' is invalid", - ); + }); cases.add("compileLog of tagged enum doesn't crash the compiler", \\const Bar = union(enum(u32)) { @@ -6888,33 +6328,32 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\pub fn main () void { \\ comptime testCompileLog(Bar{.X = 123}); \\} - , "tmp.zig:6:5: error: found compile log statement"); + , &[_][]const u8{ + "tmp.zig:6:5: error: found compile log statement", + }); - cases.add( - "attempted implicit cast from *const T to *[1]T", + cases.add("attempted implicit cast from *const T to *[1]T", \\export fn entry(byte: u8) void { \\ const w: i32 = 1234; \\ var x: *const i32 = &w; \\ var y: *[1]i32 = x; \\ y[0] += 1; \\} - , + , &[_][]const u8{ "tmp.zig:4:22: error: expected type '*[1]i32', found '*const i32'", "tmp.zig:4:22: note: cast discards const qualifier", - ); + }); - cases.add( - "attempted implicit cast from *const T to []T", + cases.add("attempted implicit cast from *const T to []T", \\export fn entry() void { \\ const u: u32 = 42; \\ const x: []u32 = &u; \\} - , + , &[_][]const u8{ "tmp.zig:3:23: error: expected type '[]u32', found '*const u32'", - ); + }); - cases.add( - "for loop body expression ignored", + cases.add("for loop body expression ignored", \\fn returns() usize { \\ return 2; \\} @@ -6925,37 +6364,35 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { \\ var x: anyerror!i32 = error.Bad; \\ for ("hello") |_| returns() else unreachable; \\} - , + , &[_][]const u8{ "tmp.zig:5:30: error: expression value is ignored", "tmp.zig:9:30: error: expression value is ignored", - ); + }); - cases.add( - "aligned variable of zero-bit type", + cases.add("aligned variable of zero-bit type", \\export fn f() void { \\ var s: struct {} align(4) = undefined; \\} - , + , &[_][]const u8{ "tmp.zig:2:5: error: variable 's' of zero-bit type 'struct:2:12' has no in-memory representation, it cannot be aligned", - ); + }); - cases.add( - "function returning opaque type", + cases.add("function returning opaque type", \\const FooType = @OpaqueType(); \\export fn bar() !FooType { \\ return error.InvalidValue; \\} - , + , &[_][]const u8{ "tmp.zig:2:18: error: opaque return type 'FooType' not allowed", "tmp.zig:1:1: note: declared here", - ); + }); cases.add( // fixed bug #2032 "compile diagnostic string for top level decl type", \\export fn entry() void { \\ var foo: u32 = @This(){}; \\} - , + , &[_][]const u8{ "tmp.zig:2:27: error: type 'u32' does not support array initialization", - ); + }); } diff --git a/test/gen_h.zig b/test/gen_h.zig index 93ccb21a64..f519d8feb6 100644 --- a/test/gen_h.zig +++ b/test/gen_h.zig @@ -4,7 +4,7 @@ pub fn addCases(cases: *tests.GenHContext) void { cases.add("declare enum", \\const Foo = extern enum { A, B, C }; \\export fn entry(foo: Foo) void { } - , + , &[_][]const u8{ \\enum Foo { \\ A = 0, \\ B = 1, @@ -12,7 +12,7 @@ pub fn addCases(cases: *tests.GenHContext) void { \\}; , \\void entry(enum Foo foo); - ); + }); cases.add("declare struct", \\const Foo = extern struct { @@ -24,7 +24,7 @@ pub fn addCases(cases: *tests.GenHContext) void { \\ F: u64, \\}; \\export fn entry(foo: Foo) void { } - , + , &[_][]const u8{ \\struct Foo { \\ int32_t A; \\ float B; @@ -36,7 +36,7 @@ pub fn addCases(cases: *tests.GenHContext) void { , \\void entry(struct Foo foo); \\ - ); + }); cases.add("declare union", \\const Big = extern struct { @@ -53,7 +53,7 @@ pub fn addCases(cases: *tests.GenHContext) void { \\ D: Big, \\}; \\export fn entry(foo: Foo) void {} - , + , &[_][]const u8{ \\struct Big { \\ uint64_t A; \\ uint64_t B; @@ -71,17 +71,17 @@ pub fn addCases(cases: *tests.GenHContext) void { , \\void entry(union Foo foo); \\ - ); + }); cases.add("declare opaque type", \\const Foo = @OpaqueType(); \\ \\export fn entry(foo: ?*Foo) void { } - , + , &[_][]const u8{ \\struct Foo; , \\void entry(struct Foo * foo); - ); + }); cases.add("array field-type", \\const Foo = extern struct { @@ -89,7 +89,7 @@ pub fn addCases(cases: *tests.GenHContext) void { \\ B: [4]*u32, \\}; \\export fn entry(foo: Foo, bar: [3]u8) void { } - , + , &[_][]const u8{ \\struct Foo { \\ int32_t A[2]; \\ uint32_t * B[4]; @@ -97,7 +97,7 @@ pub fn addCases(cases: *tests.GenHContext) void { , \\void entry(struct Foo foo, uint8_t bar[]); \\ - ); + }); cases.add("ptr to zig struct", \\const S = struct { @@ -107,12 +107,12 @@ pub fn addCases(cases: *tests.GenHContext) void { \\export fn a(s: *S) u8 { \\ return s.a; \\} - , + , &[_][]const u8{ \\struct S; , \\uint8_t a(struct S * s); \\ - ); + }); cases.add("ptr to zig union", \\const U = union(enum) { @@ -123,12 +123,12 @@ pub fn addCases(cases: *tests.GenHContext) void { \\export fn a(s: *U) u8 { \\ return s.A; \\} - , + , &[_][]const u8{ \\union U; , \\uint8_t a(union U * s); \\ - ); + }); cases.add("ptr to zig enum", \\const E = enum(u8) { @@ -139,10 +139,10 @@ pub fn addCases(cases: *tests.GenHContext) void { \\export fn a(s: *E) u8 { \\ return @enumToInt(s.*); \\} - , + , &[_][]const u8{ \\enum E; , \\uint8_t a(enum E * s); \\ - ); + }); } diff --git a/test/stage1/behavior/eval.zig b/test/stage1/behavior/eval.zig index be7226d94c..44ad2f81fa 100644 --- a/test/stage1/behavior/eval.zig +++ b/test/stage1/behavior/eval.zig @@ -670,10 +670,10 @@ fn loopNTimes(comptime n: usize) void { } test "variable inside inline loop that has different types on different iterations" { - testVarInsideInlineLoop(true, @as(u32, 42)); + testVarInsideInlineLoop(.{true, @as(u32, 42)}); } -fn testVarInsideInlineLoop(args: ...) void { +fn testVarInsideInlineLoop(args: var) void { comptime var i = 0; inline while (i < args.len) : (i += 1) { const x = args[i]; diff --git a/test/stage1/behavior/reflection.zig b/test/stage1/behavior/reflection.zig index 739e0b318a..12067ee51d 100644 --- a/test/stage1/behavior/reflection.zig +++ b/test/stage1/behavior/reflection.zig @@ -15,7 +15,6 @@ test "reflection: function return type, var args, and param types" { comptime { expect(@typeOf(dummy).ReturnType == i32); expect(!@typeOf(dummy).is_var_args); - expect(@typeOf(dummy_varargs).is_var_args); expect(@typeOf(dummy).arg_count == 3); expect(@ArgType(@typeOf(dummy), 0) == bool); expect(@ArgType(@typeOf(dummy), 1) == i32); @@ -26,7 +25,6 @@ test "reflection: function return type, var args, and param types" { fn dummy(a: bool, b: i32, c: f32) i32 { return 1234; } -fn dummy_varargs(args: ...) void {} test "reflection: struct member types and names" { comptime { diff --git a/test/stage1/behavior/type_info.zig b/test/stage1/behavior/type_info.zig index 598bbca6be..a0fd4a4e6c 100644 --- a/test/stage1/behavior/type_info.zig +++ b/test/stage1/behavior/type_info.zig @@ -198,7 +198,7 @@ fn testUnion() void { expect(@as(TypeId, typeinfo_info) == TypeId.Union); expect(typeinfo_info.Union.layout == TypeInfo.ContainerLayout.Auto); expect(typeinfo_info.Union.tag_type.? == TypeId); - expect(typeinfo_info.Union.fields.len == 26); + expect(typeinfo_info.Union.fields.len == 25); expect(typeinfo_info.Union.fields[4].enum_field != null); expect(typeinfo_info.Union.fields[4].enum_field.?.value == 4); expect(typeinfo_info.Union.fields[4].field_type == @typeOf(@typeInfo(u8).Int)); diff --git a/test/stage1/behavior/var_args.zig b/test/stage1/behavior/var_args.zig index 19df436481..0c8674a7fb 100644 --- a/test/stage1/behavior/var_args.zig +++ b/test/stage1/behavior/var_args.zig @@ -1,6 +1,6 @@ const expect = @import("std").testing.expect; -fn add(args: ...) i32 { +fn add(args: var) i32 { var sum = @as(i32, 0); { comptime var i: usize = 0; @@ -12,43 +12,42 @@ fn add(args: ...) i32 { } test "add arbitrary args" { - expect(add(@as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4)) == 10); - expect(add(@as(i32, 1234)) == 1234); - expect(add() == 0); + expect(add(.{ @as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4) }) == 10); + expect(add(.{@as(i32, 1234)}) == 1234); + expect(add(.{}) == 0); } -fn readFirstVarArg(args: ...) void { +fn readFirstVarArg(args: var) void { const value = args[0]; } test "send void arg to var args" { - readFirstVarArg({}); + readFirstVarArg(.{{}}); } test "pass args directly" { - expect(addSomeStuff(@as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4)) == 10); - expect(addSomeStuff(@as(i32, 1234)) == 1234); - expect(addSomeStuff() == 0); + expect(addSomeStuff(.{ @as(i32, 1), @as(i32, 2), @as(i32, 3), @as(i32, 4) }) == 10); + expect(addSomeStuff(.{@as(i32, 1234)}) == 1234); + expect(addSomeStuff(.{}) == 0); } -fn addSomeStuff(args: ...) i32 { +fn addSomeStuff(args: var) i32 { return add(args); } test "runtime parameter before var args" { - expect(extraFn(10) == 0); - expect(extraFn(10, false) == 1); - expect(extraFn(10, false, true) == 2); + expect(extraFn(10, .{}) == 0); + expect(extraFn(10, .{false}) == 1); + expect(extraFn(10, .{ false, true }) == 2); - // TODO issue #313 - //comptime { - // expect(extraFn(10) == 0); - // expect(extraFn(10, false) == 1); - // expect(extraFn(10, false, true) == 2); - //} + comptime { + expect(extraFn(10, .{}) == 0); + expect(extraFn(10, .{false}) == 1); + expect(extraFn(10, .{ false, true }) == 2); + } } -fn extraFn(extra: u32, args: ...) usize { +fn extraFn(extra: u32, args: var) usize { if (args.len >= 1) { expect(args[0] == false); } @@ -58,27 +57,27 @@ fn extraFn(extra: u32, args: ...) usize { return args.len; } -const foos = [_]fn (...) bool{ +const foos = [_]fn (var) bool{ foo1, foo2, }; -fn foo1(args: ...) bool { +fn foo1(args: var) bool { return true; } -fn foo2(args: ...) bool { +fn foo2(args: var) bool { return false; } test "array of var args functions" { - expect(foos[0]()); - expect(!foos[1]()); + expect(foos[0](.{})); + expect(!foos[1](.{})); } test "pass zero length array to var args param" { - doNothingWithFirstArg(""); + doNothingWithFirstArg(.{""}); } -fn doNothingWithFirstArg(args: ...) void { +fn doNothingWithFirstArg(args: var) void { const a = args[0]; } diff --git a/test/tests.zig b/test/tests.zig index 7548be6c4b..7326b62054 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -1253,7 +1253,12 @@ pub const CompileErrorContext = struct { } }; - pub fn create(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) *TestCase { + pub fn create( + self: *CompileErrorContext, + name: []const u8, + source: []const u8, + expected_lines: []const []const u8, + ) *TestCase { const tc = self.b.allocator.create(TestCase) catch unreachable; tc.* = TestCase{ .name = name, @@ -1266,31 +1271,46 @@ pub const CompileErrorContext = struct { }; tc.addSourceFile("tmp.zig", source); - comptime var arg_i = 0; - inline while (arg_i < expected_lines.len) : (arg_i += 1) { + var arg_i: usize = 0; + while (arg_i < expected_lines.len) : (arg_i += 1) { tc.addExpectedError(expected_lines[arg_i]); } return tc; } - pub fn addC(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void { + pub fn addC(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: []const []const u8) void { var tc = self.create(name, source, expected_lines); tc.link_libc = true; self.addCase(tc); } - pub fn addExe(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void { + pub fn addExe( + self: *CompileErrorContext, + name: []const u8, + source: []const u8, + expected_lines: []const []const u8, + ) void { var tc = self.create(name, source, expected_lines); tc.is_exe = true; self.addCase(tc); } - pub fn add(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void { + pub fn add( + self: *CompileErrorContext, + name: []const u8, + source: []const u8, + expected_lines: []const []const u8, + ) void { const tc = self.create(name, source, expected_lines); self.addCase(tc); } - pub fn addTest(self: *CompileErrorContext, name: []const u8, source: []const u8, expected_lines: ...) void { + pub fn addTest( + self: *CompileErrorContext, + name: []const u8, + source: []const u8, + expected_lines: []const []const u8, + ) void { const tc = self.create(name, source, expected_lines); tc.is_test = true; self.addCase(tc); @@ -1549,7 +1569,14 @@ pub const TranslateCContext = struct { warn("\n", .{}); } - pub fn create(self: *TranslateCContext, allow_warnings: bool, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase { + pub fn create( + self: *TranslateCContext, + allow_warnings: bool, + filename: []const u8, + name: []const u8, + source: []const u8, + expected_lines: []const []const u8, + ) *TestCase { const tc = self.b.allocator.create(TestCase) catch unreachable; tc.* = TestCase{ .name = name, @@ -1560,24 +1587,39 @@ pub const TranslateCContext = struct { }; tc.addSourceFile(filename, source); - comptime var arg_i = 0; - inline while (arg_i < expected_lines.len) : (arg_i += 1) { + var arg_i: usize = 0; + while (arg_i < expected_lines.len) : (arg_i += 1) { tc.addExpectedLine(expected_lines[arg_i]); } return tc; } - pub fn add(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void { + pub fn add( + self: *TranslateCContext, + name: []const u8, + source: []const u8, + expected_lines: []const []const u8, + ) void { const tc = self.create(false, "source.h", name, source, expected_lines); self.addCase(tc); } - pub fn addC(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void { + pub fn addC( + self: *TranslateCContext, + name: []const u8, + source: []const u8, + expected_lines: []const []const u8, + ) void { const tc = self.create(false, "source.c", name, source, expected_lines); self.addCase(tc); } - pub fn add_both(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void { + pub fn add_both( + self: *TranslateCContext, + name: []const u8, + source: []const u8, + expected_lines: []const []const u8, + ) void { for ([_]bool{ false, true }) |stage2| { const tc = self.create(false, "source.h", name, source, expected_lines); tc.stage2 = stage2; @@ -1585,7 +1627,12 @@ pub const TranslateCContext = struct { } } - pub fn addC_both(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void { + pub fn addC_both( + self: *TranslateCContext, + name: []const u8, + source: []const u8, + expected_lines: []const []const u8, + ) void { for ([_]bool{ false, true }) |stage2| { const tc = self.create(false, "source.c", name, source, expected_lines); tc.stage2 = stage2; @@ -1593,19 +1640,34 @@ pub const TranslateCContext = struct { } } - pub fn add_2(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void { + pub fn add_2( + self: *TranslateCContext, + name: []const u8, + source: []const u8, + expected_lines: []const []const u8, + ) void { const tc = self.create(false, "source.h", name, source, expected_lines); tc.stage2 = true; self.addCase(tc); } - pub fn addC_2(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void { + pub fn addC_2( + self: *TranslateCContext, + name: []const u8, + source: []const u8, + expected_lines: []const []const u8, + ) void { const tc = self.create(false, "source.c", name, source, expected_lines); tc.stage2 = true; self.addCase(tc); } - pub fn addAllowWarnings(self: *TranslateCContext, name: []const u8, source: []const u8, expected_lines: ...) void { + pub fn addAllowWarnings( + self: *TranslateCContext, + name: []const u8, + source: []const u8, + expected_lines: []const []const u8, + ) void { const tc = self.create(true, "source.h", name, source, expected_lines); self.addCase(tc); } @@ -1723,7 +1785,13 @@ pub const GenHContext = struct { warn("\n", .{}); } - pub fn create(self: *GenHContext, filename: []const u8, name: []const u8, source: []const u8, expected_lines: ...) *TestCase { + pub fn create( + self: *GenHContext, + filename: []const u8, + name: []const u8, + source: []const u8, + expected_lines: []const []const u8, + ) *TestCase { const tc = self.b.allocator.create(TestCase) catch unreachable; tc.* = TestCase{ .name = name, @@ -1732,14 +1800,14 @@ pub const GenHContext = struct { }; tc.addSourceFile(filename, source); - comptime var arg_i = 0; - inline while (arg_i < expected_lines.len) : (arg_i += 1) { + var arg_i: usize = 0; + while (arg_i < expected_lines.len) : (arg_i += 1) { tc.addExpectedLine(expected_lines[arg_i]); } return tc; } - pub fn add(self: *GenHContext, name: []const u8, source: []const u8, expected_lines: ...) void { + pub fn add(self: *GenHContext, name: []const u8, source: []const u8, expected_lines: []const []const u8) void { const tc = self.create("test.zig", name, source, expected_lines); self.addCase(tc); } diff --git a/test/translate_c.zig b/test/translate_c.zig index f543fbc74e..a2ee07f219 100644 --- a/test/translate_c.zig +++ b/test/translate_c.zig @@ -13,10 +13,10 @@ pub fn addCases(cases: *tests.TranslateCContext) void { cases.add_both("simple function prototypes", \\void __attribute__((noreturn)) foo(void); \\int bar(void); - , + , &[_][]const u8{ \\pub extern fn foo() noreturn; \\pub extern fn bar() c_int; - ); + }); cases.add_both("simple var decls", \\void foo(void) { @@ -25,14 +25,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ const int c; \\ const unsigned d = 440; \\} - , + , &[_][]const u8{ \\pub fn foo() void { \\ var a: c_int = undefined; \\ var b: u8 = @as(u8, 123); \\ const c: c_int = undefined; \\ const d: c_uint = @as(c_uint, 440); \\} - ); + }); cases.add_both("ignore result, explicit function arguments", \\void foo(void) { @@ -43,7 +43,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ 1 - 1; \\ a = 1; \\} - , + , &[_][]const u8{ \\pub fn foo() void { \\ var a: c_int = undefined; \\ _ = 1; @@ -52,7 +52,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ _ = (1 - 1); \\ a = 1; \\} - ); + }); /////////////// Cases that pass for only stage2 //////////////// // TODO: restore these tests after removing "import mode" concept @@ -83,12 +83,12 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\void b(void) {} \\void c(); \\void d(void); - , + , &[_][]const u8{ \\pub fn a(...) void {} \\pub fn b() void {} \\pub extern fn c(...) void; \\pub extern fn d() void; - ); + }); /////////////// Cases for only stage1 which are TODO items for stage2 //////////////// @@ -98,13 +98,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ void (*func)(void); \\ lws_callback_function *callback_http; \\}; - , + , &[_][]const u8{ \\pub const lws_callback_function = extern fn () void; \\pub const struct_Foo = extern struct { \\ func: ?extern fn () void, \\ callback_http: ?lws_callback_function, \\}; - ); + }); cases.add("pointer to struct demoted to opaque due to bit fields", \\struct Foo { @@ -113,26 +113,26 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\struct Bar { \\ struct Foo *foo; \\}; - , + , &[_][]const u8{ \\pub const struct_Foo = @OpaqueType(); \\pub const struct_Bar = extern struct { \\ foo: ?*struct_Foo, \\}; - ); + }); cases.add_both("simple function definition", \\void foo(void) {} \\static void bar(void) {} - , + , &[_][]const u8{ \\pub fn foo() void {} \\pub fn bar() void {} - ); + }); cases.add("macro with left shift", \\#define REDISMODULE_READ (1<<0) - , + , &[_][]const u8{ \\pub const REDISMODULE_READ = 1 << 0; - ); + }); cases.add_both("casting pointers to ints and ints to pointers", \\void foo(void); @@ -140,13 +140,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ void *func_ptr = foo; \\ void (*typed_func_ptr)(void) = (void (*)(void)) (unsigned long) func_ptr; \\} - , + , &[_][]const u8{ \\pub extern fn foo() void; \\pub fn bar() void { \\ var func_ptr: ?*c_void = @ptrCast(?*c_void, foo); \\ var typed_func_ptr: ?extern fn () void = @intToPtr(?extern fn () void, @as(c_ulong, @ptrToInt(func_ptr))); \\} - ); + }); if (builtin.os != builtin.Os.windows) { // Windows treats this as an enum with type c_int @@ -176,7 +176,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ VAL22 = 0xFFFFFFFFFFFFFFFF + 1, \\ VAL23 = 0xFFFFFFFFFFFFFFFF, \\}; - , + , &[_][]const u8{ \\pub const enum_EnumWithInits = extern enum(c_longlong) { \\ VAL01 = 0, \\ VAL02 = 1, @@ -202,7 +202,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ VAL22 = 0, \\ VAL23 = -1, \\}; - ); + }); } cases.add("predefined expressions", @@ -211,13 +211,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ __FUNCTION__; \\ __PRETTY_FUNCTION__; \\} - , + , &[_][]const u8{ \\pub fn foo() void { \\ _ = "foo"; \\ _ = "foo"; \\ _ = "void foo(void)"; \\} - ); + }); cases.add("ignore result, no function arguments", \\void foo() { @@ -228,7 +228,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ 1 - 1; \\ a = 1; \\} - , + , &[_][]const u8{ \\pub fn foo() void { \\ var a: c_int = undefined; \\ _ = 1; @@ -237,53 +237,53 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ _ = (1 - 1); \\ a = 1; \\} - ); + }); cases.add("for loop with var init but empty body", \\void foo(void) { \\ for (int x = 0; x < 10; x++); \\} - , + , &[_][]const u8{ \\pub fn foo() void { \\ { \\ var x: c_int = 0; \\ while (x < 10) : (x += 1) {} \\ } \\} - ); + }); cases.add("do while with empty body", \\void foo(void) { \\ do ; while (1); \\} - , // TODO this should be if (1 != 0) break + , &[_][]const u8{ // TODO this should be if (1 != 0) break \\pub fn foo() void { \\ while (true) { \\ {} \\ if (!1) break; \\ } \\} - ); + }); cases.add("for with empty body", \\void foo(void) { \\ for (;;); \\} - , + , &[_][]const u8{ \\pub fn foo() void { \\ while (true) {} \\} - ); + }); cases.add("while with empty body", \\void foo(void) { \\ while (1); \\} - , + , &[_][]const u8{ \\pub fn foo() void { \\ while (1 != 0) {} \\} - ); + }); cases.add("double define struct", \\typedef struct Bar Bar; @@ -296,7 +296,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\struct Bar { \\ Foo *a; \\}; - , + , &[_][]const u8{ \\pub const struct_Foo = extern struct { \\ a: [*c]Foo, \\}; @@ -304,7 +304,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub const struct_Bar = extern struct { \\ a: [*c]Foo, \\}; - ); + }); cases.addAllowWarnings("simple data types", \\#include @@ -312,29 +312,29 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\int foo(char a, unsigned char b, signed char c); // test a duplicate prototype \\void bar(uint8_t a, uint16_t b, uint32_t c, uint64_t d); \\void baz(int8_t a, int16_t b, int32_t c, int64_t d); - , + , &[_][]const u8{ \\pub extern fn foo(a: u8, b: u8, c: i8) c_int; , \\pub extern fn bar(a: u8, b: u16, c: u32, d: u64) void; , \\pub extern fn baz(a: i8, b: i16, c: i32, d: i64) void; - ); + }); cases.add_both("noreturn attribute", \\void foo(void) __attribute__((noreturn)); - , + , &[_][]const u8{ \\pub extern fn foo() noreturn; - ); + }); cases.addC("simple function", \\int abs(int a) { \\ return a < 0 ? -a : a; \\} - , + , &[_][]const u8{ \\export fn abs(a: c_int) c_int { \\ return if (a < 0) -a else a; \\} - ); + }); cases.add("enums", \\enum Foo { @@ -342,7 +342,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ FooB, \\ Foo1, \\}; - , + , &[_][]const u8{ \\pub const enum_Foo = extern enum { \\ A, \\ B, @@ -356,7 +356,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub const Foo1 = enum_Foo.@"1"; , \\pub const Foo = enum_Foo; - ); + }); cases.add("enums", \\enum Foo { @@ -364,7 +364,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ FooB = 5, \\ Foo1, \\}; - , + , &[_][]const u8{ \\pub const enum_Foo = extern enum { \\ A = 2, \\ B = 5, @@ -378,27 +378,27 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub const Foo1 = enum_Foo.@"1"; , \\pub const Foo = enum_Foo; - ); + }); cases.add("restrict -> noalias", \\void foo(void *restrict bar, void *restrict); - , + , &[_][]const u8{ \\pub extern fn foo(noalias bar: ?*c_void, noalias arg1: ?*c_void) void; - ); + }); cases.add("simple struct", \\struct Foo { \\ int x; \\ char *y; \\}; - , + , &[_][]const u8{ \\const struct_Foo = extern struct { \\ x: c_int, \\ y: [*c]u8, \\}; , \\pub const Foo = struct_Foo; - ); + }); cases.add("qualified struct and enum", \\struct Foo { @@ -410,7 +410,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ BarB, \\}; \\void func(struct Foo *a, enum Bar **b); - , + , &[_][]const u8{ \\pub const struct_Foo = extern struct { \\ x: c_int, \\ y: c_int, @@ -430,66 +430,66 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub const Foo = struct_Foo; , \\pub const Bar = enum_Bar; - ); + }); cases.add("constant size array", \\void func(int array[20]); - , + , &[_][]const u8{ \\pub extern fn func(array: [*c]c_int) void; - ); + }); cases.add("self referential struct with function pointer", \\struct Foo { \\ void (*derp)(struct Foo *foo); \\}; - , + , &[_][]const u8{ \\pub const struct_Foo = extern struct { \\ derp: ?extern fn ([*c]struct_Foo) void, \\}; , \\pub const Foo = struct_Foo; - ); + }); cases.add("struct prototype used in func", \\struct Foo; \\struct Foo *some_func(struct Foo *foo, int x); - , + , &[_][]const u8{ \\pub const struct_Foo = @OpaqueType(); , \\pub extern fn some_func(foo: ?*struct_Foo, x: c_int) ?*struct_Foo; , \\pub const Foo = struct_Foo; - ); + }); cases.add("#define a char literal", \\#define A_CHAR 'a' - , + , &[_][]const u8{ \\pub const A_CHAR = 97; - ); + }); cases.add("#define an unsigned integer literal", \\#define CHANNEL_COUNT 24 - , + , &[_][]const u8{ \\pub const CHANNEL_COUNT = 24; - ); + }); cases.add("#define referencing another #define", \\#define THING2 THING1 \\#define THING1 1234 - , + , &[_][]const u8{ \\pub const THING1 = 1234; , \\pub const THING2 = THING1; - ); + }); cases.add("variables", \\extern int extern_var; \\static const int int_var = 13; - , + , &[_][]const u8{ \\pub extern var extern_var: c_int; , \\pub const int_var: c_int = 13; - ); + }); cases.add("circular struct definitions", \\struct Bar; @@ -501,7 +501,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\struct Bar { \\ struct Foo *next; \\}; - , + , &[_][]const u8{ \\pub const struct_Bar = extern struct { \\ next: [*c]struct_Foo, \\}; @@ -509,16 +509,16 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub const struct_Foo = extern struct { \\ next: [*c]struct_Bar, \\}; - ); + }); cases.add("typedef void", \\typedef void Foo; \\Foo fun(Foo *a); - , + , &[_][]const u8{ \\pub const Foo = c_void; , \\pub extern fn fun(a: ?*Foo) Foo; - ); + }); cases.add("generate inline func for #define global extern fn", \\extern void (*fn_ptr)(void); @@ -526,7 +526,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ \\extern char (*fn_ptr2)(int, float); \\#define bar fn_ptr2 - , + , &[_][]const u8{ \\pub extern var fn_ptr: ?extern fn () void; , \\pub inline fn foo() void { @@ -538,109 +538,109 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\pub inline fn bar(arg0: c_int, arg1: f32) u8 { \\ return fn_ptr2.?(arg0, arg1); \\} - ); + }); cases.add("#define string", \\#define foo "a string" - , + , &[_][]const u8{ \\pub const foo = "a string"; - ); + }); cases.add("__cdecl doesn't mess up function pointers", \\void foo(void (__cdecl *fn_ptr)(void)); - , + , &[_][]const u8{ \\pub extern fn foo(fn_ptr: ?extern fn () void) void; - ); + }); cases.add("comment after integer literal", \\#define SDL_INIT_VIDEO 0x00000020 /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ - , + , &[_][]const u8{ \\pub const SDL_INIT_VIDEO = 32; - ); + }); cases.add("u integer suffix after hex literal", \\#define SDL_INIT_VIDEO 0x00000020u /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ - , + , &[_][]const u8{ \\pub const SDL_INIT_VIDEO = @as(c_uint, 32); - ); + }); cases.add("l integer suffix after hex literal", \\#define SDL_INIT_VIDEO 0x00000020l /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ - , + , &[_][]const u8{ \\pub const SDL_INIT_VIDEO = @as(c_long, 32); - ); + }); cases.add("ul integer suffix after hex literal", \\#define SDL_INIT_VIDEO 0x00000020ul /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ - , + , &[_][]const u8{ \\pub const SDL_INIT_VIDEO = @as(c_ulong, 32); - ); + }); cases.add("lu integer suffix after hex literal", \\#define SDL_INIT_VIDEO 0x00000020lu /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ - , + , &[_][]const u8{ \\pub const SDL_INIT_VIDEO = @as(c_ulong, 32); - ); + }); cases.add("ll integer suffix after hex literal", \\#define SDL_INIT_VIDEO 0x00000020ll /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ - , + , &[_][]const u8{ \\pub const SDL_INIT_VIDEO = @as(c_longlong, 32); - ); + }); cases.add("ull integer suffix after hex literal", \\#define SDL_INIT_VIDEO 0x00000020ull /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ - , + , &[_][]const u8{ \\pub const SDL_INIT_VIDEO = @as(c_ulonglong, 32); - ); + }); cases.add("llu integer suffix after hex literal", \\#define SDL_INIT_VIDEO 0x00000020llu /**< SDL_INIT_VIDEO implies SDL_INIT_EVENTS */ - , + , &[_][]const u8{ \\pub const SDL_INIT_VIDEO = @as(c_ulonglong, 32); - ); + }); cases.add("zig keywords in C code", \\struct comptime { \\ int defer; \\}; - , + , &[_][]const u8{ \\pub const struct_comptime = extern struct { \\ @"defer": c_int, \\}; , \\pub const @"comptime" = struct_comptime; - ); + }); cases.add("macro defines string literal with hex", \\#define FOO "aoeu\xab derp" \\#define FOO2 "aoeu\x0007a derp" \\#define FOO_CHAR '\xfF' - , + , &[_][]const u8{ \\pub const FOO = "aoeu\xab derp"; , \\pub const FOO2 = "aoeuz derp"; , \\pub const FOO_CHAR = 255; - ); + }); cases.add("macro defines string literal with octal", \\#define FOO "aoeu\023 derp" \\#define FOO2 "aoeu\0234 derp" \\#define FOO_CHAR '\077' - , + , &[_][]const u8{ \\pub const FOO = "aoeu\x13 derp"; , \\pub const FOO2 = "aoeu\x134 derp"; , \\pub const FOO_CHAR = 63; - ); + }); cases.add("macro with parens around negative number", \\#define LUA_GLOBALSINDEX (-10002) - , + , &[_][]const u8{ \\pub const LUA_GLOBALSINDEX = -10002; - ); + }); cases.addC("post increment", \\unsigned foo1(unsigned a) { @@ -651,7 +651,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ a++; \\ return a; \\} - , + , &[_][]const u8{ \\pub export fn foo1(_arg_a: c_uint) c_uint { \\ var a = _arg_a; \\ a +%= 1; @@ -662,7 +662,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ a += 1; \\ return a; \\} - ); + }); cases.addC("shift right assign", \\int log2(unsigned a) { @@ -672,7 +672,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ } \\ return i; \\} - , + , &[_][]const u8{ \\pub export fn log2(_arg_a: c_uint) c_int { \\ var a = _arg_a; \\ var i: c_int = 0; @@ -681,7 +681,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ } \\ return i; \\} - ); + }); cases.addC("if statement", \\int max(int a, int b) { @@ -695,13 +695,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ \\ if (a < b) ; else ; \\} - , + , &[_][]const u8{ \\pub export fn max(a: c_int, b: c_int) c_int { \\ if (a < b) return b; \\ if (a < b) return b else return a; \\ if (a < b) {} else {} \\} - ); + }); cases.addC("==, !=", \\int max(int a, int b) { @@ -711,13 +711,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ return b; \\ return a; \\} - , + , &[_][]const u8{ \\pub export fn max(a: c_int, b: c_int) c_int { \\ if (a == b) return a; \\ if (a != b) return b; \\ return a; \\} - ); + }); cases.addC("add, sub, mul, div, rem", \\int s(int a, int b) { @@ -736,7 +736,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ c = a / b; \\ c = a % b; \\} - , + , &[_][]const u8{ \\pub export fn s(a: c_int, b: c_int) c_int { \\ var c: c_int = undefined; \\ c = (a + b); @@ -753,17 +753,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ c = (a / b); \\ c = (a % b); \\} - ); + }); cases.addC("bitwise binary operators", \\int max(int a, int b) { \\ return (a & b) ^ (a | b); \\} - , + , &[_][]const u8{ \\pub export fn max(a: c_int, b: c_int) c_int { \\ return (a & b) ^ (a | b); \\} - ); + }); cases.addC("logical and, logical or", \\int max(int a, int b) { @@ -773,13 +773,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ return a; \\ return a; \\} - , + , &[_][]const u8{ \\pub export fn max(a: c_int, b: c_int) c_int { \\ if ((a < b) or (a == b)) return b; \\ if ((a >= b) and (a == b)) return a; \\ return a; \\} - ); + }); cases.addC("logical and, logical or on none bool values", \\int and_or_none_bool(int a, float b, void *c) { @@ -791,7 +791,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ if (a || c) return 5; \\ return 6; \\} - , + , &[_][]const u8{ \\pub export fn and_or_none_bool(a: c_int, b: f32, c: ?*c_void) c_int { \\ if ((a != 0) and (b != 0)) return 0; \\ if ((b != 0) and (c != null)) return 1; @@ -801,7 +801,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ if ((a != 0) or (c != null)) return 5; \\ return 6; \\} - ); + }); cases.addC("assign", \\int max(int a) { @@ -809,21 +809,21 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ tmp = a; \\ a = tmp; \\} - , + , &[_][]const u8{ \\pub export fn max(_arg_a: c_int) c_int { \\ var a = _arg_a; \\ var tmp: c_int = undefined; \\ tmp = a; \\ a = tmp; \\} - ); + }); cases.addC("chaining assign", \\void max(int a) { \\ int b, c; \\ c = b = a; \\} - , + , &[_][]const u8{ \\pub export fn max(a: c_int) void { \\ var b: c_int = undefined; \\ var c: c_int = undefined; @@ -833,7 +833,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ break :x _tmp; \\ }); \\} - ); + }); cases.addC("shift right assign with a fixed size type", \\#include @@ -844,7 +844,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ } \\ return i; \\} - , + , &[_][]const u8{ \\pub export fn log2(_arg_a: u32) c_int { \\ var a = _arg_a; \\ var i: c_int = 0; @@ -853,17 +853,17 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ } \\ return i; \\} - ); + }); cases.add("anonymous enum", \\enum { \\ One, \\ Two, \\}; - , + , &[_][]const u8{ \\pub const One = 0; \\pub const Two = 1; - ); + }); cases.addC("function call", \\static void bar(void) { } @@ -872,7 +872,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ bar(); \\ baz(); \\} - , + , &[_][]const u8{ \\pub fn bar() void {} \\pub fn baz() c_int { \\ return 0; @@ -881,7 +881,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ bar(); \\ _ = baz(); \\} - ); + }); cases.addC("field access expression", \\struct Foo { @@ -890,20 +890,20 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\int read_field(struct Foo *foo) { \\ return foo->field; \\} - , + , &[_][]const u8{ \\pub const struct_Foo = extern struct { \\ field: c_int, \\}; \\pub export fn read_field(foo: [*c]struct_Foo) c_int { \\ return foo.*.field; \\} - ); + }); cases.addC("null statements", \\void foo(void) { \\ ;;;;; \\} - , + , &[_][]const u8{ \\pub export fn foo() void { \\ {} \\ {} @@ -911,89 +911,89 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ {} \\ {} \\} - ); + }); cases.add("undefined array global", \\int array[100]; - , + , &[_][]const u8{ \\pub var array: [100]c_int = undefined; - ); + }); cases.addC("array access", \\int array[100]; \\int foo(int index) { \\ return array[index]; \\} - , + , &[_][]const u8{ \\pub var array: [100]c_int = undefined; \\pub export fn foo(index: c_int) c_int { \\ return array[index]; \\} - ); + }); cases.addC("c style cast", \\int float_to_int(float a) { \\ return (int)a; \\} - , + , &[_][]const u8{ \\pub export fn float_to_int(a: f32) c_int { \\ return @as(c_int, a); \\} - ); + }); cases.addC("void cast", \\void foo(int a) { \\ (void) a; \\} - , + , &[_][]const u8{ \\pub export fn foo(a: c_int) void { \\ _ = a; \\} - ); + }); cases.addC("implicit cast to void *", \\void *foo(unsigned short *x) { \\ return x; \\} - , + , &[_][]const u8{ \\pub export fn foo(x: [*c]c_ushort) ?*c_void { \\ return @ptrCast(?*c_void, x); \\} - ); + }); cases.addC("sizeof", \\#include \\size_t size_of(void) { \\ return sizeof(int); \\} - , + , &[_][]const u8{ \\pub export fn size_of() usize { \\ return @sizeOf(c_int); \\} - ); + }); cases.addC("null pointer implicit cast", \\int* foo(void) { \\ return 0; \\} - , + , &[_][]const u8{ \\pub export fn foo() [*c]c_int { \\ return null; \\} - ); + }); cases.addC("comma operator", \\int foo(void) { \\ return 1, 2; \\} - , + , &[_][]const u8{ \\pub export fn foo() c_int { \\ return x: { \\ _ = 1; \\ break :x 2; \\ }; \\} - ); + }); cases.addC("statement expression", \\int foo(void) { @@ -1002,34 +1002,34 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ a; \\ }); \\} - , + , &[_][]const u8{ \\pub export fn foo() c_int { \\ return x: { \\ var a: c_int = 1; \\ break :x a; \\ }; \\} - ); + }); cases.addC("__extension__ cast", \\int foo(void) { \\ return __extension__ 1; \\} - , + , &[_][]const u8{ \\pub export fn foo() c_int { \\ return 1; \\} - ); + }); cases.addC("bitshift", \\int foo(void) { \\ return (1 << 2) >> 1; \\} - , + , &[_][]const u8{ \\pub export fn foo() c_int { \\ return (1 << @as(@import("std").math.Log2Int(c_int), 2)) >> @as(@import("std").math.Log2Int(c_int), 1); \\} - ); + }); cases.addC("compound assignment operators", \\void foo(void) { @@ -1043,7 +1043,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ a >>= (a >>= 1); \\ a <<= (a <<= 1); \\} - , + , &[_][]const u8{ \\pub export fn foo() void { \\ var a: c_int = 0; \\ a += (x: { @@ -1087,7 +1087,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ break :x _ref.*; \\ })); \\} - ); + }); cases.addC("compound assignment operators unsigned", \\void foo(void) { @@ -1101,7 +1101,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ a >>= (a >>= 1); \\ a <<= (a <<= 1); \\} - , + , &[_][]const u8{ \\pub export fn foo() void { \\ var a: c_uint = @as(c_uint, 0); \\ a +%= (x: { @@ -1145,18 +1145,18 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ break :x _ref.*; \\ })); \\} - ); + }); cases.addC("duplicate typedef", \\typedef long foo; \\typedef int bar; \\typedef long foo; \\typedef int baz; - , + , &[_][]const u8{ \\pub const foo = c_long; \\pub const bar = c_int; \\pub const baz = c_int; - ); + }); cases.addC("post increment/decrement", \\void foo(void) { @@ -1171,7 +1171,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ u = u++; \\ u = u--; \\} - , + , &[_][]const u8{ \\pub export fn foo() void { \\ var i: c_int = 0; \\ var u: c_uint = @as(c_uint, 0); @@ -1204,7 +1204,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ break :x _tmp; \\ }); \\} - ); + }); cases.addC("pre increment/decrement", \\void foo(void) { @@ -1219,7 +1219,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ u = ++u; \\ u = --u; \\} - , + , &[_][]const u8{ \\pub export fn foo() void { \\ var i: c_int = 0; \\ var u: c_uint = @as(c_uint, 0); @@ -1248,7 +1248,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ break :x _ref.*; \\ }); \\} - ); + }); cases.addC("do loop", \\void foo(void) { @@ -1262,7 +1262,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ b--; \\ while (b != 0); \\} - , + , &[_][]const u8{ \\pub export fn foo() void { \\ var a: c_int = 2; \\ while (true) { @@ -1275,7 +1275,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ if (!(b != 0)) break; \\ } \\} - ); + }); cases.addC("deref function pointer", \\void foo(void) {} @@ -1290,7 +1290,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ (*(b))(); \\ baz(); \\} - , + , &[_][]const u8{ \\pub export fn foo() void {} \\pub export fn baz() c_int { \\ return 0; @@ -1305,31 +1305,31 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ _ = b.?(); \\ _ = baz(); \\} - ); + }); cases.addC("normal deref", \\void foo(int *x) { \\ *x = 1; \\} - , + , &[_][]const u8{ \\pub export fn foo(x: [*c]c_int) void { \\ x.?.* = 1; \\} - ); + }); cases.add("simple union", \\union Foo { \\ int x; \\ double y; \\}; - , + , &[_][]const u8{ \\pub const union_Foo = extern union { \\ x: c_int, \\ y: f64, \\}; , \\pub const Foo = union_Foo; - ); + }); cases.add("address of operator", \\int foo(void) { @@ -1337,56 +1337,56 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ int *ptr = &x; \\ return *ptr; \\} - , + , &[_][]const u8{ \\pub fn foo() c_int { \\ var x: c_int = 1234; \\ var ptr: [*c]c_int = &x; \\ return ptr.?.*; \\} - ); + }); cases.add("string literal", \\const char *foo(void) { \\ return "bar"; \\} - , + , &[_][]const u8{ \\pub fn foo() [*c]const u8 { \\ return "bar"; \\} - ); + }); cases.add("return void", \\void foo(void) { \\ return; \\} - , + , &[_][]const u8{ \\pub fn foo() void { \\ return; \\} - ); + }); cases.add("for loop", \\void foo(void) { \\ for (int i = 0; i < 10; i += 1) { } \\} - , + , &[_][]const u8{ \\pub fn foo() void { \\ { \\ var i: c_int = 0; \\ while (i < 10) : (i += 1) {} \\ } \\} - ); + }); cases.add("empty for loop", \\void foo(void) { \\ for (;;) { } \\} - , + , &[_][]const u8{ \\pub fn foo() void { \\ while (true) {} \\} - ); + }); cases.add("break statement", \\void foo(void) { @@ -1394,13 +1394,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ break; \\ } \\} - , + , &[_][]const u8{ \\pub fn foo() void { \\ while (true) { \\ break; \\ } \\} - ); + }); cases.add("continue statement", \\void foo(void) { @@ -1408,13 +1408,13 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ continue; \\ } \\} - , + , &[_][]const u8{ \\pub fn foo() void { \\ while (true) { \\ continue; \\ } \\} - ); + }); cases.add("macros with field targets", \\typedef unsigned int GLbitfield; @@ -1429,7 +1429,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\extern union OpenGLProcs glProcs; \\#define glClearUnion glProcs.gl.Clear \\#define glClearPFN PFNGLCLEARPROC - , + , &[_][]const u8{ \\pub const GLbitfield = c_uint; , \\pub const PFNGLCLEARPROC = ?extern fn (GLbitfield) void; @@ -1452,7 +1452,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\} , \\pub const OpenGLProcs = union_OpenGLProcs; - ); + }); cases.add("variable name shadowing", \\int foo(void) { @@ -1463,7 +1463,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ } \\ return x; \\} - , + , &[_][]const u8{ \\pub fn foo() c_int { \\ var x: c_int = 1; \\ { @@ -1472,27 +1472,27 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ } \\ return x; \\} - ); + }); cases.add("pointer casting", \\float *ptrcast(int *a) { \\ return (float *)a; \\} - , + , &[_][]const u8{ \\fn ptrcast(a: [*c]c_int) [*c]f32 { \\ return @ptrCast([*c]f32, @alignCast(@alignOf(f32), a)); \\} - ); + }); cases.add("bin not", \\int foo(int x) { \\ return ~x; \\} - , + , &[_][]const u8{ \\pub fn foo(x: c_int) c_int { \\ return ~x; \\} - ); + }); cases.add("bool not", \\int foo(int a, float b, void *c) { @@ -1501,46 +1501,46 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ return !b; \\ return !c; \\} - , + , &[_][]const u8{ \\pub fn foo(a: c_int, b: f32, c: ?*c_void) c_int { \\ return !(a == 0); \\ return !(a != 0); \\ return !(b != 0); \\ return !(c != null); \\} - ); + }); cases.add("primitive types included in defined symbols", \\int foo(int u32) { \\ return u32; \\} - , + , &[_][]const u8{ \\pub fn foo(u32_0: c_int) c_int { \\ return u32_0; \\} - ); + }); cases.add("const ptr initializer", \\static const char *v0 = "0.0.0"; - , + , &[_][]const u8{ \\pub var v0: [*c]const u8 = "0.0.0"; - ); + }); cases.add("static incomplete array inside function", \\void foo(void) { \\ static const char v2[] = "2.2.2"; \\} - , + , &[_][]const u8{ \\pub fn foo() void { \\ const v2: [*c]const u8 = "2.2.2"; \\} - ); + }); cases.add("macro pointer cast", \\#define NRF_GPIO ((NRF_GPIO_Type *) NRF_GPIO_BASE) - , + , &[_][]const u8{ \\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); - ); + }); cases.add("if on non-bool", \\enum SomeEnum { A, B, C }; @@ -1551,7 +1551,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ if (d) return 3; \\ return 4; \\} - , + , &[_][]const u8{ \\pub const A = enum_SomeEnum.A; \\pub const B = enum_SomeEnum.B; \\pub const C = enum_SomeEnum.C; @@ -1567,7 +1567,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ if (d != @bitCast(enum_SomeEnum, @as(@TagType(enum_SomeEnum), 0))) return 3; \\ return 4; \\} - ); + }); cases.add("while on non-bool", \\int while_none_bool(int a, float b, void *c) { @@ -1576,14 +1576,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ while (c) return 2; \\ return 3; \\} - , + , &[_][]const u8{ \\pub fn while_none_bool(a: c_int, b: f32, c: ?*c_void) c_int { \\ while (a != 0) return 0; \\ while (b != 0) return 1; \\ while (c != null) return 2; \\ return 3; \\} - ); + }); cases.add("for on non-bool", \\int for_none_bool(int a, float b, void *c) { @@ -1592,14 +1592,14 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ for (;c;) return 2; \\ return 3; \\} - , + , &[_][]const u8{ \\pub fn for_none_bool(a: c_int, b: f32, c: ?*c_void) c_int { \\ while (a != 0) return 0; \\ while (b != 0) return 1; \\ while (c != null) return 2; \\ return 3; \\} - ); + }); cases.add("switch on int", \\int switch_fn(int i) { @@ -1616,7 +1616,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ res = 5; \\ } \\} - , + , &[_][]const u8{ \\pub fn switch_fn(i: c_int) c_int { \\ var res: c_int = 0; \\ __switch: { @@ -1641,54 +1641,70 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ res = 5; \\ } \\} - ); + }); cases.addC( "u integer suffix after 0 (zero) in macro definition", "#define ZERO 0U", - "pub const ZERO = @as(c_uint, 0);", + &[_][]const u8{ + "pub const ZERO = @as(c_uint, 0);", + }, ); cases.addC( "l integer suffix after 0 (zero) in macro definition", "#define ZERO 0L", - "pub const ZERO = @as(c_long, 0);", + &[_][]const u8{ + "pub const ZERO = @as(c_long, 0);", + }, ); cases.addC( "ul integer suffix after 0 (zero) in macro definition", "#define ZERO 0UL", - "pub const ZERO = @as(c_ulong, 0);", + &[_][]const u8{ + "pub const ZERO = @as(c_ulong, 0);", + }, ); cases.addC( "lu integer suffix after 0 (zero) in macro definition", "#define ZERO 0LU", - "pub const ZERO = @as(c_ulong, 0);", + &[_][]const u8{ + "pub const ZERO = @as(c_ulong, 0);", + }, ); cases.addC( "ll integer suffix after 0 (zero) in macro definition", "#define ZERO 0LL", - "pub const ZERO = @as(c_longlong, 0);", + &[_][]const u8{ + "pub const ZERO = @as(c_longlong, 0);", + }, ); cases.addC( "ull integer suffix after 0 (zero) in macro definition", "#define ZERO 0ULL", - "pub const ZERO = @as(c_ulonglong, 0);", + &[_][]const u8{ + "pub const ZERO = @as(c_ulonglong, 0);", + }, ); cases.addC( "llu integer suffix after 0 (zero) in macro definition", "#define ZERO 0LLU", - "pub const ZERO = @as(c_ulonglong, 0);", + &[_][]const u8{ + "pub const ZERO = @as(c_ulonglong, 0);", + }, ); cases.addC( "bitwise not on u-suffixed 0 (zero) in macro definition", "#define NOT_ZERO (~0U)", - "pub const NOT_ZERO = ~@as(c_uint, 0);", + &[_][]const u8{ + "pub const NOT_ZERO = ~@as(c_uint, 0);", + }, ); cases.addC("implicit casts", @@ -1719,7 +1735,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ fn_int(&fn_int); \\ fn_ptr(42); \\} - , + , &[_][]const u8{ \\pub extern fn fn_int(x: c_int) void; \\pub extern fn fn_f32(x: f32) void; \\pub extern fn fn_f64(x: f64) void; @@ -1744,7 +1760,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ fn_int(@intCast(c_int, @ptrToInt(&fn_int))); \\ fn_ptr(@intToPtr(?*c_void, 42)); \\} - ); + }); cases.addC("pointer conversion with different alignment", \\void test_ptr_cast() { @@ -1762,7 +1778,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ long long *to_longlong = p; \\ } \\} - , + , &[_][]const u8{ \\pub export fn test_ptr_cast() void { \\ var p: ?*c_void = undefined; \\ { @@ -1778,7 +1794,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ var to_longlong: [*c]c_longlong = @ptrCast([*c]c_longlong, @alignCast(@alignOf(c_longlong), p)); \\ } \\} - ); + }); cases.addC("escape sequences", \\const char *escapes() { @@ -1796,7 +1812,7 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ return "\'\\\a\b\f\n\r\t\v\0\""; \\} \\ - , + , &[_][]const u8{ \\pub export fn escapes() [*c]const u8 { \\ var a: u8 = @as(u8, '\''); \\ var b: u8 = @as(u8, '\\'); @@ -1812,23 +1828,23 @@ pub fn addCases(cases: *tests.TranslateCContext) void { \\ return "\'\\\x07\x08\x0c\n\r\t\x0b\x00\""; \\} \\ - ); + }); if (builtin.os != builtin.Os.windows) { // sysv_abi not currently supported on windows cases.add("Macro qualified functions", \\void __attribute__((sysv_abi)) foo(void); - , + , &[_][]const u8{ \\pub extern fn foo() void; - ); + }); } /////////////// Cases for only stage1 because stage2 behavior is better //////////////// cases.addC("Parameterless function prototypes", \\void foo() {} \\void bar(void) {} - , + , &[_][]const u8{ \\pub export fn foo() void {} \\pub export fn bar() void {} - ); + }); }