authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-01 17:29:18-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-07-01 17:29:18-04:00
log7e2eb1326ba267012d47aa2eda539f01963d4d6b
tree61c165bea75319123ffec3412fb722bc1700147f
parentb79884eaf003ad32e800213c20da5c6b8935af34
parent2029601cb2ad4a6e9c8b260eec68de881d46735b
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #11973 from Vexu/stage2-compile-errors

more stage2 compile error fixes

104 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 {
8282 var d = dest.?;
8383 var n = len;
8484 while (true) {
85 d.* = c;
85 d[0] = c;
8686 n -= 1;
8787 if (n == 0) break;
8888 d += 1;
lib/std/os.zig+1-1
......@@ -1868,7 +1868,7 @@ pub fn getenv(key: []const u8) ?[]const u8 {
18681868 }
18691869 // Search the entire `environ` because we don't have a null terminated pointer.
18701870 var ptr = std.c.environ;
1871 while (ptr.*) |line| : (ptr += 1) {
1871 while (ptr[0]) |line| : (ptr += 1) {
18721872 var line_i: usize = 0;
18731873 while (line[line_i] != 0 and line[line_i] != '=') : (line_i += 1) {}
18741874 const this_key = line[0..line_i];
lib/std/process.zig+1-1
......@@ -313,7 +313,7 @@ pub fn getEnvMap(allocator: Allocator) !EnvMap {
313313 return result;
314314 } else if (builtin.link_libc) {
315315 var ptr = std.c.environ;
316 while (ptr.*) |line| : (ptr += 1) {
316 while (ptr[0]) |line| : (ptr += 1) {
317317 var line_i: usize = 0;
318318 while (line[line_i] != 0 and line[line_i] != '=') : (line_i += 1) {}
319319 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
812812
813813 .deref => {
814814 const lhs = try expr(gz, scope, .none, node_datas[node].lhs);
815 _ = try gz.addUnTok(.validate_deref, lhs, main_tokens[node]);
815816 switch (rl) {
816817 .ref => return lhs,
817818 else => {
......@@ -2500,6 +2501,7 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner
25002501 .memset,
25012502 .validate_array_init_ty,
25022503 .validate_struct_init_ty,
2504 .validate_deref,
25032505 => break :b true,
25042506 }
25052507 } else switch (maybe_unused_result) {
......@@ -5152,16 +5154,14 @@ fn arrayAccess(
51525154 const tree = astgen.tree;
51535155 const node_datas = tree.nodes.items(.data);
51545156 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),
51655165 }
51665166}
51675167
......@@ -5683,7 +5683,7 @@ fn whileExpr(
56835683 try then_scope.addDbgVar(.dbg_var_val, some, dbg_var_inst);
56845684 }
56855685 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);
56875687 }
56885688 try then_scope.addDbgBlockEnd();
56895689 const repeat_tag: Zir.Inst.Tag = if (is_inline) .repeat_inline else .repeat;
......@@ -5888,7 +5888,10 @@ fn forExpr(
58885888 if (!mem.eql(u8, value_name, "_")) {
58895889 const name_str_index = try astgen.identAsString(ident);
58905890 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 });
58925895 try astgen.detectLocalShadowing(&then_scope.base, name_str_index, ident, value_name);
58935896 payload_val_scope = .{
58945897 .parent = &then_scope.base,
src/Sema.zig+147-39
......@@ -1080,6 +1080,11 @@ fn analyzeBodyInner(
10801080 i += 1;
10811081 continue;
10821082 },
1083 .validate_deref => {
1084 try sema.zirValidateDeref(block, inst);
1085 i += 1;
1086 continue;
1087 },
10831088 .@"export" => {
10841089 try sema.zirExport(block, inst);
10851090 i += 1;
......@@ -2434,9 +2439,9 @@ fn zirEnumDecl(
24342439 const field_src = enumFieldSrcLoc(sema.mod.declPtr(block.src_decl), tree.*, src.node_offset.x, field_i);
24352440 const other_tag_src = enumFieldSrcLoc(sema.mod.declPtr(block.src_decl), tree.*, src.node_offset.x, gop.index);
24362441 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});
24382443 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", .{});
24402445 break :msg msg;
24412446 };
24422447 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -2733,6 +2738,7 @@ fn ensureResultUsed(
27332738 const operand_ty = sema.typeOf(operand);
27342739 switch (operand_ty.zigTypeTag()) {
27352740 .Void, .NoReturn => return,
2741 .ErrorSet, .ErrorUnion => return sema.fail(block, src, "error is ignored. consider using `try`, `catch`, or `if`", .{}),
27362742 else => return sema.fail(block, src, "expression value is ignored", .{}),
27372743 }
27382744}
......@@ -2746,7 +2752,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
27462752 const src = inst_data.src();
27472753 const operand_ty = sema.typeOf(operand);
27482754 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`", .{}),
27502756 else => return,
27512757 }
27522758}
......@@ -3849,6 +3855,28 @@ fn zirValidateArrayInit(
38493855 }
38503856}
38513857
3858fn 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
38523880fn failWithBadMemberAccess(
38533881 sema: *Sema,
38543882 block: *Block,
......@@ -4272,7 +4300,8 @@ fn zirCompileLog(
42724300 }
42734301 try writer.print("\n", .{});
42744302
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);
42764305 if (!gop.found_existing) {
42774306 gop.value_ptr.* = src_node;
42784307 }
......@@ -6416,6 +6445,7 @@ fn zirIntToEnum(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
64166445 if (dest_ty.zigTypeTag() != .Enum) {
64176446 return sema.fail(block, dest_ty_src, "expected enum, found '{}'", .{dest_ty.fmt(sema.mod)});
64186447 }
6448 _ = try sema.checkIntType(block, operand_src, sema.typeOf(operand));
64196449
64206450 if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |int_val| {
64216451 if (dest_ty.isNonexhaustiveEnum()) {
......@@ -7007,6 +7037,7 @@ fn funcCommon(
70077037 noalias_bits: u32,
70087038) CompileError!Air.Inst.Ref {
70097039 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 };
70107041
70117042 var is_generic = bare_return_type.tag() == .generic_poison or
70127043 alignment == null or
......@@ -7062,7 +7093,7 @@ fn funcCommon(
70627093 const param_types = try sema.arena.alloc(Type, block.params.items.len);
70637094 const comptime_params = try sema.arena.alloc(bool, block.params.items.len);
70647095 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
70667097 param_types[i] = param.ty;
70677098 comptime_params[i] = param.is_comptime or
70687099 try sema.typeRequiresComptime(block, param_src, param.ty);
......@@ -7109,6 +7140,45 @@ fn funcCommon(
71097140 const cc_workaround = cc orelse .Unspecified;
71107141 const align_workaround = alignment orelse 0;
71117142
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
71127182 break :fn_ty try Type.Tag.function.create(sema.arena, .{
71137183 .param_types = param_types,
71147184 .comptime_params = comptime_params.ptr,
......@@ -7617,11 +7687,11 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
76177687 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
76187688
76197689 const dest_ty = try sema.resolveType(block, dest_ty_src, extra.lhs);
7690 const operand = try sema.resolveInst(extra.rhs);
76207691 switch (dest_ty.zigTypeTag()) {
76217692 .AnyFrame,
76227693 .ComptimeFloat,
76237694 .ComptimeInt,
7624 .Enum,
76257695 .EnumLiteral,
76267696 .ErrorSet,
76277697 .ErrorUnion,
......@@ -7634,7 +7704,21 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
76347704 .Type,
76357705 .Undefined,
76367706 .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 },
76387722
76397723 .Pointer => return sema.fail(block, dest_ty_src, "cannot @bitCast to '{}', use @ptrCast to cast to a pointer", .{
76407724 dest_ty.fmt(sema.mod),
......@@ -7658,8 +7742,6 @@ fn zirBitcast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
76587742 .Vector,
76597743 => {},
76607744 }
7661
7662 const operand = try sema.resolveInst(extra.rhs);
76637745 return sema.bitCast(block, dest_ty, operand, operand_src);
76647746}
76657747
......@@ -7717,12 +7799,12 @@ fn zirElemVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
77177799 const tracy = trace(@src());
77187800 defer tracy.end();
77197801
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);
77267808}
77277809
77287810fn 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
77427824 const tracy = trace(@src());
77437825 defer tracy.end();
77447826
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);
77497833}
77507834
77517835fn 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
82978381 block,
82988382 src,
82998383 msg,
8300 "unhandled error value: error.{s}",
8384 "unhandled error value: 'error.{s}'",
83018385 .{error_name},
83028386 );
83038387 }
83048388 }
83058389
83068390 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);
83138393 return sema.failWithOwnedErrorMsg(block, msg);
83148394 }
83158395
......@@ -17062,9 +17142,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
1706217142 const field_index = struct_obj.fields.getIndex(field_name) orelse
1706317143 return sema.failWithBadStructFieldAccess(block, struct_obj, name_src, field_name);
1706417144
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);
1706817146 const field = struct_obj.fields.values()[field_index];
1706917147 const field_ptr_ty_info = field_ptr_ty.ptrInfo().data;
1707017148
......@@ -17087,8 +17165,29 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
1708717165 const result_ptr = try Type.ptr(sema.arena, sema.mod, ptr_ty_data);
1708817166
1708917167 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);
1709217191 }
1709317192
1709417193 try sema.requireRuntimeBlock(block, src);
......@@ -18434,7 +18533,16 @@ fn fieldVal(
1843418533 kw_name, child_type.fmt(sema.mod), field_name,
1843518534 });
1843618535 },
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 },
1843818546 }
1843918547 },
1844018548 .Struct => if (is_pointer_to) {
......@@ -18658,7 +18766,7 @@ fn fieldPtr(
1865818766 },
1865918767 else => {},
1866018768 }
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)});
1866218770}
1866318771
1866418772fn fieldCallBind(
......@@ -19349,7 +19457,7 @@ fn tupleFieldPtr(
1934919457 const tuple_fields = tuple_ty.tupleFields();
1935019458
1935119459 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", .{});
1935319461 }
1935419462
1935519463 if (field_index >= tuple_fields.types.len) {
......@@ -19392,7 +19500,7 @@ fn tupleField(
1939219500 const tuple_fields = tuple_ty.tupleFields();
1939319501
1939419502 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", .{});
1939619504 }
1939719505
1939819506 if (field_index >= tuple_fields.types.len) {
......@@ -19433,7 +19541,7 @@ fn elemValArray(
1943319541 const elem_ty = array_ty.childType();
1943419542
1943519543 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", .{});
1943719545 }
1943819546
1943919547 const maybe_undef_array_val = try sema.resolveMaybeUndefVal(block, array_src, array);
......@@ -19513,7 +19621,7 @@ fn elemPtrArray(
1951319621 const array_len_s = array_len + @boolToInt(array_sent);
1951419622
1951519623 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", .{});
1951719625 }
1951819626
1951919627 const maybe_undef_array_ptr_val = try sema.resolveMaybeUndefVal(block, array_ptr_src, array_ptr);
......@@ -19595,7 +19703,7 @@ fn elemValSlice(
1959519703 const slice_len = slice_val.sliceLen(sema.mod);
1959619704 const slice_len_s = slice_len + @boolToInt(slice_sent);
1959719705 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", .{});
1959919707 }
1960019708 if (maybe_index_val) |index_val| {
1960119709 const index = @intCast(usize, index_val.toUnsignedInt(target));
......@@ -19652,7 +19760,7 @@ fn elemPtrSlice(
1965219760 const slice_len = slice_val.sliceLen(sema.mod);
1965319761 const slice_len_s = slice_len + @boolToInt(slice_sent);
1965419762 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", .{});
1965619764 }
1965719765 if (offset) |index| {
1965819766 if (index >= slice_len_s) {
src/Zir.zig+15-10
......@@ -370,24 +370,23 @@ pub const Inst = struct {
370370 /// Uses the `pl_node` union field. Payload is `Bin`.
371371 div,
372372 /// 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.
377374 /// Uses the `pl_node` union field. AST node is a[b] syntax. Payload is `Bin`.
378375 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,
379379 /// Same as `elem_ptr_node` except the index is stored immediately rather than
380380 /// as a reference to another ZIR instruction.
381381 /// Uses the `pl_node` union field. AST node is an element inside array initialization
382382 /// syntax. Payload is `ElemPtrImm`.
383383 elem_ptr_imm,
384384 /// 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.
389385 /// Uses the `pl_node` union field. AST node is a[b] syntax. Payload is `Bin`.
390386 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,
391390 /// Emits a compile error if the operand is not `void`.
392391 /// Uses the `un_node` field.
393392 ensure_result_used,
......@@ -729,6 +728,9 @@ pub const Inst = struct {
729728 /// Same as `validate_array_init` but additionally communicates that the
730729 /// resulting array initialization value is within a comptime scope.
731730 validate_array_init_comptime,
731 /// Check that operand type supports the dereference operand (.*).
732 /// Uses the `un_tok` field.
733 validate_deref,
732734 /// A struct literal with a specified type, with no fields.
733735 /// Uses the `un_node` field.
734736 struct_init_empty,
......@@ -1156,6 +1158,7 @@ pub const Inst = struct {
11561158 .validate_struct_init_comptime,
11571159 .validate_array_init,
11581160 .validate_array_init_comptime,
1161 .validate_deref,
11591162 .struct_init_empty,
11601163 .struct_init,
11611164 .struct_init_ref,
......@@ -1309,6 +1312,7 @@ pub const Inst = struct {
13091312 .validate_struct_init_comptime,
13101313 .validate_array_init,
13111314 .validate_array_init_comptime,
1315 .validate_deref,
13121316 .@"export",
13131317 .export_value,
13141318 .set_cold,
......@@ -1622,10 +1626,10 @@ pub const Inst = struct {
16221626 .decl_val = .str_tok,
16231627 .load = .un_node,
16241628 .div = .pl_node,
1625 .elem_ptr = .bin,
1629 .elem_ptr = .pl_node,
16261630 .elem_ptr_node = .pl_node,
16271631 .elem_ptr_imm = .pl_node,
1628 .elem_val = .bin,
1632 .elem_val = .pl_node,
16291633 .elem_val_node = .pl_node,
16301634 .ensure_result_used = .un_node,
16311635 .ensure_result_non_error = .un_node,
......@@ -1709,6 +1713,7 @@ pub const Inst = struct {
17091713 .validate_struct_init_comptime = .pl_node,
17101714 .validate_array_init = .pl_node,
17111715 .validate_array_init_comptime = .pl_node,
1716 .validate_deref = .un_tok,
17121717 .struct_init_empty = .un_node,
17131718 .field_type = .pl_node,
17141719 .field_type_ref = .pl_node,
src/print_zir.zig+3-2
......@@ -144,8 +144,6 @@ const Writer = struct {
144144 switch (tag) {
145145 .array_type,
146146 .as,
147 .elem_ptr,
148 .elem_val,
149147 .store,
150148 .store_to_block_ptr,
151149 .store_to_inferred_ptr,
......@@ -242,6 +240,7 @@ const Writer = struct {
242240 .ret_tok,
243241 .ensure_err_payload_void,
244242 .closure_capture,
243 .validate_deref,
245244 => try self.writeUnTok(stream, inst),
246245
247246 .bool_br_and,
......@@ -354,6 +353,8 @@ const Writer = struct {
354353 .minimum,
355354 .elem_ptr_node,
356355 .elem_val_node,
356 .elem_ptr,
357 .elem_val,
357358 .coerce_result_ptr,
358359 => try self.writePlNodeBin(stream, inst),
359360
src/type.zig+1-1
......@@ -189,7 +189,7 @@ pub const Type = extern union {
189189 .Frame,
190190 => false,
191191
192 .Pointer => is_equality_cmp or ty.isCPtr(),
192 .Pointer => !ty.isSlice() and (is_equality_cmp or ty.isCPtr()),
193193 .Optional => {
194194 if (!is_equality_cmp) return false;
195195 var buf: Payload.ElemType = undefined;
test/cases/compile_errors/assign_to_invalid_dereference.zig created+9
......@@ -0,0 +1,9 @@
1export 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 @@
1export 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 @@
1const x = @import("builtin").bogus;
2export 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 @@
1export fn entry1() callconv(.APCS) void {}
2export fn entry2() callconv(.AAPCS) void {}
3export 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 @@
1export 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 @@
1export 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 @@
1const F1 = fn () callconv(.Stdcall) void;
2const F2 = fn () callconv(.Fastcall) void;
3const F3 = fn () callconv(.Thiscall) void;
4export fn entry1() void {
5 var a: F1 = undefined;
6 _ = a;
7}
8export fn entry2() void {
9 var a: F2 = undefined;
10 _ = a;
11}
12export 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 @@
1export 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 @@
1comptime {
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 @@
1comptime {
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 @@
1const Bar = union(enum(u32)) {
2 X: i32 = 1
3};
4
5fn testCompileLog(x: Bar) void {
6 @compileLog(x);
7}
8
9pub 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 @@
1export fn foo() void {
2 comptime bar(12, "hi",);
3}
4fn 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 @@
1fn Foo(comptime T: type) type {
2 @compileLog(@typeName(T));
3 return T;
4}
5export 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 @@
1const y = foo(0);
2fn foo(x: u32) u32 {
3 return 1 / x;
4}
5
6export 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 @@
1comptime {
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 @@
1export 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 @@
1var s_buffer: [10]u8 = undefined;
2pub fn pass(in: []u8) []u8 {
3 var out = &s_buffer;
4 out.*.* = in[0];
5 return out.*[0..1];
6}
7
8export 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 @@
1fn entry(x: []i32) i32 {
2 return x.*;
3}
4comptime {
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 @@
1export 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 @@
1export fn entry() void {
2 _ = foo();
3}
4fn 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 @@
1const lit_int_x = 1 / 0;
2const lit_float_x = 1.0 / 0.0;
3const int_x = @as(u32, 1) / @as(u32, 0);
4const float_x = @as(f32, 1.0) / @as(f32, 0.0);
5
6export fn entry1() usize { return @sizeOf(@TypeOf(lit_int_x)); }
7export fn entry2() usize { return @sizeOf(@TypeOf(lit_float_x)); }
8export fn entry3() usize { return @sizeOf(@TypeOf(int_x)); }
9export 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 @@
1const Foo = enum {
2 Bar,
3 Bar,
4};
5
6export 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 @@
1export fn entry() void {
2 foo(452) catch |err| switch (err) {
3 error.Foo => {},
4 error.Bar => {},
5 error.Foo => {},
6 else => {},
7 };
8}
9fn 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 @@
1export fn entry() void {
2 foo(452) catch |err| switch (err) {
3 error.Foo => {},
4 };
5}
6fn 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 @@
1const Small = enum(u2) {
2 One,
3 Two,
4 Three,
5 Four,
6};
7
8export 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 @@
1const Foo = struct {
2 a: i32,
3 b: i32,
4};
5const foo = Foo { .a = 1, .b = 2, };
6
7comptime {
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 @@
1const Foo = struct {
2 a: i32,
3 b: i32,
4};
5const foo = Foo { .a = 1, .b = 2, };
6
7comptime {
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 @@
1const Foo = extern struct {
2 a: i32,
3};
4export 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 @@
1const MyType = opaque {};
2
3export fn entry() bool {
4 var x: i32 = 1;
5 return bar(@ptrCast(*MyType, &x));
6}
7
8fn 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 @@
1export 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 @@
1const Foo = extern struct {
2 a: i32,
3};
4
5export 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 @@
1export fn foo() void {
2 defer bar();
3}
4fn 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 @@
1export fn a() void {
2 while (true) : (bad()) {}
3}
4export fn b() void {
5 var x: anyerror!i32 = 1234;
6 while (x) |_| : (bad()) {} else |_| {}
7}
8export fn c() void {
9 var x: ?i32 = 1234;
10 while (x) |_| : (bad()) {}
11}
12fn 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 @@
1fn bad_eql_1(a: []u8, b: []u8) bool {
2 return a == b;
3}
4const EnumWithData = union(enum) {
5 One: void,
6 Two: i32,
7};
8fn bad_eql_2(a: *const EnumWithData, b: *const EnumWithData) bool {
9 return a.* == b.*;
10}
11
12export fn entry1() usize { return @sizeOf(@TypeOf(&bad_eql_1)); }
13export 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 @@
1const Small = enum(u2) {
2 One,
3 Two,
4 Three,
5 Four,
6};
7
8export 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 @@
1const array = [_]u8{};
2export 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 @@
1const array = [_]u8{};
2export 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 @@
1export 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 @@
1const E = enum(usize) { One, Two };
2
3export fn entry() void {
4 foo(1);
5}
6
7fn 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 @@
1comptime {
2 var tile = Tile.Empty;
3 switch (tile.*) {
4 Tile.Empty => {},
5 Tile.Filled => {},
6 }
7}
8const 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 @@
1export fn a() void {
2 var box = Box{ .field = 0 };
3 box.*.field = 1;
4}
5export fn b() void {
6 var box = Box{ .field = 0 };
7 var boxPtr = &box;
8 boxPtr.*.*.field = 1;
9}
10pub 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 {
2424// target=native
2525// backend=stage2
2626//
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 @@
1fn foo() void {
2 const node: struct {} = undefined;
3 const vla_ptr = @ptrCast([*]const u8, &node);
4 _ = vla_ptr;
5}
6comptime { 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 @@
1comptime {
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 @@
1const Set1 = error{A, C};
2const Set2 = error{B, D};
3export fn entry() void {
4 foo(Set1.A);
5}
6fn 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 @@
1var x: f64 = 1.0;
2var y: f32 = x;
3
4export 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 @@
1export 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 @@
1export 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 @@
1export 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 @@
1const x = @import("builtin").bogus;
2export 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 @@
1export fn entry1() callconv(.APCS) void {}
2export fn entry2() callconv(.AAPCS) void {}
3export 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 @@
1export 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 @@
1export 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 @@
1const F1 = fn () callconv(.Stdcall) void;
2const F2 = fn () callconv(.Fastcall) void;
3const F3 = fn () callconv(.Thiscall) void;
4export fn entry1() void {
5 var a: F1 = undefined;
6 _ = a;
7}
8export fn entry2() void {
9 var a: F2 = undefined;
10 _ = a;
11}
12export 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 @@
1export fn entry1() callconv(.Stdcall) void {}
2export fn entry2() callconv(.Fastcall) void {}
3export 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 @@
1export 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 @@
1comptime {
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 @@
1comptime {
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 @@
1const Bar = union(enum(u32)) {
2 X: i32 = 1
3};
4
5fn testCompileLog(x: Bar) void {
6 @compileLog(x);
7}
8
9pub 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 @@
1export fn foo() void {
2 comptime bar(12, "hi",);
3}
4fn 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 @@
1fn Foo(comptime T: type) type {
2 @compileLog(@typeName(T));
3 return T;
4}
5export 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 @@
1const y = foo(0);
2fn foo(x: u32) u32 {
3 return 1 / x;
4}
5
6export 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 @@
1fn foo() void {
2 const node: struct {} = undefined;
3 const vla_ptr = @ptrCast([*]const u8, &node);
4 _ = vla_ptr;
5}
6comptime { 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 @@
1export 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 @@
1var s_buffer: [10]u8 = undefined;
2pub fn pass(in: []u8) []u8 {
3 var out = &s_buffer;
4 out.*.* = in[0];
5 return out.*[0..1];
6}
7
8export 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 @@
1export 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 @@
1export fn entry() void {
2 _ = foo();
3}
4fn 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 @@
1const lit_int_x = 1 / 0;
2const lit_float_x = 1.0 / 0.0;
3const int_x = @as(u32, 1) / @as(u32, 0);
4const float_x = @as(f32, 1.0) / @as(f32, 0.0);
5
6export fn entry1() usize { return @sizeOf(@TypeOf(lit_int_x)); }
7export fn entry2() usize { return @sizeOf(@TypeOf(lit_float_x)); }
8export fn entry3() usize { return @sizeOf(@TypeOf(int_x)); }
9export 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 @@
1const Foo = enum {
2 Bar,
3 Bar,
4};
5
6export 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 @@
1export fn entry() void {
2 foo(452) catch |err| switch (err) {
3 error.Foo => {},
4 error.Bar => {},
5 error.Foo => {},
6 else => {},
7 };
8}
9fn 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 @@
1const Set1 = error{A, C};
2const Set2 = error{B, D};
3export fn entry() void {
4 foo(Set1.A);
5}
6fn 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 @@
1export fn entry() void {
2 foo(452) catch |err| switch (err) {
3 error.Foo => {},
4 };
5}
6fn 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 @@
1const Small = enum(u2) {
2 One,
3 Two,
4 Three,
5 Four,
6};
7
8export 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 @@
1const Foo = struct {
2 a: i32,
3 b: i32,
4};
5const foo = Foo { .a = 1, .b = 2, };
6
7comptime {
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 @@
1const Foo = struct {
2 a: i32,
3 b: i32,
4};
5const foo = Foo { .a = 1, .b = 2, };
6
7comptime {
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 @@
1const Foo = extern struct {
2 a: i32,
3};
4export 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 @@
1const MyType = opaque {};
2
3export fn entry() bool {
4 var x: i32 = 1;
5 return bar(@ptrCast(*MyType, &x));
6}
7
8fn 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 @@
1export 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 @@
1const Foo = extern struct {
2 a: i32,
3};
4
5export 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 @@
1export fn foo() void {
2 defer bar();
3}
4fn 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 @@
1export fn a() void {
2 while (true) : (bad()) {}
3}
4export fn b() void {
5 var x: anyerror!i32 = 1234;
6 while (x) |_| : (bad()) {} else |_| {}
7}
8export fn c() void {
9 var x: ?i32 = 1234;
10 while (x) |_| : (bad()) {}
11}
12fn 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 @@
1fn bad_eql_1(a: []u8, b: []u8) bool {
2 return a == b;
3}
4const EnumWithData = union(enum) {
5 One: void,
6 Two: i32,
7};
8fn bad_eql_2(a: *const EnumWithData, b: *const EnumWithData) bool {
9 return a.* == b.*;
10}
11
12export fn entry1() usize { return @sizeOf(@TypeOf(bad_eql_1)); }
13export 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 @@
1var x: f64 = 1.0;
2var y: f32 = x;
3
4export 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 @@
1const Small = enum(u2) {
2 One,
3 Two,
4 Three,
5 Four,
6};
7
8export 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 @@
1const array = [_]u8{};
2export 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 @@
1const array = [_]u8{};
2export 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 @@
1export 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 @@
1export 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 @@
1const E = enum(usize) { One, Two };
2
3export fn entry() void {
4 foo(1);
5}
6
7fn 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 @@
1comptime {
2 var tile = Tile.Empty;
3 switch (tile.*) {
4 Tile.Empty => {},
5 Tile.Filled => {},
6 }
7}
8const 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 @@
1export fn a() void {
2 var box = Box{ .field = 0 };
3 box.*.field = 1;
4}
5export fn b() void {
6 var box = Box{ .field = 0 };
7 var boxPtr = &box;
8 boxPtr.*.*.field = 1;
9}
10pub 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 @@
1export 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 @@
1export 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 {
729729 \\ _ = E1.a;
730730 \\}
731731 , &.{
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",
734734 });
735735
736736 case.addError(