| author | |
| committer | |
| log | 7e2eb1326ba267012d47aa2eda539f01963d4d6b |
| tree | 61c165bea75319123ffec3412fb722bc1700147f |
| parent | b79884eaf003ad32e800213c20da5c6b8935af34 |
| parent | 2029601cb2ad4a6e9c8b260eec68de881d46735b |
| signature |
more stage2 compile error fixes104 files changed, 840 insertions(+), 719 deletions(-)
lib/c.zig+1-1| ... | ... | @@ -82,7 +82,7 @@ fn memset(dest: ?[*]u8, c: u8, len: usize) callconv(.C) ?[*]u8 { |
| 82 | 82 | var d = dest.?; |
| 83 | 83 | var n = len; |
| 84 | 84 | while (true) { |
| 85 | d.* = c; | |
| 85 | d[0] = c; | |
| 86 | 86 | n -= 1; |
| 87 | 87 | if (n == 0) break; |
| 88 | 88 | d += 1; |
lib/std/os.zig+1-1| ... | ... | @@ -1868,7 +1868,7 @@ pub fn getenv(key: []const u8) ?[]const u8 { |
| 1868 | 1868 | } |
| 1869 | 1869 | // Search the entire `environ` because we don't have a null terminated pointer. |
| 1870 | 1870 | var ptr = std.c.environ; |
| 1871 | while (ptr.*) |line| : (ptr += 1) { | |
| 1871 | while (ptr[0]) |line| : (ptr += 1) { | |
| 1872 | 1872 | var line_i: usize = 0; |
| 1873 | 1873 | while (line[line_i] != 0 and line[line_i] != '=') : (line_i += 1) {} |
| 1874 | 1874 | const this_key = line[0..line_i]; |
lib/std/process.zig+1-1| ... | ... | @@ -313,7 +313,7 @@ pub fn getEnvMap(allocator: Allocator) !EnvMap { |
| 313 | 313 | return result; |
| 314 | 314 | } else if (builtin.link_libc) { |
| 315 | 315 | var ptr = std.c.environ; |
| 316 | while (ptr.*) |line| : (ptr += 1) { | |
| 316 | while (ptr[0]) |line| : (ptr += 1) { | |
| 317 | 317 | var line_i: usize = 0; |
| 318 | 318 | while (line[line_i] != 0 and line[line_i] != '=') : (line_i += 1) {} |
| 319 | 319 | const key = line[0..line_i]; |
src/AstGen.zig+15-12| ... | ... | @@ -812,6 +812,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) InnerEr |
| 812 | 812 | |
| 813 | 813 | .deref => { |
| 814 | 814 | const lhs = try expr(gz, scope, .none, node_datas[node].lhs); |
| 815 | _ = try gz.addUnTok(.validate_deref, lhs, main_tokens[node]); | |
| 815 | 816 | switch (rl) { |
| 816 | 817 | .ref => return lhs, |
| 817 | 818 | else => { |
| ... | ... | @@ -2500,6 +2501,7 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner |
| 2500 | 2501 | .memset, |
| 2501 | 2502 | .validate_array_init_ty, |
| 2502 | 2503 | .validate_struct_init_ty, |
| 2504 | .validate_deref, | |
| 2503 | 2505 | => break :b true, |
| 2504 | 2506 | } |
| 2505 | 2507 | } else switch (maybe_unused_result) { |
| ... | ... | @@ -5152,16 +5154,14 @@ fn arrayAccess( |
| 5152 | 5154 | const tree = astgen.tree; |
| 5153 | 5155 | const node_datas = tree.nodes.items(.data); |
| 5154 | 5156 | switch (rl) { |
| 5155 | .ref => return gz.addBin( | |
| 5156 | .elem_ptr, | |
| 5157 | try expr(gz, scope, .ref, node_datas[node].lhs), | |
| 5158 | try expr(gz, scope, .{ .ty = .usize_type }, node_datas[node].rhs), | |
| 5159 | ), | |
| 5160 | else => return rvalue(gz, rl, try gz.addBin( | |
| 5161 | .elem_val, | |
| 5162 | try expr(gz, scope, .none, node_datas[node].lhs), | |
| 5163 | try expr(gz, scope, .{ .coerced_ty = .usize_type }, node_datas[node].rhs), | |
| 5164 | ), node), | |
| 5157 | .ref => return gz.addPlNode(.elem_ptr_node, node, Zir.Inst.Bin{ | |
| 5158 | .lhs = try expr(gz, scope, .ref, node_datas[node].lhs), | |
| 5159 | .rhs = try expr(gz, scope, .{ .ty = .usize_type }, node_datas[node].rhs), | |
| 5160 | }), | |
| 5161 | else => return rvalue(gz, rl, try gz.addPlNode(.elem_val_node, node, Zir.Inst.Bin{ | |
| 5162 | .lhs = try expr(gz, scope, .none, node_datas[node].lhs), | |
| 5163 | .rhs = try expr(gz, scope, .{ .ty = .usize_type }, node_datas[node].rhs), | |
| 5164 | }), node), | |
| 5165 | 5165 | } |
| 5166 | 5166 | } |
| 5167 | 5167 | |
| ... | ... | @@ -5683,7 +5683,7 @@ fn whileExpr( |
| 5683 | 5683 | try then_scope.addDbgVar(.dbg_var_val, some, dbg_var_inst); |
| 5684 | 5684 | } |
| 5685 | 5685 | if (while_full.ast.cont_expr != 0) { |
| 5686 | _ = try expr(&loop_scope, then_sub_scope, .{ .ty = .void_type }, while_full.ast.cont_expr); | |
| 5686 | _ = try unusedResultExpr(&loop_scope, then_sub_scope, while_full.ast.cont_expr); | |
| 5687 | 5687 | } |
| 5688 | 5688 | try then_scope.addDbgBlockEnd(); |
| 5689 | 5689 | const repeat_tag: Zir.Inst.Tag = if (is_inline) .repeat_inline else .repeat; |
| ... | ... | @@ -5888,7 +5888,10 @@ fn forExpr( |
| 5888 | 5888 | if (!mem.eql(u8, value_name, "_")) { |
| 5889 | 5889 | const name_str_index = try astgen.identAsString(ident); |
| 5890 | 5890 | const tag: Zir.Inst.Tag = if (is_ptr) .elem_ptr else .elem_val; |
| 5891 | const payload_inst = try then_scope.addBin(tag, array_ptr, index); | |
| 5891 | const payload_inst = try then_scope.addPlNode(tag, for_full.ast.cond_expr, Zir.Inst.Bin{ | |
| 5892 | .lhs = array_ptr, | |
| 5893 | .rhs = index, | |
| 5894 | }); | |
| 5892 | 5895 | try astgen.detectLocalShadowing(&then_scope.base, name_str_index, ident, value_name); |
| 5893 | 5896 | payload_val_scope = .{ |
| 5894 | 5897 | .parent = &then_scope.base, |
src/Sema.zig+147-39| ... | ... | @@ -1080,6 +1080,11 @@ fn analyzeBodyInner( |
| 1080 | 1080 | i += 1; |
| 1081 | 1081 | continue; |
| 1082 | 1082 | }, |
| 1083 | .validate_deref => { | |
| 1084 | try sema.zirValidateDeref(block, inst); | |
| 1085 | i += 1; | |
| 1086 | continue; | |
| 1087 | }, | |
| 1083 | 1088 | .@"export" => { |
| 1084 | 1089 | try sema.zirExport(block, inst); |
| 1085 | 1090 | i += 1; |
| ... | ... | @@ -2434,9 +2439,9 @@ fn zirEnumDecl( |
| 2434 | 2439 | const field_src = enumFieldSrcLoc(sema.mod.declPtr(block.src_decl), tree.*, src.node_offset.x, field_i); |
| 2435 | 2440 | const other_tag_src = enumFieldSrcLoc(sema.mod.declPtr(block.src_decl), tree.*, src.node_offset.x, gop.index); |
| 2436 | 2441 | const msg = msg: { |
| 2437 | const msg = try sema.errMsg(block, field_src, "duplicate enum tag", .{}); | |
| 2442 | const msg = try sema.errMsg(block, field_src, "duplicate enum field '{s}'", .{field_name}); | |
| 2438 | 2443 | errdefer msg.destroy(gpa); |
| 2439 | try sema.errNote(block, other_tag_src, msg, "other tag here", .{}); | |
| 2444 | try sema.errNote(block, other_tag_src, msg, "other field here", .{}); | |
| 2440 | 2445 | break :msg msg; |
| 2441 | 2446 | }; |
| 2442 | 2447 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -2733,6 +2738,7 @@ fn ensureResultUsed( |
| 2733 | 2738 | const operand_ty = sema.typeOf(operand); |
| 2734 | 2739 | switch (operand_ty.zigTypeTag()) { |
| 2735 | 2740 | .Void, .NoReturn => return, |
| 2741 | .ErrorSet, .ErrorUnion => return sema.fail(block, src, "error is ignored. consider using `try`, `catch`, or `if`", .{}), | |
| 2736 | 2742 | else => return sema.fail(block, src, "expression value is ignored", .{}), |
| 2737 | 2743 | } |
| 2738 | 2744 | } |
| ... | ... | @@ -2746,7 +2752,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com |
| 2746 | 2752 | const src = inst_data.src(); |
| 2747 | 2753 | const operand_ty = sema.typeOf(operand); |
| 2748 | 2754 | switch (operand_ty.zigTypeTag()) { |
| 2749 | .ErrorSet, .ErrorUnion => return sema.fail(block, src, "error is discarded", .{}), | |
| 2755 | .ErrorSet, .ErrorUnion => return sema.fail(block, src, "error is discarded. consider using `try`, `catch`, or `if`", .{}), | |
| 2750 | 2756 | else => return, |
| 2751 | 2757 | } |
| 2752 | 2758 | } |
| ... | ... | @@ -3849,6 +3855,28 @@ fn zirValidateArrayInit( |
| 3849 | 3855 | } |
| 3850 | 3856 | } |
| 3851 | 3857 | |
| 3858 | fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { | |
| 3859 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; | |
| 3860 | const src = inst_data.src(); | |
| 3861 | const operand_src: LazySrcLoc = .{ .token_offset = inst_data.src_tok + 1 }; | |
| 3862 | const operand = try sema.resolveInst(inst_data.operand); | |
| 3863 | const operand_ty = sema.typeOf(operand); | |
| 3864 | ||
| 3865 | if (operand_ty.zigTypeTag() != .Pointer) { | |
| 3866 | return sema.fail(block, src, "cannot dereference non-pointer type '{}'", .{operand_ty.fmt(sema.mod)}); | |
| 3867 | } else switch (operand_ty.ptrSize()) { | |
| 3868 | .One, .C => {}, | |
| 3869 | .Many => return sema.fail(block, src, "index syntax required for unknown-length pointer type '{}'", .{operand_ty.fmt(sema.mod)}), | |
| 3870 | .Slice => return sema.fail(block, src, "index syntax required for slice type '{}'", .{operand_ty.fmt(sema.mod)}), | |
| 3871 | } | |
| 3872 | ||
| 3873 | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { | |
| 3874 | if (val.isUndef()) { | |
| 3875 | return sema.fail(block, src, "cannot dereference undefined value", .{}); | |
| 3876 | } | |
| 3877 | } | |
| 3878 | } | |
| 3879 | ||
| 3852 | 3880 | fn failWithBadMemberAccess( |
| 3853 | 3881 | sema: *Sema, |
| 3854 | 3882 | block: *Block, |
| ... | ... | @@ -4272,7 +4300,8 @@ fn zirCompileLog( |
| 4272 | 4300 | } |
| 4273 | 4301 | try writer.print("\n", .{}); |
| 4274 | 4302 | |
| 4275 | const gop = try sema.mod.compile_log_decls.getOrPut(sema.gpa, sema.owner_decl_index); | |
| 4303 | const decl_index = if (sema.func) |some| some.owner_decl else sema.owner_decl_index; | |
| 4304 | const gop = try sema.mod.compile_log_decls.getOrPut(sema.gpa, decl_index); | |
| 4276 | 4305 | if (!gop.found_existing) { |
| 4277 | 4306 | gop.value_ptr.* = src_node; |
| 4278 | 4307 | } |
| ... | ... | @@ -6416,6 +6445,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 6416 | 6445 | if (dest_ty.zigTypeTag() != .Enum) { |
| 6417 | 6446 | return sema.fail(block, dest_ty_src, "expected enum, found '{}'", .{dest_ty.fmt(sema.mod)}); |
| 6418 | 6447 | } |
| 6448 | _ = try sema.checkIntType(block, operand_src, sema.typeOf(operand)); | |
| 6419 | 6449 | |
| 6420 | 6450 | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |int_val| { |
| 6421 | 6451 | if (dest_ty.isNonexhaustiveEnum()) { |
| ... | ... | @@ -7007,6 +7037,7 @@ fn funcCommon( |
| 7007 | 7037 | noalias_bits: u32, |
| 7008 | 7038 | ) CompileError!Air.Inst.Ref { |
| 7009 | 7039 | const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = src_node_offset }; |
| 7040 | const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = src_node_offset }; | |
| 7010 | 7041 | |
| 7011 | 7042 | var is_generic = bare_return_type.tag() == .generic_poison or |
| 7012 | 7043 | alignment == null or |
| ... | ... | @@ -7062,7 +7093,7 @@ fn funcCommon( |
| 7062 | 7093 | const param_types = try sema.arena.alloc(Type, block.params.items.len); |
| 7063 | 7094 | const comptime_params = try sema.arena.alloc(bool, block.params.items.len); |
| 7064 | 7095 | for (block.params.items) |param, i| { |
| 7065 | const param_src = LazySrcLoc.nodeOffset(src_node_offset); // TODO better src | |
| 7096 | const param_src = LazySrcLoc.nodeOffset(src_node_offset); // TODO better soruce location | |
| 7066 | 7097 | param_types[i] = param.ty; |
| 7067 | 7098 | comptime_params[i] = param.is_comptime or |
| 7068 | 7099 | try sema.typeRequiresComptime(block, param_src, param.ty); |
| ... | ... | @@ -7109,6 +7140,45 @@ fn funcCommon( |
| 7109 | 7140 | const cc_workaround = cc orelse .Unspecified; |
| 7110 | 7141 | const align_workaround = alignment orelse 0; |
| 7111 | 7142 | |
| 7143 | const arch = sema.mod.getTarget().cpu.arch; | |
| 7144 | if (switch (cc_workaround) { | |
| 7145 | .Unspecified, .C, .Naked, .Async, .Inline => null, | |
| 7146 | .Interrupt => switch (arch) { | |
| 7147 | .i386, .x86_64, .avr, .msp430 => null, | |
| 7148 | else => @as([]const u8, "i386, x86_64, AVR, and MSP430"), | |
| 7149 | }, | |
| 7150 | .Signal => switch (arch) { | |
| 7151 | .avr => null, | |
| 7152 | else => @as([]const u8, "AVR"), | |
| 7153 | }, | |
| 7154 | .Stdcall, .Fastcall, .Thiscall => switch (arch) { | |
| 7155 | .i386 => null, | |
| 7156 | else => @as([]const u8, "i386"), | |
| 7157 | }, | |
| 7158 | .Vectorcall => switch (arch) { | |
| 7159 | .i386, .aarch64, .aarch64_be, .aarch64_32 => null, | |
| 7160 | else => @as([]const u8, "i386 and AArch64"), | |
| 7161 | }, | |
| 7162 | .APCS, .AAPCS, .AAPCSVFP => switch (arch) { | |
| 7163 | .arm, .armeb, .aarch64, .aarch64_be, .aarch64_32 => null, | |
| 7164 | else => @as([]const u8, "ARM"), | |
| 7165 | }, | |
| 7166 | .SysV, .Win64 => switch (arch) { | |
| 7167 | .x86_64 => null, | |
| 7168 | else => @as([]const u8, "x86_64"), | |
| 7169 | }, | |
| 7170 | .PtxKernel => switch (arch) { | |
| 7171 | .nvptx, .nvptx64 => null, | |
| 7172 | else => @as([]const u8, "nvptx and nvptx64"), | |
| 7173 | }, | |
| 7174 | }) |allowed_platform| { | |
| 7175 | return sema.fail(block, cc_src, "callconv '{s}' is only available on {s}, not {s}", .{ | |
| 7176 | @tagName(cc_workaround), | |
| 7177 | allowed_platform, | |
| 7178 | @tagName(arch), | |
| 7179 | }); | |
| 7180 | } | |
| 7181 | ||
| 7112 | 7182 | break :fn_ty try Type.Tag.function.create(sema.arena, .{ |
| 7113 | 7183 | .param_types = param_types, |
| 7114 | 7184 | .comptime_params = comptime_params.ptr, |
| ... | ... | @@ -7617,11 +7687,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 7617 | 7687 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; |
| 7618 | 7688 | |
| 7619 | 7689 | const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs); |
| 7690 | const operand = try sema.resolveInst(extra.rhs); | |
| 7620 | 7691 | switch (dest_ty.zigTypeTag()) { |
| 7621 | 7692 | .AnyFrame, |
| 7622 | 7693 | .ComptimeFloat, |
| 7623 | 7694 | .ComptimeInt, |
| 7624 | .Enum, | |
| 7625 | 7695 | .EnumLiteral, |
| 7626 | 7696 | .ErrorSet, |
| 7627 | 7697 | .ErrorUnion, |
| ... | ... | @@ -7634,7 +7704,21 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 7634 | 7704 | .Type, |
| 7635 | 7705 | .Undefined, |
| 7636 | 7706 | .Void, |
| 7637 | => return sema.fail(block, dest_ty_src, "invalid type '{}' for @bitCast", .{dest_ty.fmt(sema.mod)}), | |
| 7707 | => return sema.fail(block, dest_ty_src, "cannot @bitCast to '{}'", .{dest_ty.fmt(sema.mod)}), | |
| 7708 | ||
| 7709 | .Enum => { | |
| 7710 | const msg = msg: { | |
| 7711 | const msg = try sema.errMsg(block, dest_ty_src, "cannot @bitCast to '{}'", .{dest_ty.fmt(sema.mod)}); | |
| 7712 | errdefer msg.destroy(sema.gpa); | |
| 7713 | switch (sema.typeOf(operand).zigTypeTag()) { | |
| 7714 | .Int, .ComptimeInt => try sema.errNote(block, dest_ty_src, msg, "use @intToEnum for type coercion", .{}), | |
| 7715 | else => {}, | |
| 7716 | } | |
| 7717 | ||
| 7718 | break :msg msg; | |
| 7719 | }; | |
| 7720 | return sema.failWithOwnedErrorMsg(block, msg); | |
| 7721 | }, | |
| 7638 | 7722 | |
| 7639 | 7723 | .Pointer => return sema.fail(block, dest_ty_src, "cannot @bitCast to '{}', use @ptrCast to cast to a pointer", .{ |
| 7640 | 7724 | dest_ty.fmt(sema.mod), |
| ... | ... | @@ -7658,8 +7742,6 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 7658 | 7742 | .Vector, |
| 7659 | 7743 | => {}, |
| 7660 | 7744 | } |
| 7661 | ||
| 7662 | const operand = try sema.resolveInst(extra.rhs); | |
| 7663 | 7745 | return sema.bitCast(block, dest_ty, operand, operand_src); |
| 7664 | 7746 | } |
| 7665 | 7747 | |
| ... | ... | @@ -7717,12 +7799,12 @@ fn zirElemVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 7717 | 7799 | const tracy = trace(@src()); |
| 7718 | 7800 | defer tracy.end(); |
| 7719 | 7801 | |
| 7720 | const bin_inst = sema.code.instructions.items(.data)[inst].bin; | |
| 7721 | const src = sema.src; // TODO better source location | |
| 7722 | const elem_index_src = sema.src; // TODO better source location | |
| 7723 | const array = try sema.resolveInst(bin_inst.lhs); | |
| 7724 | const elem_index = try sema.resolveInst(bin_inst.rhs); | |
| 7725 | return sema.elemVal(block, src, array, elem_index, elem_index_src); | |
| 7802 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | |
| 7803 | const src = inst_data.src(); | |
| 7804 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | |
| 7805 | const array = try sema.resolveInst(extra.lhs); | |
| 7806 | const elem_index = try sema.resolveInst(extra.rhs); | |
| 7807 | return sema.elemVal(block, src, array, elem_index, src); | |
| 7726 | 7808 | } |
| 7727 | 7809 | |
| 7728 | 7810 | fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -7742,10 +7824,12 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 7742 | 7824 | const tracy = trace(@src()); |
| 7743 | 7825 | defer tracy.end(); |
| 7744 | 7826 | |
| 7745 | const bin_inst = sema.code.instructions.items(.data)[inst].bin; | |
| 7746 | const array_ptr = try sema.resolveInst(bin_inst.lhs); | |
| 7747 | const elem_index = try sema.resolveInst(bin_inst.rhs); | |
| 7748 | return sema.elemPtr(block, sema.src, array_ptr, elem_index, sema.src, false); | |
| 7827 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | |
| 7828 | const src = inst_data.src(); | |
| 7829 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | |
| 7830 | const array_ptr = try sema.resolveInst(extra.lhs); | |
| 7831 | const elem_index = try sema.resolveInst(extra.rhs); | |
| 7832 | return sema.elemPtr(block, src, array_ptr, elem_index, src, false); | |
| 7749 | 7833 | } |
| 7750 | 7834 | |
| 7751 | 7835 | fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -8297,19 +8381,15 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8297 | 8381 | block, |
| 8298 | 8382 | src, |
| 8299 | 8383 | msg, |
| 8300 | "unhandled error value: error.{s}", | |
| 8384 | "unhandled error value: 'error.{s}'", | |
| 8301 | 8385 | .{error_name}, |
| 8302 | 8386 | ); |
| 8303 | 8387 | } |
| 8304 | 8388 | } |
| 8305 | 8389 | |
| 8306 | 8390 | if (maybe_msg) |msg| { |
| 8307 | try sema.mod.errNoteNonLazy( | |
| 8308 | operand_ty.declSrcLoc(sema.mod), | |
| 8309 | msg, | |
| 8310 | "error set '{}' declared here", | |
| 8311 | .{operand_ty.fmt(sema.mod)}, | |
| 8312 | ); | |
| 8391 | maybe_msg = null; | |
| 8392 | try sema.addDeclaredHereNote(msg, operand_ty); | |
| 8313 | 8393 | return sema.failWithOwnedErrorMsg(block, msg); |
| 8314 | 8394 | } |
| 8315 | 8395 | |
| ... | ... | @@ -17062,9 +17142,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 17062 | 17142 | const field_index = struct_obj.fields.getIndex(field_name) orelse |
| 17063 | 17143 | return sema.failWithBadStructFieldAccess(block, struct_obj, name_src, field_name); |
| 17064 | 17144 | |
| 17065 | if (field_ptr_ty.zigTypeTag() != .Pointer) { | |
| 17066 | return sema.fail(block, ty_src, "expected pointer type, found '{}'", .{field_ptr_ty.fmt(sema.mod)}); | |
| 17067 | } | |
| 17145 | try sema.checkPtrOperand(block, ptr_src, field_ptr_ty); | |
| 17068 | 17146 | const field = struct_obj.fields.values()[field_index]; |
| 17069 | 17147 | const field_ptr_ty_info = field_ptr_ty.ptrInfo().data; |
| 17070 | 17148 | |
| ... | ... | @@ -17087,8 +17165,29 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 17087 | 17165 | const result_ptr = try Type.ptr(sema.arena, sema.mod, ptr_ty_data); |
| 17088 | 17166 | |
| 17089 | 17167 | if (try sema.resolveDefinedValue(block, src, casted_field_ptr)) |field_ptr_val| { |
| 17090 | const payload = field_ptr_val.castTag(.field_ptr).?.data; | |
| 17091 | return sema.addConstant(result_ptr, payload.container_ptr); | |
| 17168 | const payload = field_ptr_val.castTag(.field_ptr) orelse { | |
| 17169 | return sema.fail(block, ptr_src, "pointer value not based on parent struct", .{}); | |
| 17170 | }; | |
| 17171 | if (payload.data.field_index != field_index) { | |
| 17172 | const msg = msg: { | |
| 17173 | const msg = try sema.errMsg( | |
| 17174 | block, | |
| 17175 | src, | |
| 17176 | "field '{s}' has index '{d}' but pointer value is index '{d}' of struct '{}'", | |
| 17177 | .{ | |
| 17178 | field_name, | |
| 17179 | field_index, | |
| 17180 | payload.data.field_index, | |
| 17181 | struct_ty.fmt(sema.mod), | |
| 17182 | }, | |
| 17183 | ); | |
| 17184 | errdefer msg.destroy(sema.gpa); | |
| 17185 | try sema.addDeclaredHereNote(msg, struct_ty); | |
| 17186 | break :msg msg; | |
| 17187 | }; | |
| 17188 | return sema.failWithOwnedErrorMsg(block, msg); | |
| 17189 | } | |
| 17190 | return sema.addConstant(result_ptr, payload.data.container_ptr); | |
| 17092 | 17191 | } |
| 17093 | 17192 | |
| 17094 | 17193 | try sema.requireRuntimeBlock(block, src); |
| ... | ... | @@ -18434,7 +18533,16 @@ fn fieldVal( |
| 18434 | 18533 | kw_name, child_type.fmt(sema.mod), field_name, |
| 18435 | 18534 | }); |
| 18436 | 18535 | }, |
| 18437 | else => return sema.fail(block, src, "type '{}' has no members", .{child_type.fmt(sema.mod)}), | |
| 18536 | else => { | |
| 18537 | const msg = msg: { | |
| 18538 | const msg = try sema.errMsg(block, src, "type '{}' has no members", .{child_type.fmt(sema.mod)}); | |
| 18539 | errdefer msg.destroy(sema.gpa); | |
| 18540 | if (child_type.isSlice()) try sema.errNote(block, src, msg, "slice values have 'len' and 'ptr' members", .{}); | |
| 18541 | if (child_type.zigTypeTag() == .Array) try sema.errNote(block, src, msg, "array values have 'len' member", .{}); | |
| 18542 | break :msg msg; | |
| 18543 | }; | |
| 18544 | return sema.failWithOwnedErrorMsg(block, msg); | |
| 18545 | }, | |
| 18438 | 18546 | } |
| 18439 | 18547 | }, |
| 18440 | 18548 | .Struct => if (is_pointer_to) { |
| ... | ... | @@ -18658,7 +18766,7 @@ fn fieldPtr( |
| 18658 | 18766 | }, |
| 18659 | 18767 | else => {}, |
| 18660 | 18768 | } |
| 18661 | return sema.fail(block, src, "type '{}' does not support field access (fieldPtr, {}.{s})", .{ object_ty.fmt(sema.mod), object_ptr_ty.fmt(sema.mod), field_name }); | |
| 18769 | return sema.fail(block, src, "type '{}' does not support field access", .{object_ty.fmt(sema.mod)}); | |
| 18662 | 18770 | } |
| 18663 | 18771 | |
| 18664 | 18772 | fn fieldCallBind( |
| ... | ... | @@ -19349,7 +19457,7 @@ fn tupleFieldPtr( |
| 19349 | 19457 | const tuple_fields = tuple_ty.tupleFields(); |
| 19350 | 19458 | |
| 19351 | 19459 | if (tuple_fields.types.len == 0) { |
| 19352 | return sema.fail(block, field_index_src, "indexing into empty tuple", .{}); | |
| 19460 | return sema.fail(block, tuple_ptr_src, "indexing into empty tuple is not allowed", .{}); | |
| 19353 | 19461 | } |
| 19354 | 19462 | |
| 19355 | 19463 | if (field_index >= tuple_fields.types.len) { |
| ... | ... | @@ -19392,7 +19500,7 @@ fn tupleField( |
| 19392 | 19500 | const tuple_fields = tuple_ty.tupleFields(); |
| 19393 | 19501 | |
| 19394 | 19502 | if (tuple_fields.types.len == 0) { |
| 19395 | return sema.fail(block, field_index_src, "indexing into empty tuple", .{}); | |
| 19503 | return sema.fail(block, tuple_src, "indexing into empty tuple is not allowed", .{}); | |
| 19396 | 19504 | } |
| 19397 | 19505 | |
| 19398 | 19506 | if (field_index >= tuple_fields.types.len) { |
| ... | ... | @@ -19433,7 +19541,7 @@ fn elemValArray( |
| 19433 | 19541 | const elem_ty = array_ty.childType(); |
| 19434 | 19542 | |
| 19435 | 19543 | if (array_len_s == 0) { |
| 19436 | return sema.fail(block, elem_index_src, "indexing into empty array", .{}); | |
| 19544 | return sema.fail(block, array_src, "indexing into empty array is not allowed", .{}); | |
| 19437 | 19545 | } |
| 19438 | 19546 | |
| 19439 | 19547 | const maybe_undef_array_val = try sema.resolveMaybeUndefVal(block, array_src, array); |
| ... | ... | @@ -19513,7 +19621,7 @@ fn elemPtrArray( |
| 19513 | 19621 | const array_len_s = array_len + @boolToInt(array_sent); |
| 19514 | 19622 | |
| 19515 | 19623 | if (array_len_s == 0) { |
| 19516 | return sema.fail(block, elem_index_src, "indexing into empty array", .{}); | |
| 19624 | return sema.fail(block, array_ptr_src, "indexing into empty array is not allowed", .{}); | |
| 19517 | 19625 | } |
| 19518 | 19626 | |
| 19519 | 19627 | const maybe_undef_array_ptr_val = try sema.resolveMaybeUndefVal(block, array_ptr_src, array_ptr); |
| ... | ... | @@ -19595,7 +19703,7 @@ fn elemValSlice( |
| 19595 | 19703 | const slice_len = slice_val.sliceLen(sema.mod); |
| 19596 | 19704 | const slice_len_s = slice_len + @boolToInt(slice_sent); |
| 19597 | 19705 | if (slice_len_s == 0) { |
| 19598 | return sema.fail(block, elem_index_src, "indexing into empty slice", .{}); | |
| 19706 | return sema.fail(block, slice_src, "indexing into empty slice is not allowed", .{}); | |
| 19599 | 19707 | } |
| 19600 | 19708 | if (maybe_index_val) |index_val| { |
| 19601 | 19709 | const index = @intCast(usize, index_val.toUnsignedInt(target)); |
| ... | ... | @@ -19652,7 +19760,7 @@ fn elemPtrSlice( |
| 19652 | 19760 | const slice_len = slice_val.sliceLen(sema.mod); |
| 19653 | 19761 | const slice_len_s = slice_len + @boolToInt(slice_sent); |
| 19654 | 19762 | if (slice_len_s == 0) { |
| 19655 | return sema.fail(block, elem_index_src, "indexing into empty slice", .{}); | |
| 19763 | return sema.fail(block, slice_src, "indexing into empty slice is not allowed", .{}); | |
| 19656 | 19764 | } |
| 19657 | 19765 | if (offset) |index| { |
| 19658 | 19766 | if (index >= slice_len_s) { |
src/Zir.zig+15-10| ... | ... | @@ -370,24 +370,23 @@ pub const Inst = struct { |
| 370 | 370 | /// Uses the `pl_node` union field. Payload is `Bin`. |
| 371 | 371 | div, |
| 372 | 372 | /// Given a pointer to an array, slice, or pointer, returns a pointer to the element at |
| 373 | /// the provided index. Uses the `bin` union field. Source location is implied | |
| 374 | /// to be the same as the previous instruction. | |
| 375 | elem_ptr, | |
| 376 | /// Same as `elem_ptr` except also stores a source location node. | |
| 373 | /// the provided index. | |
| 377 | 374 | /// Uses the `pl_node` union field. AST node is a[b] syntax. Payload is `Bin`. |
| 378 | 375 | elem_ptr_node, |
| 376 | /// Same as `elem_ptr_node` but used only for for loop. | |
| 377 | /// Uses the `pl_node` union field. AST node is the condition of a for loop. Payload is `Bin`. | |
| 378 | elem_ptr, | |
| 379 | 379 | /// Same as `elem_ptr_node` except the index is stored immediately rather than |
| 380 | 380 | /// as a reference to another ZIR instruction. |
| 381 | 381 | /// Uses the `pl_node` union field. AST node is an element inside array initialization |
| 382 | 382 | /// syntax. Payload is `ElemPtrImm`. |
| 383 | 383 | elem_ptr_imm, |
| 384 | 384 | /// Given an array, slice, or pointer, returns the element at the provided index. |
| 385 | /// Uses the `bin` union field. Source location is implied to be the same | |
| 386 | /// as the previous instruction. | |
| 387 | elem_val, | |
| 388 | /// Same as `elem_val` except also stores a source location node. | |
| 389 | 385 | /// Uses the `pl_node` union field. AST node is a[b] syntax. Payload is `Bin`. |
| 390 | 386 | elem_val_node, |
| 387 | /// Same as `elem_val_node` but used only for for loop. | |
| 388 | /// Uses the `pl_node` union field. AST node is the condition of a for loop. Payload is `Bin`. | |
| 389 | elem_val, | |
| 391 | 390 | /// Emits a compile error if the operand is not `void`. |
| 392 | 391 | /// Uses the `un_node` field. |
| 393 | 392 | ensure_result_used, |
| ... | ... | @@ -729,6 +728,9 @@ pub const Inst = struct { |
| 729 | 728 | /// Same as `validate_array_init` but additionally communicates that the |
| 730 | 729 | /// resulting array initialization value is within a comptime scope. |
| 731 | 730 | validate_array_init_comptime, |
| 731 | /// Check that operand type supports the dereference operand (.*). | |
| 732 | /// Uses the `un_tok` field. | |
| 733 | validate_deref, | |
| 732 | 734 | /// A struct literal with a specified type, with no fields. |
| 733 | 735 | /// Uses the `un_node` field. |
| 734 | 736 | struct_init_empty, |
| ... | ... | @@ -1156,6 +1158,7 @@ pub const Inst = struct { |
| 1156 | 1158 | .validate_struct_init_comptime, |
| 1157 | 1159 | .validate_array_init, |
| 1158 | 1160 | .validate_array_init_comptime, |
| 1161 | .validate_deref, | |
| 1159 | 1162 | .struct_init_empty, |
| 1160 | 1163 | .struct_init, |
| 1161 | 1164 | .struct_init_ref, |
| ... | ... | @@ -1309,6 +1312,7 @@ pub const Inst = struct { |
| 1309 | 1312 | .validate_struct_init_comptime, |
| 1310 | 1313 | .validate_array_init, |
| 1311 | 1314 | .validate_array_init_comptime, |
| 1315 | .validate_deref, | |
| 1312 | 1316 | .@"export", |
| 1313 | 1317 | .export_value, |
| 1314 | 1318 | .set_cold, |
| ... | ... | @@ -1622,10 +1626,10 @@ pub const Inst = struct { |
| 1622 | 1626 | .decl_val = .str_tok, |
| 1623 | 1627 | .load = .un_node, |
| 1624 | 1628 | .div = .pl_node, |
| 1625 | .elem_ptr = .bin, | |
| 1629 | .elem_ptr = .pl_node, | |
| 1626 | 1630 | .elem_ptr_node = .pl_node, |
| 1627 | 1631 | .elem_ptr_imm = .pl_node, |
| 1628 | .elem_val = .bin, | |
| 1632 | .elem_val = .pl_node, | |
| 1629 | 1633 | .elem_val_node = .pl_node, |
| 1630 | 1634 | .ensure_result_used = .un_node, |
| 1631 | 1635 | .ensure_result_non_error = .un_node, |
| ... | ... | @@ -1709,6 +1713,7 @@ pub const Inst = struct { |
| 1709 | 1713 | .validate_struct_init_comptime = .pl_node, |
| 1710 | 1714 | .validate_array_init = .pl_node, |
| 1711 | 1715 | .validate_array_init_comptime = .pl_node, |
| 1716 | .validate_deref = .un_tok, | |
| 1712 | 1717 | .struct_init_empty = .un_node, |
| 1713 | 1718 | .field_type = .pl_node, |
| 1714 | 1719 | .field_type_ref = .pl_node, |
src/print_zir.zig+3-2| ... | ... | @@ -144,8 +144,6 @@ const Writer = struct { |
| 144 | 144 | switch (tag) { |
| 145 | 145 | .array_type, |
| 146 | 146 | .as, |
| 147 | .elem_ptr, | |
| 148 | .elem_val, | |
| 149 | 147 | .store, |
| 150 | 148 | .store_to_block_ptr, |
| 151 | 149 | .store_to_inferred_ptr, |
| ... | ... | @@ -242,6 +240,7 @@ const Writer = struct { |
| 242 | 240 | .ret_tok, |
| 243 | 241 | .ensure_err_payload_void, |
| 244 | 242 | .closure_capture, |
| 243 | .validate_deref, | |
| 245 | 244 | => try self.writeUnTok(stream, inst), |
| 246 | 245 | |
| 247 | 246 | .bool_br_and, |
| ... | ... | @@ -354,6 +353,8 @@ const Writer = struct { |
| 354 | 353 | .minimum, |
| 355 | 354 | .elem_ptr_node, |
| 356 | 355 | .elem_val_node, |
| 356 | .elem_ptr, | |
| 357 | .elem_val, | |
| 357 | 358 | .coerce_result_ptr, |
| 358 | 359 | => try self.writePlNodeBin(stream, inst), |
| 359 | 360 |
src/type.zig+1-1| ... | ... | @@ -189,7 +189,7 @@ pub const Type = extern union { |
| 189 | 189 | .Frame, |
| 190 | 190 | => false, |
| 191 | 191 | |
| 192 | .Pointer => is_equality_cmp or ty.isCPtr(), | |
| 192 | .Pointer => !ty.isSlice() and (is_equality_cmp or ty.isCPtr()), | |
| 193 | 193 | .Optional => { |
| 194 | 194 | if (!is_equality_cmp) return false; |
| 195 | 195 | var buf: Payload.ElemType = undefined; |
test/cases/compile_errors/assign_to_invalid_dereference.zig created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | export fn entry() void { | |
| 2 | 'a'.* = 1; | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage2 | |
| 7 | // target=native | |
| 8 | // | |
| 9 | // :2:8: error: cannot dereference non-pointer type 'comptime_int' |
test/cases/compile_errors/bitCast_to_enum_type.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | export fn entry() void { | |
| 2 | const E = enum(u32) { a, b }; | |
| 3 | const y = @bitCast(E, @as(u32, 3)); | |
| 4 | _ = y; | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage2 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // :3:24: error: cannot @bitCast to 'tmp.entry.E' | |
| 12 | // :3:24: note: use @intToEnum for type coercion |
test/cases/compile_errors/bogus_compile_var.zig created+8| ... | ... | @@ -0,0 +1,8 @@ |
| 1 | const x = @import("builtin").bogus; | |
| 2 | export fn entry() usize { return @sizeOf(@TypeOf(x)); } | |
| 3 | ||
| 4 | // error | |
| 5 | // backend=stage2 | |
| 6 | // target=native | |
| 7 | // | |
| 8 | // :1:29: error: struct 'builtin.builtin' has no member named 'bogus' |
test/cases/compile_errors/callconv_apcs_aapcs_aapcsvfp_on_unsupported_platform.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | export fn entry1() callconv(.APCS) void {} | |
| 2 | export fn entry2() callconv(.AAPCS) void {} | |
| 3 | export fn entry3() callconv(.AAPCSVFP) void {} | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage2 | |
| 7 | // target=x86_64-linux-none | |
| 8 | // | |
| 9 | // :1:30: error: callconv 'APCS' is only available on ARM, not x86_64 | |
| 10 | // :2:30: error: callconv 'AAPCS' is only available on ARM, not x86_64 | |
| 11 | // :3:30: error: callconv 'AAPCSVFP' is only available on ARM, not x86_64 |
test/cases/compile_errors/callconv_interrupt_on_unsupported_platform.zig created+7| ... | ... | @@ -0,0 +1,7 @@ |
| 1 | export fn entry() callconv(.Interrupt) void {} | |
| 2 | ||
| 3 | // error | |
| 4 | // backend=stage2 | |
| 5 | // target=aarch64-linux-none | |
| 6 | // | |
| 7 | // :1:29: error: callconv 'Interrupt' is only available on i386, x86_64, AVR, and MSP430, not aarch64 |
test/cases/compile_errors/callconv_signal_on_unsupported_platform.zig created+7| ... | ... | @@ -0,0 +1,7 @@ |
| 1 | export fn entry() callconv(.Signal) void {} | |
| 2 | ||
| 3 | // error | |
| 4 | // backend=stage2 | |
| 5 | // target=x86_64-linux-none | |
| 6 | // | |
| 7 | // :1:29: error: callconv 'Signal' is only available on AVR, not x86_64 |
test/cases/compile_errors/callconv_stdcall_fastcall_thiscall_on_unsupported_platform.zig created+23| ... | ... | @@ -0,0 +1,23 @@ |
| 1 | const F1 = fn () callconv(.Stdcall) void; | |
| 2 | const F2 = fn () callconv(.Fastcall) void; | |
| 3 | const F3 = fn () callconv(.Thiscall) void; | |
| 4 | export fn entry1() void { | |
| 5 | var a: F1 = undefined; | |
| 6 | _ = a; | |
| 7 | } | |
| 8 | export fn entry2() void { | |
| 9 | var a: F2 = undefined; | |
| 10 | _ = a; | |
| 11 | } | |
| 12 | export fn entry3() void { | |
| 13 | var a: F3 = undefined; | |
| 14 | _ = a; | |
| 15 | } | |
| 16 | ||
| 17 | // error | |
| 18 | // backend=stage2 | |
| 19 | // target=x86_64-linux-none | |
| 20 | // | |
| 21 | // :1:28: error: callconv 'Stdcall' is only available on i386, not x86_64 | |
| 22 | // :2:28: error: callconv 'Fastcall' is only available on i386, not x86_64 | |
| 23 | // :3:28: error: callconv 'Thiscall' is only available on i386, not x86_64 |
test/cases/compile_errors/callconv_vectorcall_on_unsupported_platform.zig created+7| ... | ... | @@ -0,0 +1,7 @@ |
| 1 | export fn entry() callconv(.Vectorcall) void {} | |
| 2 | ||
| 3 | // error | |
| 4 | // backend=stage2 | |
| 5 | // target=x86_64-linux-none | |
| 6 | // | |
| 7 | // :1:29: error: callconv 'Vectorcall' is only available on i386 and AArch64, not x86_64 |
test/cases/compile_errors/compile-time_division_by_zero.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | comptime { | |
| 2 | const a: i32 = 1; | |
| 3 | const b: i32 = 0; | |
| 4 | const c = a / b; | |
| 5 | _ = c; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage2 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // :4:19: error: division by zero here causes undefined behavior |
test/cases/compile_errors/compile-time_remainder_division_by_zero.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | comptime { | |
| 2 | const a: i32 = 1; | |
| 3 | const b: i32 = 0; | |
| 4 | const c = a % b; | |
| 5 | _ = c; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage2 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // :4:19: error: division by zero here causes undefined behavior |
test/cases/compile_errors/compileLog_of_tagged_enum_doesnt_crash_the_compiler.zig created+17| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | const Bar = union(enum(u32)) { | |
| 2 | X: i32 = 1 | |
| 3 | }; | |
| 4 | ||
| 5 | fn testCompileLog(x: Bar) void { | |
| 6 | @compileLog(x); | |
| 7 | } | |
| 8 | ||
| 9 | pub export fn entry() void { | |
| 10 | comptime testCompileLog(Bar{.X = 123}); | |
| 11 | } | |
| 12 | ||
| 13 | // error | |
| 14 | // backend=stage2 | |
| 15 | // target=native | |
| 16 | // | |
| 17 | // :6:5: error: found compile log statement |
test/cases/compile_errors/compile_log.zig created+14| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | export fn foo() void { | |
| 2 | comptime bar(12, "hi",); | |
| 3 | } | |
| 4 | fn bar(a: i32, b: []const u8) void { | |
| 5 | @compileLog("begin",); | |
| 6 | @compileLog("a", a, "b", b); | |
| 7 | @compileLog("end",); | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=llvm | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // :5:5: error: found compile log statement |
test/cases/compile_errors/compile_log_statement_inside_function_which_must_be_comptime_evaluated.zig created+14| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | fn Foo(comptime T: type) type { | |
| 2 | @compileLog(@typeName(T)); | |
| 3 | return T; | |
| 4 | } | |
| 5 | export fn entry() void { | |
| 6 | _ = Foo(i32); | |
| 7 | _ = @typeName(Foo(i32)); | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage2 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // :2:5: error: found compile log statement |
test/cases/compile_errors/compile_time_division_by_zero.zig created+13| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | const y = foo(0); | |
| 2 | fn foo(x: u32) u32 { | |
| 3 | return 1 / x; | |
| 4 | } | |
| 5 | ||
| 6 | export fn entry() usize { return @sizeOf(@TypeOf(y)); } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=llvm | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // :3:16: error: division by zero here causes undefined behavior | |
| 13 | // :1:14: note: called from here |
test/cases/compile_errors/deref_on_undefined_value.zig created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | comptime { | |
| 2 | var a: *u8 = undefined; | |
| 3 | _ = a.*; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage2 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // :3:10: error: cannot dereference undefined value |
test/cases/compile_errors/deref_slice_and_get_len_field.zig created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | export fn entry() void { | |
| 2 | var a: []u8 = undefined; | |
| 3 | _ = a.*.len; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage2 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // :3:10: error: index syntax required for slice type '[]u8' |
test/cases/compile_errors/dereference_an_array.zig created+14| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | var s_buffer: [10]u8 = undefined; | |
| 2 | pub fn pass(in: []u8) []u8 { | |
| 3 | var out = &s_buffer; | |
| 4 | out.*.* = in[0]; | |
| 5 | return out.*[0..1]; | |
| 6 | } | |
| 7 | ||
| 8 | export fn entry() usize { return @sizeOf(@TypeOf(&pass)); } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage2 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // :4:10: error: cannot dereference non-pointer type '[10]u8' |
test/cases/compile_errors/dereference_slice.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | fn entry(x: []i32) i32 { | |
| 2 | return x.*; | |
| 3 | } | |
| 4 | comptime { | |
| 5 | _ = entry; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage2 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // :2:13: error: index syntax required for slice type '[]i32' |
test/cases/compile_errors/dereference_unknown_length_pointer.zig created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | export fn entry(x: [*]i32) i32 { | |
| 2 | return x.*; | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage2 | |
| 7 | // target=native | |
| 8 | // | |
| 9 | // :2:13: error: index syntax required for unknown-length pointer type '[*]i32' |
test/cases/compile_errors/discarding_error_value.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | export fn entry() void { | |
| 2 | _ = foo(); | |
| 3 | } | |
| 4 | fn foo() !void { | |
| 5 | return error.OutOfMemory; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage2 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // :2:12: error: error is discarded. consider using `try`, `catch`, or `if` |
test/cases/compile_errors/division_by_zero.zig created+17| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | const lit_int_x = 1 / 0; | |
| 2 | const lit_float_x = 1.0 / 0.0; | |
| 3 | const int_x = @as(u32, 1) / @as(u32, 0); | |
| 4 | const float_x = @as(f32, 1.0) / @as(f32, 0.0); | |
| 5 | ||
| 6 | export fn entry1() usize { return @sizeOf(@TypeOf(lit_int_x)); } | |
| 7 | export fn entry2() usize { return @sizeOf(@TypeOf(lit_float_x)); } | |
| 8 | export fn entry3() usize { return @sizeOf(@TypeOf(int_x)); } | |
| 9 | export fn entry4() usize { return @sizeOf(@TypeOf(float_x)); } // no error on purpose | |
| 10 | ||
| 11 | // error | |
| 12 | // backend=stage2 | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // :1:23: error: division by zero here causes undefined behavior | |
| 16 | // :2:27: error: division by zero here causes undefined behavior | |
| 17 | // :3:29: error: division by zero here causes undefined behavior |
test/cases/compile_errors/duplicate_enum_field.zig created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | const Foo = enum { | |
| 2 | Bar, | |
| 3 | Bar, | |
| 4 | }; | |
| 5 | ||
| 6 | export fn entry() void { | |
| 7 | const a: Foo = undefined; | |
| 8 | _ = a; | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // backend=stage2 | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // :3:5: error: duplicate enum field 'Bar' | |
| 16 | // :2:5: note: other field here |
test/cases/compile_errors/duplicate_error_in_switch.zig created+22| ... | ... | @@ -0,0 +1,22 @@ |
| 1 | export fn entry() void { | |
| 2 | foo(452) catch |err| switch (err) { | |
| 3 | error.Foo => {}, | |
| 4 | error.Bar => {}, | |
| 5 | error.Foo => {}, | |
| 6 | else => {}, | |
| 7 | }; | |
| 8 | } | |
| 9 | fn foo(x: i32) !void { | |
| 10 | switch (x) { | |
| 11 | 0 ... 10 => return error.Foo, | |
| 12 | 11 ... 20 => return error.Bar, | |
| 13 | else => {}, | |
| 14 | } | |
| 15 | } | |
| 16 | ||
| 17 | // error | |
| 18 | // backend=llvm | |
| 19 | // target=native | |
| 20 | // | |
| 21 | // :5:9: error: duplicate switch value | |
| 22 | // :3:9: note: other value here |
test/cases/compile_errors/error_not_handled_in_switch.zig created+21| ... | ... | @@ -0,0 +1,21 @@ |
| 1 | export fn entry() void { | |
| 2 | foo(452) catch |err| switch (err) { | |
| 3 | error.Foo => {}, | |
| 4 | }; | |
| 5 | } | |
| 6 | fn foo(x: i32) !void { | |
| 7 | switch (x) { | |
| 8 | 0 ... 10 => return error.Foo, | |
| 9 | 11 ... 20 => return error.Bar, | |
| 10 | 21 ... 30 => return error.Baz, | |
| 11 | else => {}, | |
| 12 | } | |
| 13 | } | |
| 14 | ||
| 15 | // error | |
| 16 | // backend=llvm | |
| 17 | // target=native | |
| 18 | // | |
| 19 | // :2:26: error: switch must handle all possibilities | |
| 20 | // :2:26: note: unhandled error value: 'error.Bar' | |
| 21 | // :2:26: note: unhandled error value: 'error.Baz' |
test/cases/compile_errors/explicitly_casting_non_tag_type_to_enum.zig created+18| ... | ... | @@ -0,0 +1,18 @@ |
| 1 | const Small = enum(u2) { | |
| 2 | One, | |
| 3 | Two, | |
| 4 | Three, | |
| 5 | Four, | |
| 6 | }; | |
| 7 | ||
| 8 | export fn entry() void { | |
| 9 | var y = @as(f32, 3); | |
| 10 | var x = @intToEnum(Small, y); | |
| 11 | _ = x; | |
| 12 | } | |
| 13 | ||
| 14 | // error | |
| 15 | // backend=stage2 | |
| 16 | // target=native | |
| 17 | // | |
| 18 | // :10:31: error: expected integer type, found 'f32' |
test/cases/compile_errors/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig created+17| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | const Foo = struct { | |
| 2 | a: i32, | |
| 3 | b: i32, | |
| 4 | }; | |
| 5 | const foo = Foo { .a = 1, .b = 2, }; | |
| 6 | ||
| 7 | comptime { | |
| 8 | const field_ptr = @intToPtr(*i32, 0x1234); | |
| 9 | const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr); | |
| 10 | _ = another_foo_ptr; | |
| 11 | } | |
| 12 | ||
| 13 | // error | |
| 14 | // backend=stage2 | |
| 15 | // target=native | |
| 16 | // | |
| 17 | // :9:55: error: pointer value not based on parent struct |
test/cases/compile_errors/fieldParentPtr-comptime_wrong_field_index.zig created+17| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | const Foo = struct { | |
| 2 | a: i32, | |
| 3 | b: i32, | |
| 4 | }; | |
| 5 | const foo = Foo { .a = 1, .b = 2, }; | |
| 6 | ||
| 7 | comptime { | |
| 8 | const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a); | |
| 9 | _ = another_foo_ptr; | |
| 10 | } | |
| 11 | ||
| 12 | // error | |
| 13 | // backend=stage2 | |
| 14 | // target=native | |
| 15 | // | |
| 16 | // :8:29: error: field 'b' has index '1' but pointer value is index '0' of struct 'tmp.Foo' | |
| 17 | // :1:13: note: struct declared here |
test/cases/compile_errors/fieldParentPtr-field_pointer_is_not_pointer.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | const Foo = extern struct { | |
| 2 | a: i32, | |
| 3 | }; | |
| 4 | export fn foo(a: i32) *Foo { | |
| 5 | return @fieldParentPtr(Foo, "a", a); | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage2 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // :5:38: error: expected pointer type, found 'i32' |
test/cases/compile_errors/field_access_of_opaque_type.zig created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | const MyType = opaque {}; | |
| 2 | ||
| 3 | export fn entry() bool { | |
| 4 | var x: i32 = 1; | |
| 5 | return bar(@ptrCast(*MyType, &x)); | |
| 6 | } | |
| 7 | ||
| 8 | fn bar(x: *MyType) bool { | |
| 9 | return x.blah; | |
| 10 | } | |
| 11 | ||
| 12 | // error | |
| 13 | // backend=stage2 | |
| 14 | // target=native | |
| 15 | // | |
| 16 | // :9:13: error: type '*tmp.MyType' does not support field access |
test/cases/compile_errors/field_access_of_slices.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | export fn entry() void { | |
| 2 | var slice: []i32 = undefined; | |
| 3 | const info = @TypeOf(slice).unknown; | |
| 4 | _ = info; | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage2 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // :3:32: error: type '[]i32' has no members | |
| 12 | // :3:32: note: slice values have 'len' and 'ptr' members |
test/cases/compile_errors/field_access_of_unknown_length_pointer.zig created+13| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | const Foo = extern struct { | |
| 2 | a: i32, | |
| 3 | }; | |
| 4 | ||
| 5 | export fn entry(foo: [*]Foo) void { | |
| 6 | foo.a += 1; | |
| 7 | } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage2 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // :6:8: error: type '[*]tmp.Foo' does not support field access |
test/cases/compile_errors/ignored_deferred_function_call.zig created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | export fn foo() void { | |
| 2 | defer bar(); | |
| 3 | } | |
| 4 | fn bar() anyerror!i32 { return 0; } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage2 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // :2:14: error: error is ignored. consider using `try`, `catch`, or `if` |
test/cases/compile_errors/ignored_expression_in_while_continuation.zig created+22| ... | ... | @@ -0,0 +1,22 @@ |
| 1 | export fn a() void { | |
| 2 | while (true) : (bad()) {} | |
| 3 | } | |
| 4 | export fn b() void { | |
| 5 | var x: anyerror!i32 = 1234; | |
| 6 | while (x) |_| : (bad()) {} else |_| {} | |
| 7 | } | |
| 8 | export fn c() void { | |
| 9 | var x: ?i32 = 1234; | |
| 10 | while (x) |_| : (bad()) {} | |
| 11 | } | |
| 12 | fn bad() anyerror!void { | |
| 13 | return error.Bad; | |
| 14 | } | |
| 15 | ||
| 16 | // error | |
| 17 | // backend=stage2 | |
| 18 | // target=native | |
| 19 | // | |
| 20 | // :2:24: error: error is ignored. consider using `try`, `catch`, or `if` | |
| 21 | // :6:25: error: error is ignored. consider using `try`, `catch`, or `if` | |
| 22 | // :10:25: error: error is ignored. consider using `try`, `catch`, or `if` |
test/cases/compile_errors/illegal_comparison_of_types.zig created+20| ... | ... | @@ -0,0 +1,20 @@ |
| 1 | fn bad_eql_1(a: []u8, b: []u8) bool { | |
| 2 | return a == b; | |
| 3 | } | |
| 4 | const EnumWithData = union(enum) { | |
| 5 | One: void, | |
| 6 | Two: i32, | |
| 7 | }; | |
| 8 | fn bad_eql_2(a: *const EnumWithData, b: *const EnumWithData) bool { | |
| 9 | return a.* == b.*; | |
| 10 | } | |
| 11 | ||
| 12 | export fn entry1() usize { return @sizeOf(@TypeOf(&bad_eql_1)); } | |
| 13 | export fn entry2() usize { return @sizeOf(@TypeOf(&bad_eql_2)); } | |
| 14 | ||
| 15 | // error | |
| 16 | // backend=stage2 | |
| 17 | // target=native | |
| 18 | // | |
| 19 | // :2:14: error: operator == not allowed for type '[]u8' | |
| 20 | // :9:16: error: operator == not allowed for type 'tmp.EnumWithData' |
test/cases/compile_errors/implicitly_casting_enum_to_tag_type.zig created+17| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | const Small = enum(u2) { | |
| 2 | One, | |
| 3 | Two, | |
| 4 | Three, | |
| 5 | Four, | |
| 6 | }; | |
| 7 | ||
| 8 | export fn entry() void { | |
| 9 | var x: u2 = Small.Two; | |
| 10 | _ = x; | |
| 11 | } | |
| 12 | ||
| 13 | // error | |
| 14 | // backend=stage2 | |
| 15 | // target=native | |
| 16 | // | |
| 17 | // :9:22: error: expected type 'u2', found 'tmp.Small' |
test/cases/compile_errors/incorrect_return_type.zig created+21| ... | ... | @@ -0,0 +1,21 @@ |
| 1 | pub export fn entry() void{ | |
| 2 | _ = foo(); | |
| 3 | } | |
| 4 | const A = struct { | |
| 5 | a: u32, | |
| 6 | }; | |
| 7 | fn foo() A { | |
| 8 | return bar(); | |
| 9 | } | |
| 10 | const B = struct { | |
| 11 | a: u32, | |
| 12 | }; | |
| 13 | fn bar() B { | |
| 14 | unreachable; | |
| 15 | } | |
| 16 | ||
| 17 | // error | |
| 18 | // backend=stage2 | |
| 19 | // target=native | |
| 20 | // | |
| 21 | // :8:16: error: expected type 'tmp.A', found 'tmp.B' |
test/cases/compile_errors/indexing_an_array_of_size_zero.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | const array = [_]u8{}; | |
| 2 | export fn foo() void { | |
| 3 | const pointer = &array[0]; | |
| 4 | _ = pointer; | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage2 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // :3:27: error: indexing into empty array is not allowed |
test/cases/compile_errors/indexing_an_array_of_size_zero_with_runtime_index.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | const array = [_]u8{}; | |
| 2 | export fn foo() void { | |
| 3 | var index: usize = 0; | |
| 4 | const pointer = &array[index]; | |
| 5 | _ = pointer; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage2 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // :4:27: error: indexing into empty array is not allowed |
test/cases/compile_errors/indexing_single-item_pointer.zig created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | export fn entry(ptr: *i32) i32 { | |
| 2 | return ptr[1]; | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage2 | |
| 7 | // target=native | |
| 8 | // | |
| 9 | // :2:15: error: element access of non-indexable type '*i32' |
test/cases/compile_errors/invalid_cast_from_integral_type_to_enum.zig created+17| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | const E = enum(usize) { One, Two }; | |
| 2 | ||
| 3 | export fn entry() void { | |
| 4 | foo(1); | |
| 5 | } | |
| 6 | ||
| 7 | fn foo(x: usize) void { | |
| 8 | switch (x) { | |
| 9 | E.One => {}, | |
| 10 | } | |
| 11 | } | |
| 12 | ||
| 13 | // error | |
| 14 | // backend=stage2 | |
| 15 | // target=native | |
| 16 | // | |
| 17 | // :9:10: error: expected type 'usize', found 'tmp.E' |
test/cases/compile_errors/invalid_deref_on_switch_target.zig created+17| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | comptime { | |
| 2 | var tile = Tile.Empty; | |
| 3 | switch (tile.*) { | |
| 4 | Tile.Empty => {}, | |
| 5 | Tile.Filled => {}, | |
| 6 | } | |
| 7 | } | |
| 8 | const Tile = enum { | |
| 9 | Empty, | |
| 10 | Filled, | |
| 11 | }; | |
| 12 | ||
| 13 | // error | |
| 14 | // backend=stage2 | |
| 15 | // target=native | |
| 16 | // | |
| 17 | // :3:17: error: cannot dereference non-pointer type 'tmp.Tile' |
test/cases/compile_errors/invalid_multiple_dereferences.zig created+19| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | export fn a() void { | |
| 2 | var box = Box{ .field = 0 }; | |
| 3 | box.*.field = 1; | |
| 4 | } | |
| 5 | export fn b() void { | |
| 6 | var box = Box{ .field = 0 }; | |
| 7 | var boxPtr = &box; | |
| 8 | boxPtr.*.*.field = 1; | |
| 9 | } | |
| 10 | pub const Box = struct { | |
| 11 | field: i32, | |
| 12 | }; | |
| 13 | ||
| 14 | // error | |
| 15 | // backend=stage2 | |
| 16 | // target=native | |
| 17 | // | |
| 18 | // :3:8: error: cannot dereference non-pointer type 'tmp.Box' | |
| 19 | // :8:13: error: cannot dereference non-pointer type 'tmp.Box' |
test/cases/compile_errors/runtime_indexing_comptime_array.zig+6-6| ... | ... | @@ -24,9 +24,9 @@ pub export fn entry3() void { |
| 24 | 24 | // target=native |
| 25 | 25 | // backend=stage2 |
| 26 | 26 | // |
| 27 | // :6:5: error: values of type '[2]fn() void' must be comptime known, but index value is runtime known | |
| 28 | // :6:5: note: use '*const fn() void' for a function pointer type | |
| 29 | // :13:5: error: values of type '[2]fn() void' must be comptime known, but index value is runtime known | |
| 30 | // :13:5: note: use '*const fn() void' for a function pointer type | |
| 31 | // :19:5: error: values of type '[2]fn() void' must be comptime known, but index value is runtime known | |
| 32 | // :19:5: note: use '*const fn() void' for a function pointer type | |
| 27 | // :7:10: error: values of type '[2]fn() void' must be comptime known, but index value is runtime known | |
| 28 | // :7:10: note: use '*const fn() void' for a function pointer type | |
| 29 | // :15:18: error: values of type '[2]fn() void' must be comptime known, but index value is runtime known | |
| 30 | // :15:17: note: use '*const fn() void' for a function pointer type | |
| 31 | // :21:19: error: values of type '[2]fn() void' must be comptime known, but index value is runtime known | |
| 32 | // :21:18: note: use '*const fn() void' for a function pointer type |
test/cases/compile_errors/stage1/comptime_ptrcast_of_zero-sized_type.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | fn foo() void { | |
| 2 | const node: struct {} = undefined; | |
| 3 | const vla_ptr = @ptrCast([*]const u8, &node); | |
| 4 | _ = vla_ptr; | |
| 5 | } | |
| 6 | comptime { foo(); } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:3:21: error: '*const struct:2:17' and '[*]const u8' do not have the same in-memory representation |
test/cases/compile_errors/stage1/deref_on_undefined_value.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | comptime { | |
| 2 | var a: *u8 = undefined; | |
| 3 | _ = a.*; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // tmp.zig:3:9: error: attempt to dereference undefined value |
test/cases/compile_errors/stage1/error_equality_but_sets_have_no_common_members.zig created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | const Set1 = error{A, C}; | |
| 2 | const Set2 = error{B, D}; | |
| 3 | export fn entry() void { | |
| 4 | foo(Set1.A); | |
| 5 | } | |
| 6 | fn foo(x: Set1) void { | |
| 7 | if (x == Set2.B) { | |
| 8 | ||
| 9 | } | |
| 10 | } | |
| 11 | ||
| 12 | // error | |
| 13 | // backend=stage1 | |
| 14 | // target=native | |
| 15 | // | |
| 16 | // tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors |
test/cases/compile_errors/stage1/implicit_cast_from_f64_to_f32.zig created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | var x: f64 = 1.0; | |
| 2 | var y: f32 = x; | |
| 3 | ||
| 4 | export fn entry() usize { return @sizeOf(@TypeOf(y)); } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // tmp.zig:2:14: error: expected type 'f32', found 'f64' |
test/cases/compile_errors/stage1/int_to_ptr_of_0_bits.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | export fn foo() void { | |
| 2 | var x: usize = 0x1000; | |
| 3 | var y: *void = @intToPtr(*void, x); | |
| 4 | _ = y; | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage1 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information |
test/cases/compile_errors/stage1/obj/assign_to_invalid_dereference.zig deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | 'a'.* = 1; | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage1 | |
| 7 | // target=native | |
| 8 | // | |
| 9 | // tmp.zig:2:8: error: attempt to dereference non-pointer type 'comptime_int' |
test/cases/compile_errors/stage1/obj/bitCast_to_enum_type.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | const y = @bitCast(enum(u32) { a, b }, @as(u32, 3)); | |
| 3 | _ = y; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // tmp.zig:2:24: error: cannot cast a value of type 'y' |
test/cases/compile_errors/stage1/obj/bogus_compile_var.zig deleted-8| ... | ... | @@ -1,8 +0,0 @@ |
| 1 | const x = @import("builtin").bogus; | |
| 2 | export fn entry() usize { return @sizeOf(@TypeOf(x)); } | |
| 3 | ||
| 4 | // error | |
| 5 | // backend=stage1 | |
| 6 | // target=native | |
| 7 | // | |
| 8 | // tmp.zig:1:29: error: container 'builtin' has no member called 'bogus' |
test/cases/compile_errors/stage1/obj/callconv_apcs_aapcs_aapcsvfp_on_unsupported_platform.zig deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | export fn entry1() callconv(.APCS) void {} | |
| 2 | export fn entry2() callconv(.AAPCS) void {} | |
| 3 | export fn entry3() callconv(.AAPCSVFP) void {} | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage1 | |
| 7 | // target=x86_64-linux-none | |
| 8 | // | |
| 9 | // tmp.zig:1:29: error: callconv 'APCS' is only available on ARM, not x86_64 | |
| 10 | // tmp.zig:2:29: error: callconv 'AAPCS' is only available on ARM, not x86_64 | |
| 11 | // tmp.zig:3:29: error: callconv 'AAPCSVFP' is only available on ARM, not x86_64 |
test/cases/compile_errors/stage1/obj/callconv_interrupt_on_unsupported_platform.zig deleted-7| ... | ... | @@ -1,7 +0,0 @@ |
| 1 | export fn entry() callconv(.Interrupt) void {} | |
| 2 | ||
| 3 | // error | |
| 4 | // backend=stage1 | |
| 5 | // target=aarch64-linux-none | |
| 6 | // | |
| 7 | // tmp.zig:1:28: error: callconv 'Interrupt' is only available on x86, x86_64, AVR, and MSP430, not aarch64 |
test/cases/compile_errors/stage1/obj/callconv_signal_on_unsupported_platform.zig deleted-7| ... | ... | @@ -1,7 +0,0 @@ |
| 1 | export fn entry() callconv(.Signal) void {} | |
| 2 | ||
| 3 | // error | |
| 4 | // backend=stage1 | |
| 5 | // target=x86_64-linux-none | |
| 6 | // | |
| 7 | // tmp.zig:1:28: error: callconv 'Signal' is only available on AVR, not x86_64 |
test/cases/compile_errors/stage1/obj/callconv_stdcall_fastcall_thiscall_on_unsupported_platform-0.zig deleted-23| ... | ... | @@ -1,23 +0,0 @@ |
| 1 | const F1 = fn () callconv(.Stdcall) void; | |
| 2 | const F2 = fn () callconv(.Fastcall) void; | |
| 3 | const F3 = fn () callconv(.Thiscall) void; | |
| 4 | export fn entry1() void { | |
| 5 | var a: F1 = undefined; | |
| 6 | _ = a; | |
| 7 | } | |
| 8 | export fn entry2() void { | |
| 9 | var a: F2 = undefined; | |
| 10 | _ = a; | |
| 11 | } | |
| 12 | export fn entry3() void { | |
| 13 | var a: F3 = undefined; | |
| 14 | _ = a; | |
| 15 | } | |
| 16 | ||
| 17 | // error | |
| 18 | // backend=stage1 | |
| 19 | // target=x86_64-linux-none | |
| 20 | // | |
| 21 | // tmp.zig:1:27: error: callconv 'Stdcall' is only available on x86, not x86_64 | |
| 22 | // tmp.zig:2:27: error: callconv 'Fastcall' is only available on x86, not x86_64 | |
| 23 | // tmp.zig:3:27: error: callconv 'Thiscall' is only available on x86, not x86_64 |
test/cases/compile_errors/stage1/obj/callconv_stdcall_fastcall_thiscall_on_unsupported_platform-1.zig deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | export fn entry1() callconv(.Stdcall) void {} | |
| 2 | export fn entry2() callconv(.Fastcall) void {} | |
| 3 | export fn entry3() callconv(.Thiscall) void {} | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage1 | |
| 7 | // target=x86_64-linux-none | |
| 8 | // | |
| 9 | // tmp.zig:1:29: error: callconv 'Stdcall' is only available on x86, not x86_64 | |
| 10 | // tmp.zig:2:29: error: callconv 'Fastcall' is only available on x86, not x86_64 | |
| 11 | // tmp.zig:3:29: error: callconv 'Thiscall' is only available on x86, not x86_64 |
test/cases/compile_errors/stage1/obj/callconv_vectorcall_on_unsupported_platform.zig deleted-7| ... | ... | @@ -1,7 +0,0 @@ |
| 1 | export fn entry() callconv(.Vectorcall) void {} | |
| 2 | ||
| 3 | // error | |
| 4 | // backend=stage1 | |
| 5 | // target=x86_64-linux-none | |
| 6 | // | |
| 7 | // tmp.zig:1:28: error: callconv 'Vectorcall' is only available on x86 and AArch64, not x86_64 |
test/cases/compile_errors/stage1/obj/compile-time_division_by_zero.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | comptime { | |
| 2 | const a: i32 = 1; | |
| 3 | const b: i32 = 0; | |
| 4 | const c = a / b; | |
| 5 | _ = c; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:4:17: error: division by zero |
test/cases/compile_errors/stage1/obj/compile-time_remainder_division_by_zero.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | comptime { | |
| 2 | const a: i32 = 1; | |
| 3 | const b: i32 = 0; | |
| 4 | const c = a % b; | |
| 5 | _ = c; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:4:17: error: division by zero |
test/cases/compile_errors/stage1/obj/compileLog_of_tagged_enum_doesnt_crash_the_compiler.zig deleted-17| ... | ... | @@ -1,17 +0,0 @@ |
| 1 | const Bar = union(enum(u32)) { | |
| 2 | X: i32 = 1 | |
| 3 | }; | |
| 4 | ||
| 5 | fn testCompileLog(x: Bar) void { | |
| 6 | @compileLog(x); | |
| 7 | } | |
| 8 | ||
| 9 | pub fn main () void { | |
| 10 | comptime testCompileLog(Bar{.X = 123}); | |
| 11 | } | |
| 12 | ||
| 13 | // error | |
| 14 | // backend=stage1 | |
| 15 | // target=native | |
| 16 | // | |
| 17 | // tmp.zig:6:5: error: found compile log statement |
test/cases/compile_errors/stage1/obj/compile_log.zig deleted-16| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | export fn foo() void { | |
| 2 | comptime bar(12, "hi",); | |
| 3 | } | |
| 4 | fn bar(a: i32, b: []const u8) void { | |
| 5 | @compileLog("begin",); | |
| 6 | @compileLog("a", a, "b", b); | |
| 7 | @compileLog("end",); | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage1 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // tmp.zig:5:5: error: found compile log statement | |
| 15 | // tmp.zig:6:5: error: found compile log statement | |
| 16 | // tmp.zig:7:5: error: found compile log statement |
test/cases/compile_errors/stage1/obj/compile_log_statement_inside_function_which_must_be_comptime_evaluated.zig deleted-14| ... | ... | @@ -1,14 +0,0 @@ |
| 1 | fn Foo(comptime T: type) type { | |
| 2 | @compileLog(@typeName(T)); | |
| 3 | return T; | |
| 4 | } | |
| 5 | export fn entry() void { | |
| 6 | _ = Foo(i32); | |
| 7 | _ = @typeName(Foo(i32)); | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage1 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // tmp.zig:2:5: error: found compile log statement |
test/cases/compile_errors/stage1/obj/compile_time_division_by_zero.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | const y = foo(0); | |
| 2 | fn foo(x: u32) u32 { | |
| 3 | return 1 / x; | |
| 4 | } | |
| 5 | ||
| 6 | export fn entry() usize { return @sizeOf(@TypeOf(y)); } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:3:14: error: division by zero |
test/cases/compile_errors/stage1/obj/comptime_ptrcast_of_zero-sized_type.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | fn foo() void { | |
| 2 | const node: struct {} = undefined; | |
| 3 | const vla_ptr = @ptrCast([*]const u8, &node); | |
| 4 | _ = vla_ptr; | |
| 5 | } | |
| 6 | comptime { foo(); } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:3:21: error: '*const struct:2:17' and '[*]const u8' do not have the same in-memory representation |
test/cases/compile_errors/stage1/obj/deref_slice_and_get_len_field.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | var a: []u8 = undefined; | |
| 3 | _ = a.*.len; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // tmp.zig:3:10: error: attempt to dereference non-pointer type '[]u8' |
test/cases/compile_errors/stage1/obj/dereference_an_array.zig deleted-14| ... | ... | @@ -1,14 +0,0 @@ |
| 1 | var s_buffer: [10]u8 = undefined; | |
| 2 | pub fn pass(in: []u8) []u8 { | |
| 3 | var out = &s_buffer; | |
| 4 | out.*.* = in[0]; | |
| 5 | return out.*[0..1]; | |
| 6 | } | |
| 7 | ||
| 8 | export fn entry() usize { return @sizeOf(@TypeOf(pass)); } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage1 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // tmp.zig:4:10: error: attempt to dereference non-pointer type '[10]u8' |
test/cases/compile_errors/stage1/obj/dereference_unknown_length_pointer.zig deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | export fn entry(x: [*]i32) i32 { | |
| 2 | return x.*; | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage1 | |
| 7 | // target=native | |
| 8 | // | |
| 9 | // tmp.zig:2:13: error: index syntax required for unknown-length pointer type '[*]i32' |
test/cases/compile_errors/stage1/obj/discarding_error_value.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | _ = foo(); | |
| 3 | } | |
| 4 | fn foo() !void { | |
| 5 | return error.OutOfMemory; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:2:12: error: error is discarded. consider using `try`, `catch`, or `if` |
test/cases/compile_errors/stage1/obj/division_by_zero.zig deleted-18| ... | ... | @@ -1,18 +0,0 @@ |
| 1 | const lit_int_x = 1 / 0; | |
| 2 | const lit_float_x = 1.0 / 0.0; | |
| 3 | const int_x = @as(u32, 1) / @as(u32, 0); | |
| 4 | const float_x = @as(f32, 1.0) / @as(f32, 0.0); | |
| 5 | ||
| 6 | export fn entry1() usize { return @sizeOf(@TypeOf(lit_int_x)); } | |
| 7 | export fn entry2() usize { return @sizeOf(@TypeOf(lit_float_x)); } | |
| 8 | export fn entry3() usize { return @sizeOf(@TypeOf(int_x)); } | |
| 9 | export fn entry4() usize { return @sizeOf(@TypeOf(float_x)); } | |
| 10 | ||
| 11 | // error | |
| 12 | // backend=stage1 | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // tmp.zig:1:21: error: division by zero | |
| 16 | // tmp.zig:2:25: error: division by zero | |
| 17 | // tmp.zig:3:27: error: division by zero | |
| 18 | // tmp.zig:4:31: error: division by zero |
test/cases/compile_errors/stage1/obj/duplicate_enum_field.zig deleted-16| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | const Foo = enum { | |
| 2 | Bar, | |
| 3 | Bar, | |
| 4 | }; | |
| 5 | ||
| 6 | export fn entry() void { | |
| 7 | const a: Foo = undefined; | |
| 8 | _ = a; | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // backend=stage1 | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // tmp.zig:3:5: error: duplicate enum field: 'Bar' | |
| 16 | // tmp.zig:2:5: note: other field here |
test/cases/compile_errors/stage1/obj/duplicate_error_in_switch.zig deleted-22| ... | ... | @@ -1,22 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | foo(452) catch |err| switch (err) { | |
| 3 | error.Foo => {}, | |
| 4 | error.Bar => {}, | |
| 5 | error.Foo => {}, | |
| 6 | else => {}, | |
| 7 | }; | |
| 8 | } | |
| 9 | fn foo(x: i32) !void { | |
| 10 | switch (x) { | |
| 11 | 0 ... 10 => return error.Foo, | |
| 12 | 11 ... 20 => return error.Bar, | |
| 13 | else => {}, | |
| 14 | } | |
| 15 | } | |
| 16 | ||
| 17 | // error | |
| 18 | // backend=stage1 | |
| 19 | // target=native | |
| 20 | // | |
| 21 | // tmp.zig:5:14: error: duplicate switch value: '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set.Foo' | |
| 22 | // tmp.zig:3:14: note: other value here |
test/cases/compile_errors/stage1/obj/error_equality_but_sets_have_no_common_members.zig deleted-16| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | const Set1 = error{A, C}; | |
| 2 | const Set2 = error{B, D}; | |
| 3 | export fn entry() void { | |
| 4 | foo(Set1.A); | |
| 5 | } | |
| 6 | fn foo(x: Set1) void { | |
| 7 | if (x == Set2.B) { | |
| 8 | ||
| 9 | } | |
| 10 | } | |
| 11 | ||
| 12 | // error | |
| 13 | // backend=stage1 | |
| 14 | // target=native | |
| 15 | // | |
| 16 | // tmp.zig:7:11: error: error sets 'Set1' and 'Set2' have no common errors |
test/cases/compile_errors/stage1/obj/error_not_handled_in_switch.zig deleted-20| ... | ... | @@ -1,20 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | foo(452) catch |err| switch (err) { | |
| 3 | error.Foo => {}, | |
| 4 | }; | |
| 5 | } | |
| 6 | fn foo(x: i32) !void { | |
| 7 | switch (x) { | |
| 8 | 0 ... 10 => return error.Foo, | |
| 9 | 11 ... 20 => return error.Bar, | |
| 10 | 21 ... 30 => return error.Baz, | |
| 11 | else => {}, | |
| 12 | } | |
| 13 | } | |
| 14 | ||
| 15 | // error | |
| 16 | // backend=stage1 | |
| 17 | // target=native | |
| 18 | // | |
| 19 | // tmp.zig:2:26: error: error.Baz not handled in switch | |
| 20 | // tmp.zig:2:26: error: error.Bar not handled in switch |
test/cases/compile_errors/stage1/obj/explicitly_casting_non_tag_type_to_enum.zig deleted-18| ... | ... | @@ -1,18 +0,0 @@ |
| 1 | const Small = enum(u2) { | |
| 2 | One, | |
| 3 | Two, | |
| 4 | Three, | |
| 5 | Four, | |
| 6 | }; | |
| 7 | ||
| 8 | export fn entry() void { | |
| 9 | var y = @as(f32, 3); | |
| 10 | var x = @intToEnum(Small, y); | |
| 11 | _ = x; | |
| 12 | } | |
| 13 | ||
| 14 | // error | |
| 15 | // backend=stage1 | |
| 16 | // target=native | |
| 17 | // | |
| 18 | // tmp.zig:10:31: error: expected integer type, found 'f32' |
test/cases/compile_errors/stage1/obj/fieldParentPtr-comptime_field_ptr_not_based_on_struct.zig deleted-17| ... | ... | @@ -1,17 +0,0 @@ |
| 1 | const Foo = struct { | |
| 2 | a: i32, | |
| 3 | b: i32, | |
| 4 | }; | |
| 5 | const foo = Foo { .a = 1, .b = 2, }; | |
| 6 | ||
| 7 | comptime { | |
| 8 | const field_ptr = @intToPtr(*i32, 0x1234); | |
| 9 | const another_foo_ptr = @fieldParentPtr(Foo, "b", field_ptr); | |
| 10 | _ = another_foo_ptr; | |
| 11 | } | |
| 12 | ||
| 13 | // error | |
| 14 | // backend=stage1 | |
| 15 | // target=native | |
| 16 | // | |
| 17 | // tmp.zig:9:55: error: pointer value not based on parent struct |
test/cases/compile_errors/stage1/obj/fieldParentPtr-comptime_wrong_field_index.zig deleted-16| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | const Foo = struct { | |
| 2 | a: i32, | |
| 3 | b: i32, | |
| 4 | }; | |
| 5 | const foo = Foo { .a = 1, .b = 2, }; | |
| 6 | ||
| 7 | comptime { | |
| 8 | const another_foo_ptr = @fieldParentPtr(Foo, "b", &foo.a); | |
| 9 | _ = another_foo_ptr; | |
| 10 | } | |
| 11 | ||
| 12 | // error | |
| 13 | // backend=stage1 | |
| 14 | // target=native | |
| 15 | // | |
| 16 | // tmp.zig:8:29: error: field 'b' has index 1 but pointer value is index 0 of struct 'Foo' |
test/cases/compile_errors/stage1/obj/fieldParentPtr-field_pointer_is_not_pointer.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | const Foo = extern struct { | |
| 2 | a: i32, | |
| 3 | }; | |
| 4 | export fn foo(a: i32) *Foo { | |
| 5 | return @fieldParentPtr(Foo, "a", a); | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:5:38: error: expected pointer, found 'i32' |
test/cases/compile_errors/stage1/obj/field_access_of_opaque_type.zig deleted-16| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | const MyType = opaque {}; | |
| 2 | ||
| 3 | export fn entry() bool { | |
| 4 | var x: i32 = 1; | |
| 5 | return bar(@ptrCast(*MyType, &x)); | |
| 6 | } | |
| 7 | ||
| 8 | fn bar(x: *MyType) bool { | |
| 9 | return x.blah; | |
| 10 | } | |
| 11 | ||
| 12 | // error | |
| 13 | // backend=stage1 | |
| 14 | // target=native | |
| 15 | // | |
| 16 | // tmp.zig:9:13: error: no member named 'blah' in opaque type 'MyType' |
test/cases/compile_errors/stage1/obj/field_access_of_slices.zig deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | var slice: []i32 = undefined; | |
| 3 | const info = @TypeOf(slice).unknown; | |
| 4 | _ = info; | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage1 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // tmp.zig:3:32: error: type 'type' does not support field access |
test/cases/compile_errors/stage1/obj/field_access_of_unknown_length_pointer.zig deleted-13| ... | ... | @@ -1,13 +0,0 @@ |
| 1 | const Foo = extern struct { | |
| 2 | a: i32, | |
| 3 | }; | |
| 4 | ||
| 5 | export fn entry(foo: [*]Foo) void { | |
| 6 | foo.a += 1; | |
| 7 | } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage1 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // tmp.zig:6:8: error: type '[*]Foo' does not support field access |
test/cases/compile_errors/stage1/obj/ignored_deferred_function_call.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | export fn foo() void { | |
| 2 | defer bar(); | |
| 3 | } | |
| 4 | fn bar() anyerror!i32 { return 0; } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // tmp.zig:2:14: error: error is ignored. consider using `try`, `catch`, or `if` |
test/cases/compile_errors/stage1/obj/ignored_expression_in_while_continuation.zig deleted-22| ... | ... | @@ -1,22 +0,0 @@ |
| 1 | export fn a() void { | |
| 2 | while (true) : (bad()) {} | |
| 3 | } | |
| 4 | export fn b() void { | |
| 5 | var x: anyerror!i32 = 1234; | |
| 6 | while (x) |_| : (bad()) {} else |_| {} | |
| 7 | } | |
| 8 | export fn c() void { | |
| 9 | var x: ?i32 = 1234; | |
| 10 | while (x) |_| : (bad()) {} | |
| 11 | } | |
| 12 | fn bad() anyerror!void { | |
| 13 | return error.Bad; | |
| 14 | } | |
| 15 | ||
| 16 | // error | |
| 17 | // backend=stage1 | |
| 18 | // target=native | |
| 19 | // | |
| 20 | // tmp.zig:2:24: error: error is ignored. consider using `try`, `catch`, or `if` | |
| 21 | // tmp.zig:6:25: error: error is ignored. consider using `try`, `catch`, or `if` | |
| 22 | // tmp.zig:10:25: error: error is ignored. consider using `try`, `catch`, or `if` |
test/cases/compile_errors/stage1/obj/illegal_comparison_of_types.zig deleted-20| ... | ... | @@ -1,20 +0,0 @@ |
| 1 | fn bad_eql_1(a: []u8, b: []u8) bool { | |
| 2 | return a == b; | |
| 3 | } | |
| 4 | const EnumWithData = union(enum) { | |
| 5 | One: void, | |
| 6 | Two: i32, | |
| 7 | }; | |
| 8 | fn bad_eql_2(a: *const EnumWithData, b: *const EnumWithData) bool { | |
| 9 | return a.* == b.*; | |
| 10 | } | |
| 11 | ||
| 12 | export fn entry1() usize { return @sizeOf(@TypeOf(bad_eql_1)); } | |
| 13 | export fn entry2() usize { return @sizeOf(@TypeOf(bad_eql_2)); } | |
| 14 | ||
| 15 | // error | |
| 16 | // backend=stage1 | |
| 17 | // target=native | |
| 18 | // | |
| 19 | // tmp.zig:2:14: error: operator not allowed for type '[]u8' | |
| 20 | // tmp.zig:9:16: error: operator not allowed for type 'EnumWithData' |
test/cases/compile_errors/stage1/obj/implicit_cast_from_f64_to_f32.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | var x: f64 = 1.0; | |
| 2 | var y: f32 = x; | |
| 3 | ||
| 4 | export fn entry() usize { return @sizeOf(@TypeOf(y)); } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // tmp.zig:2:14: error: expected type 'f32', found 'f64' |
test/cases/compile_errors/stage1/obj/implicitly_casting_enum_to_tag_type.zig deleted-17| ... | ... | @@ -1,17 +0,0 @@ |
| 1 | const Small = enum(u2) { | |
| 2 | One, | |
| 3 | Two, | |
| 4 | Three, | |
| 5 | Four, | |
| 6 | }; | |
| 7 | ||
| 8 | export fn entry() void { | |
| 9 | var x: u2 = Small.Two; | |
| 10 | _ = x; | |
| 11 | } | |
| 12 | ||
| 13 | // error | |
| 14 | // backend=stage1 | |
| 15 | // target=native | |
| 16 | // | |
| 17 | // tmp.zig:9:22: error: expected type 'u2', found 'Small' |
test/cases/compile_errors/stage1/obj/incorrect_return_type.zig deleted-21| ... | ... | @@ -1,21 +0,0 @@ |
| 1 | pub export fn entry() void{ | |
| 2 | _ = foo(); | |
| 3 | } | |
| 4 | const A = struct { | |
| 5 | a: u32, | |
| 6 | }; | |
| 7 | fn foo() A { | |
| 8 | return bar(); | |
| 9 | } | |
| 10 | const B = struct { | |
| 11 | a: u32, | |
| 12 | }; | |
| 13 | fn bar() B { | |
| 14 | unreachable; | |
| 15 | } | |
| 16 | ||
| 17 | // error | |
| 18 | // backend=stage1 | |
| 19 | // target=native | |
| 20 | // | |
| 21 | // tmp.zig:8:16: error: expected type 'A', found 'B' |
test/cases/compile_errors/stage1/obj/indexing_an_array_of_size_zero.zig deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | const array = [_]u8{}; | |
| 2 | export fn foo() void { | |
| 3 | const pointer = &array[0]; | |
| 4 | _ = pointer; | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage1 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // tmp.zig:3:27: error: accessing a zero length array is not allowed |
test/cases/compile_errors/stage1/obj/indexing_an_array_of_size_zero_with_runtime_index.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | const array = [_]u8{}; | |
| 2 | export fn foo() void { | |
| 3 | var index: usize = 0; | |
| 4 | const pointer = &array[index]; | |
| 5 | _ = pointer; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:4:27: error: accessing a zero length array is not allowed |
test/cases/compile_errors/stage1/obj/indexing_single-item_pointer.zig deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | export fn entry(ptr: *i32) i32 { | |
| 2 | return ptr[1]; | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage1 | |
| 7 | // target=native | |
| 8 | // | |
| 9 | // tmp.zig:2:15: error: index of single-item pointer |
test/cases/compile_errors/stage1/obj/int_to_ptr_of_0_bits.zig deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | export fn foo() void { | |
| 2 | var x: usize = 0x1000; | |
| 3 | var y: *void = @intToPtr(*void, x); | |
| 4 | _ = y; | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage1 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // tmp.zig:3:30: error: type '*void' has 0 bits and cannot store information |
test/cases/compile_errors/stage1/obj/invalid_cast_from_integral_type_to_enum.zig deleted-17| ... | ... | @@ -1,17 +0,0 @@ |
| 1 | const E = enum(usize) { One, Two }; | |
| 2 | ||
| 3 | export fn entry() void { | |
| 4 | foo(1); | |
| 5 | } | |
| 6 | ||
| 7 | fn foo(x: usize) void { | |
| 8 | switch (x) { | |
| 9 | E.One => {}, | |
| 10 | } | |
| 11 | } | |
| 12 | ||
| 13 | // error | |
| 14 | // backend=stage1 | |
| 15 | // target=native | |
| 16 | // | |
| 17 | // tmp.zig:9:10: error: expected type 'usize', found 'E' |
test/cases/compile_errors/stage1/obj/invalid_deref_on_switch_target.zig deleted-17| ... | ... | @@ -1,17 +0,0 @@ |
| 1 | comptime { | |
| 2 | var tile = Tile.Empty; | |
| 3 | switch (tile.*) { | |
| 4 | Tile.Empty => {}, | |
| 5 | Tile.Filled => {}, | |
| 6 | } | |
| 7 | } | |
| 8 | const Tile = enum { | |
| 9 | Empty, | |
| 10 | Filled, | |
| 11 | }; | |
| 12 | ||
| 13 | // error | |
| 14 | // backend=stage1 | |
| 15 | // target=native | |
| 16 | // | |
| 17 | // tmp.zig:3:17: error: attempt to dereference non-pointer type 'Tile' |
test/cases/compile_errors/stage1/obj/invalid_multiple_dereferences.zig deleted-19| ... | ... | @@ -1,19 +0,0 @@ |
| 1 | export fn a() void { | |
| 2 | var box = Box{ .field = 0 }; | |
| 3 | box.*.field = 1; | |
| 4 | } | |
| 5 | export fn b() void { | |
| 6 | var box = Box{ .field = 0 }; | |
| 7 | var boxPtr = &box; | |
| 8 | boxPtr.*.*.field = 1; | |
| 9 | } | |
| 10 | pub const Box = struct { | |
| 11 | field: i32, | |
| 12 | }; | |
| 13 | ||
| 14 | // error | |
| 15 | // backend=stage1 | |
| 16 | // target=native | |
| 17 | // | |
| 18 | // tmp.zig:3:8: error: attempt to dereference non-pointer type 'Box' | |
| 19 | // tmp.zig:8:13: error: attempt to dereference non-pointer type 'Box' |
test/cases/compile_errors/stage1/obj/take_slice_of_invalid_dereference.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | const x = 'a'.*[0..]; | |
| 3 | _ = x; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // tmp.zig:2:18: error: attempt to dereference non-pointer type 'comptime_int' |
test/cases/compile_errors/take_slice_of_invalid_dereference.zig created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | export fn entry() void { | |
| 2 | const x = 'a'.*[0..]; | |
| 3 | _ = x; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage2 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // :2:18: error: cannot dereference non-pointer type 'comptime_int' |
test/stage2/cbe.zig+2-2| ... | ... | @@ -729,8 +729,8 @@ pub fn addCases(ctx: *TestContext) !void { |
| 729 | 729 | \\ _ = E1.a; |
| 730 | 730 | \\} |
| 731 | 731 | , &.{ |
| 732 | ":1:28: error: duplicate enum tag", | |
| 733 | ":1:22: note: other tag here", | |
| 732 | ":1:28: error: duplicate enum field 'b'", | |
| 733 | ":1:22: note: other field here", | |
| 734 | 734 | }); |
| 735 | 735 | |
| 736 | 736 | case.addError( |