authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-06-30 23:59:39+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-01 10:22:26+03:00
log2029601cb2ad4a6e9c8b260eec68de881d46735b
tree1c8573a9b47a9432a8e3f8d7574355243309b064
parenta6bf8c2593ae6e60d4c4804d4e9fd87fe29885ed

AstGen: use elem_{ptr,val}_node for array access syntax


28 files changed, 212 insertions(+), 209 deletions(-)

src/AstGen.zig+13-12
......@@ -5154,16 +5154,14 @@ fn arrayAccess(
51545154 const tree = astgen.tree;
51555155 const node_datas = tree.nodes.items(.data);
51565156 switch (rl) {
5157 .ref => return gz.addBin(
5158 .elem_ptr,
5159 try expr(gz, scope, .ref, node_datas[node].lhs),
5160 try expr(gz, scope, .{ .ty = .usize_type }, node_datas[node].rhs),
5161 ),
5162 else => return rvalue(gz, rl, try gz.addBin(
5163 .elem_val,
5164 try expr(gz, scope, .none, node_datas[node].lhs),
5165 try expr(gz, scope, .{ .coerced_ty = .usize_type }, node_datas[node].rhs),
5166 ), 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),
51675165 }
51685166}
51695167
......@@ -5685,7 +5683,7 @@ fn whileExpr(
56855683 try then_scope.addDbgVar(.dbg_var_val, some, dbg_var_inst);
56865684 }
56875685 if (while_full.ast.cont_expr != 0) {
5688 _ = 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);
56895687 }
56905688 try then_scope.addDbgBlockEnd();
56915689 const repeat_tag: Zir.Inst.Tag = if (is_inline) .repeat_inline else .repeat;
......@@ -5890,7 +5888,10 @@ fn forExpr(
58905888 if (!mem.eql(u8, value_name, "_")) {
58915889 const name_str_index = try astgen.identAsString(ident);
58925890 const tag: Zir.Inst.Tag = if (is_ptr) .elem_ptr else .elem_val;
5893 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 });
58945895 try astgen.detectLocalShadowing(&then_scope.base, name_str_index, ident, value_name);
58955896 payload_val_scope = .{
58965897 .parent = &then_scope.base,
src/Sema.zig+21-18
......@@ -2738,6 +2738,7 @@ fn ensureResultUsed(
27382738 const operand_ty = sema.typeOf(operand);
27392739 switch (operand_ty.zigTypeTag()) {
27402740 .Void, .NoReturn => return,
2741 .ErrorSet, .ErrorUnion => return sema.fail(block, src, "error is ignored. consider using `try`, `catch`, or `if`", .{}),
27412742 else => return sema.fail(block, src, "expression value is ignored", .{}),
27422743 }
27432744}
......@@ -2751,7 +2752,7 @@ fn zirEnsureResultNonError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
27512752 const src = inst_data.src();
27522753 const operand_ty = sema.typeOf(operand);
27532754 switch (operand_ty.zigTypeTag()) {
2754 .ErrorSet, .ErrorUnion => return sema.fail(block, src, "error is discardederror is discarded. consider using `try`, `catch`, or `if`", .{}),
2755 .ErrorSet, .ErrorUnion => return sema.fail(block, src, "error is discarded. consider using `try`, `catch`, or `if`", .{}),
27552756 else => return,
27562757 }
27572758}
......@@ -7092,7 +7093,7 @@ fn funcCommon(
70927093 const param_types = try sema.arena.alloc(Type, block.params.items.len);
70937094 const comptime_params = try sema.arena.alloc(bool, block.params.items.len);
70947095 for (block.params.items) |param, i| {
7095 const param_src = LazySrcLoc.nodeOffset(src_node_offset); // TODO better src
7096 const param_src = LazySrcLoc.nodeOffset(src_node_offset); // TODO better soruce location
70967097 param_types[i] = param.ty;
70977098 comptime_params[i] = param.is_comptime or
70987099 try sema.typeRequiresComptime(block, param_src, param.ty);
......@@ -7798,12 +7799,12 @@ fn zirElemVal(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
77987799 const tracy = trace(@src());
77997800 defer tracy.end();
78007801
7801 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
7802 const src = sema.src; // TODO better source location
7803 const elem_index_src = sema.src; // TODO better source location
7804 const array = try sema.resolveInst(bin_inst.lhs);
7805 const elem_index = try sema.resolveInst(bin_inst.rhs);
7806 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);
78077808}
78087809
78097810fn zirElemValNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -7823,10 +7824,12 @@ fn zirElemPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
78237824 const tracy = trace(@src());
78247825 defer tracy.end();
78257826
7826 const bin_inst = sema.code.instructions.items(.data)[inst].bin;
7827 const array_ptr = try sema.resolveInst(bin_inst.lhs);
7828 const elem_index = try sema.resolveInst(bin_inst.rhs);
7829 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);
78307833}
78317834
78327835fn zirElemPtrNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -19454,7 +19457,7 @@ fn tupleFieldPtr(
1945419457 const tuple_fields = tuple_ty.tupleFields();
1945519458
1945619459 if (tuple_fields.types.len == 0) {
19457 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", .{});
1945819461 }
1945919462
1946019463 if (field_index >= tuple_fields.types.len) {
......@@ -19497,7 +19500,7 @@ fn tupleField(
1949719500 const tuple_fields = tuple_ty.tupleFields();
1949819501
1949919502 if (tuple_fields.types.len == 0) {
19500 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", .{});
1950119504 }
1950219505
1950319506 if (field_index >= tuple_fields.types.len) {
......@@ -19538,7 +19541,7 @@ fn elemValArray(
1953819541 const elem_ty = array_ty.childType();
1953919542
1954019543 if (array_len_s == 0) {
19541 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", .{});
1954219545 }
1954319546
1954419547 const maybe_undef_array_val = try sema.resolveMaybeUndefVal(block, array_src, array);
......@@ -19618,7 +19621,7 @@ fn elemPtrArray(
1961819621 const array_len_s = array_len + @boolToInt(array_sent);
1961919622
1962019623 if (array_len_s == 0) {
19621 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", .{});
1962219625 }
1962319626
1962419627 const maybe_undef_array_ptr_val = try sema.resolveMaybeUndefVal(block, array_ptr_src, array_ptr);
......@@ -19700,7 +19703,7 @@ fn elemValSlice(
1970019703 const slice_len = slice_val.sliceLen(sema.mod);
1970119704 const slice_len_s = slice_len + @boolToInt(slice_sent);
1970219705 if (slice_len_s == 0) {
19703 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", .{});
1970419707 }
1970519708 if (maybe_index_val) |index_val| {
1970619709 const index = @intCast(usize, index_val.toUnsignedInt(target));
......@@ -19757,7 +19760,7 @@ fn elemPtrSlice(
1975719760 const slice_len = slice_val.sliceLen(sema.mod);
1975819761 const slice_len_s = slice_len + @boolToInt(slice_sent);
1975919762 if (slice_len_s == 0) {
19760 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", .{});
1976119764 }
1976219765 if (offset) |index| {
1976319766 if (index >= slice_len_s) {
src/Zir.zig+9-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,
......@@ -1627,10 +1626,10 @@ pub const Inst = struct {
16271626 .decl_val = .str_tok,
16281627 .load = .un_node,
16291628 .div = .pl_node,
1630 .elem_ptr = .bin,
1629 .elem_ptr = .pl_node,
16311630 .elem_ptr_node = .pl_node,
16321631 .elem_ptr_imm = .pl_node,
1633 .elem_val = .bin,
1632 .elem_val = .pl_node,
16341633 .elem_val_node = .pl_node,
16351634 .ensure_result_used = .un_node,
16361635 .ensure_result_non_error = .un_node,
src/print_zir.zig+2-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,
......@@ -355,6 +353,8 @@ const Writer = struct {
355353 .minimum,
356354 .elem_ptr_node,
357355 .elem_val_node,
356 .elem_ptr,
357 .elem_val,
358358 .coerce_result_ptr,
359359 => try self.writePlNodeBin(stream, inst),
360360
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/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/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/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/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'