authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-12-03 00:42:11-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-12-03 00:42:11-05:00
logfdbb0fb7b9c08ebff1b7e45ef89f7160f350d44c
tree714f2766c64ace45df1f7d67ca70be0c88193184
parentc43ac67f82cb5a022df67729aa1e6bebc22cfff2
parentb500e0eb179218f5eb03408c09b5e5a928f0c46e
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #13744 from Vexu/stage2-fixes

Improve error messages, fix dependency loops

40 files changed, 378 insertions(+), 95 deletions(-)

lib/std/fs.zig-2
......@@ -809,8 +809,6 @@ pub const IterableDir = struct {
809809 // and we avoid the code complexity here.
810810 const w = os.wasi;
811811 start_over: while (true) {
812 // TODO https://github.com/ziglang/zig/issues/12498
813 _ = @sizeOf(w.dirent_t) + 1;
814812 // According to the WASI spec, the last entry might be truncated,
815813 // so we need to check if the left buffer contains the whole dirent.
816814 if (self.end_index - self.index < @sizeOf(w.dirent_t)) {
src/AstGen.zig+41-7
......@@ -2632,7 +2632,7 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
26322632 .compile_error,
26332633 .ret_node,
26342634 .ret_load,
2635 .ret_tok,
2635 .ret_implicit,
26362636 .ret_err_value,
26372637 .@"unreachable",
26382638 .repeat,
......@@ -3696,6 +3696,29 @@ fn fnDecl(
36963696 if (param.anytype_ellipsis3) |tok| {
36973697 return astgen.failTok(tok, "missing parameter name", .{});
36983698 } else {
3699 ambiguous: {
3700 if (tree.nodes.items(.tag)[param.type_expr] != .identifier) break :ambiguous;
3701 const main_token = tree.nodes.items(.main_token)[param.type_expr];
3702 const identifier_str = tree.tokenSlice(main_token);
3703 if (isPrimitive(identifier_str)) break :ambiguous;
3704 return astgen.failNodeNotes(
3705 param.type_expr,
3706 "missing parameter name or type",
3707 .{},
3708 &[_]u32{
3709 try astgen.errNoteNode(
3710 param.type_expr,
3711 "if this is a name, annotate its type '{s}: T'",
3712 .{identifier_str},
3713 ),
3714 try astgen.errNoteNode(
3715 param.type_expr,
3716 "if this is a type, give it a name '<name>: {s}'",
3717 .{identifier_str},
3718 ),
3719 },
3720 );
3721 }
36993722 return astgen.failNode(param.type_expr, "missing parameter name", .{});
37003723 }
37013724 } else 0;
......@@ -3891,9 +3914,8 @@ fn fnDecl(
38913914 // As our last action before the return, "pop" the error trace if needed
38923915 _ = try gz.addRestoreErrRetIndex(.ret, .always);
38933916
3894 // Since we are adding the return instruction here, we must handle the coercion.
3895 // We do this by using the `ret_tok` instruction.
3896 _ = try fn_gz.addUnTok(.ret_tok, .void_value, tree.lastToken(body_node));
3917 // Add implicit return at end of function.
3918 _ = try fn_gz.addUnTok(.ret_implicit, .void_value, tree.lastToken(body_node));
38973919 }
38983920
38993921 break :func try decl_gz.addFunc(.{
......@@ -4311,9 +4333,8 @@ fn testDecl(
43114333 // As our last action before the return, "pop" the error trace if needed
43124334 _ = try gz.addRestoreErrRetIndex(.ret, .always);
43134335
4314 // Since we are adding the return instruction here, we must handle the coercion.
4315 // We do this by using the `ret_tok` instruction.
4316 _ = try fn_block.addUnTok(.ret_tok, .void_value, tree.lastToken(body_node));
4336 // Add implicit return at end of function.
4337 _ = try fn_block.addUnTok(.ret_implicit, .void_value, tree.lastToken(body_node));
43174338 }
43184339
43194340 const func_inst = try decl_block.addFunc(.{
......@@ -5605,6 +5626,14 @@ fn simpleBinOp(
56055626 const tree = astgen.tree;
56065627 const node_datas = tree.nodes.items(.data);
56075628
5629 if (op_inst_tag == .cmp_neq or op_inst_tag == .cmp_eq) {
5630 const node_tags = tree.nodes.items(.tag);
5631 const str = if (op_inst_tag == .cmp_eq) "==" else "!=";
5632 if (node_tags[node_datas[node].lhs] == .string_literal or
5633 node_tags[node_datas[node].rhs] == .string_literal)
5634 return astgen.failNode(node, "cannot compare strings with {s}", .{str});
5635 }
5636
56085637 const lhs = try reachableExpr(gz, scope, .{ .rl = .none }, node_datas[node].lhs, node);
56095638 var line: u32 = undefined;
56105639 var column: u32 = undefined;
......@@ -6602,6 +6631,11 @@ fn switchExpr(
66026631 continue;
66036632 }
66046633
6634 for (case.ast.values) |val| {
6635 if (node_tags[val] == .string_literal)
6636 return astgen.failNode(val, "cannot switch on strings", .{});
6637 }
6638
66056639 if (case.ast.values.len == 1 and node_tags[case.ast.values[0]] != .switch_range) {
66066640 scalar_cases_len += 1;
66076641 } else {
src/Module.zig+2
......@@ -940,6 +940,7 @@ pub const Struct = struct {
940940 requires_comptime: PropertyBoolean = .unknown,
941941 have_field_inits: bool = false,
942942 is_tuple: bool,
943 assumed_runtime_bits: bool = false,
943944
944945 pub const Fields = std.StringArrayHashMapUnmanaged(Field);
945946
......@@ -1205,6 +1206,7 @@ pub const Union = struct {
12051206 fully_resolved,
12061207 },
12071208 requires_comptime: PropertyBoolean = .unknown,
1209 assumed_runtime_bits: bool = false,
12081210
12091211 pub const Field = struct {
12101212 /// undefined until `status` is `have_field_types` or `have_layout`.
src/Sema.zig+106-27
......@@ -291,8 +291,8 @@ pub const Block = struct {
291291 try sema.errNote(ci.block, ci.src, parent, prefix ++ "it is inside a @cImport", .{});
292292 },
293293 .comptime_ret_ty => |rt| {
294 const src_loc = if (try sema.funcDeclSrc(rt.func)) |capture| blk: {
295 var src_loc = capture;
294 const src_loc = if (try sema.funcDeclSrc(rt.func)) |fn_decl| blk: {
295 var src_loc = fn_decl.srcLoc();
296296 src_loc.lazy = .{ .node_offset_fn_type_ret_ty = 0 };
297297 break :blk src_loc;
298298 } else blk: {
......@@ -1098,7 +1098,7 @@ fn analyzeBodyInner(
10981098 // These functions match the return type of analyzeBody so that we can
10991099 // tail call them here.
11001100 .compile_error => break sema.zirCompileError(block, inst),
1101 .ret_tok => break sema.zirRetTok(block, inst),
1101 .ret_implicit => break sema.zirRetImplicit(block, inst),
11021102 .ret_node => break sema.zirRetNode(block, inst),
11031103 .ret_load => break sema.zirRetLoad(block, inst),
11041104 .ret_err_value => break sema.zirRetErrValue(block, inst),
......@@ -5843,7 +5843,7 @@ fn lookupInNamespace(
58435843 return null;
58445844}
58455845
5846fn funcDeclSrc(sema: *Sema, func_inst: Air.Inst.Ref) !?Module.SrcLoc {
5846fn funcDeclSrc(sema: *Sema, func_inst: Air.Inst.Ref) !?*Decl {
58475847 const func_val = (try sema.resolveMaybeUndefVal(func_inst)) orelse return null;
58485848 if (func_val.isUndef()) return null;
58495849 const owner_decl_index = switch (func_val.tag()) {
......@@ -5852,8 +5852,7 @@ fn funcDeclSrc(sema: *Sema, func_inst: Air.Inst.Ref) !?Module.SrcLoc {
58525852 .decl_ref => sema.mod.declPtr(func_val.castTag(.decl_ref).?.data).val.castTag(.function).?.data.owner_decl,
58535853 else => return null,
58545854 };
5855 const owner_decl = sema.mod.declPtr(owner_decl_index);
5856 return owner_decl.srcLoc();
5855 return sema.mod.declPtr(owner_decl_index);
58575856}
58585857
58595858pub fn analyzeSaveErrRetIndex(sema: *Sema, block: *Block) SemaError!Air.Inst.Ref {
......@@ -6031,7 +6030,7 @@ fn zirCall(
60316030 break :check_args;
60326031 }
60336032
6034 const decl_src = try sema.funcDeclSrc(func);
6033 const maybe_decl = try sema.funcDeclSrc(func);
60356034 const member_str = if (bound_arg_src != null) "member function " else "";
60366035 const variadic_str = if (func_ty_info.is_var_args) "at least " else "";
60376036 const msg = msg: {
......@@ -6048,7 +6047,7 @@ fn zirCall(
60486047 );
60496048 errdefer msg.destroy(sema.gpa);
60506049
6051 if (decl_src) |some| try sema.mod.errNoteNonLazy(some, msg, "function declared here", .{});
6050 if (maybe_decl) |fn_decl| try sema.mod.errNoteNonLazy(fn_decl.srcLoc(), msg, "function declared here", .{});
60526051 break :msg msg;
60536052 };
60546053 return sema.failWithOwnedErrorMsg(msg);
......@@ -6242,7 +6241,7 @@ fn analyzeCall(
62426241 const func_ty_info = func_ty.fnInfo();
62436242 const cc = func_ty_info.cc;
62446243 if (cc == .Naked) {
6245 const decl_src = try sema.funcDeclSrc(func);
6244 const maybe_decl = try sema.funcDeclSrc(func);
62466245 const msg = msg: {
62476246 const msg = try sema.errMsg(
62486247 block,
......@@ -6252,7 +6251,7 @@ fn analyzeCall(
62526251 );
62536252 errdefer msg.destroy(sema.gpa);
62546253
6255 if (decl_src) |some| try sema.mod.errNoteNonLazy(some, msg, "function declared here", .{});
6254 if (maybe_decl) |fn_decl| try sema.mod.errNoteNonLazy(fn_decl.srcLoc(), msg, "function declared here", .{});
62566255 break :msg msg;
62576256 };
62586257 return sema.failWithOwnedErrorMsg(msg);
......@@ -6488,6 +6487,7 @@ fn analyzeCall(
64886487 &should_memoize,
64896488 memoized_call_key,
64906489 func_ty_info.param_types,
6490 func,
64916491 ) catch |err| switch (err) {
64926492 error.NeededSourceLocation => {
64936493 _ = sema.inst_map.remove(inst);
......@@ -6504,6 +6504,7 @@ fn analyzeCall(
65046504 &should_memoize,
65056505 memoized_call_key,
65066506 func_ty_info.param_types,
6507 func,
65076508 );
65086509 return error.AnalysisFail;
65096510 },
......@@ -6646,12 +6647,17 @@ fn analyzeCall(
66466647 const args = try sema.arena.alloc(Air.Inst.Ref, uncasted_args.len);
66476648 for (uncasted_args) |uncasted_arg, i| {
66486649 if (i < fn_params_len) {
6650 const opts: CoerceOpts = .{ .param_src = .{
6651 .func_inst = func,
6652 .param_i = @intCast(u32, i),
6653 } };
66496654 const param_ty = func_ty.fnParamType(i);
66506655 args[i] = sema.analyzeCallArg(
66516656 block,
66526657 .unneeded,
66536658 param_ty,
66546659 uncasted_arg,
6660 opts,
66556661 ) catch |err| switch (err) {
66566662 error.NeededSourceLocation => {
66576663 const decl = sema.mod.declPtr(block.src_decl);
......@@ -6660,6 +6666,7 @@ fn analyzeCall(
66606666 Module.argSrc(call_src.node_offset.x, sema.gpa, decl, i, bound_arg_src),
66616667 param_ty,
66626668 uncasted_arg,
6669 opts,
66636670 );
66646671 return error.AnalysisFail;
66656672 },
......@@ -6741,6 +6748,7 @@ fn analyzeInlineCallArg(
67416748 should_memoize: *bool,
67426749 memoized_call_key: Module.MemoizedCall.Key,
67436750 raw_param_types: []const Type,
6751 func_inst: Air.Inst.Ref,
67446752) !void {
67456753 const zir_tags = sema.code.instructions.items(.tag);
67466754 switch (zir_tags[inst]) {
......@@ -6765,7 +6773,13 @@ fn analyzeInlineCallArg(
67656773 return err;
67666774 };
67676775 }
6768 const casted_arg = try sema.coerce(arg_block, param_ty, uncasted_arg, arg_src);
6776 const casted_arg = sema.coerceExtra(arg_block, param_ty, uncasted_arg, arg_src, .{ .param_src = .{
6777 .func_inst = func_inst,
6778 .param_i = @intCast(u32, arg_i.*),
6779 } }) catch |err| switch (err) {
6780 error.NotCoercible => unreachable,
6781 else => |e| return e,
6782 };
67696783
67706784 if (is_comptime_call) {
67716785 sema.inst_map.putAssumeCapacityNoClobber(inst, casted_arg);
......@@ -6855,9 +6869,13 @@ fn analyzeCallArg(
68556869 arg_src: LazySrcLoc,
68566870 param_ty: Type,
68576871 uncasted_arg: Air.Inst.Ref,
6872 opts: CoerceOpts,
68586873) !Air.Inst.Ref {
68596874 try sema.resolveTypeFully(param_ty);
6860 return sema.coerce(block, param_ty, uncasted_arg, arg_src);
6875 return sema.coerceExtra(block, param_ty, uncasted_arg, arg_src, opts) catch |err| switch (err) {
6876 error.NotCoercible => unreachable,
6877 else => |e| return e,
6878 };
68616879}
68626880
68636881fn analyzeGenericCallArg(
......@@ -16546,7 +16564,7 @@ fn zirRetErrValue(
1654616564 return sema.analyzeRet(block, result_inst, src);
1654716565}
1654816566
16549fn zirRetTok(
16567fn zirRetImplicit(
1655016568 sema: *Sema,
1655116569 block: *Block,
1655216570 inst: Zir.Inst.Index,
......@@ -16556,9 +16574,33 @@ fn zirRetTok(
1655616574
1655716575 const inst_data = sema.code.instructions.items(.data)[inst].un_tok;
1655816576 const operand = try sema.resolveInst(inst_data.operand);
16559 const src = inst_data.src();
1656016577
16561 return sema.analyzeRet(block, operand, src);
16578 const r_brace_src = inst_data.src();
16579 const ret_ty_src: LazySrcLoc = .{ .node_offset_fn_type_ret_ty = 0 };
16580 const base_tag = sema.fn_ret_ty.baseZigTypeTag();
16581 if (base_tag == .NoReturn) {
16582 const msg = msg: {
16583 const msg = try sema.errMsg(block, ret_ty_src, "function declared '{}' implicitly returns", .{
16584 sema.fn_ret_ty.fmt(sema.mod),
16585 });
16586 errdefer msg.destroy(sema.gpa);
16587 try sema.errNote(block, r_brace_src, msg, "control flow reaches end of body here", .{});
16588 break :msg msg;
16589 };
16590 return sema.failWithOwnedErrorMsg(msg);
16591 } else if (base_tag != .Void) {
16592 const msg = msg: {
16593 const msg = try sema.errMsg(block, ret_ty_src, "function with non-void return type '{}' implicitly returns", .{
16594 sema.fn_ret_ty.fmt(sema.mod),
16595 });
16596 errdefer msg.destroy(sema.gpa);
16597 try sema.errNote(block, r_brace_src, msg, "control flow reaches end of body here", .{});
16598 break :msg msg;
16599 };
16600 return sema.failWithOwnedErrorMsg(msg);
16601 }
16602
16603 return sema.analyzeRet(block, operand, .unneeded);
1656216604}
1656316605
1656416606fn zirRetNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index {
......@@ -16825,7 +16867,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1682516867 const bitoffset_src: LazySrcLoc = .{ .node_offset_ptr_bitoffset = extra.data.src_node };
1682616868 const hostsize_src: LazySrcLoc = .{ .node_offset_ptr_hostsize = extra.data.src_node };
1682716869
16828 const unresolved_elem_ty = blk: {
16870 const elem_ty = blk: {
1682916871 const air_inst = try sema.resolveInst(extra.data.elem_type);
1683016872 const ty = sema.analyzeAsType(block, elem_ty_src, air_inst) catch |err| {
1683116873 if (err == error.AnalysisFail and sema.err != null and sema.typeOf(air_inst).isSinglePointer()) {
......@@ -16854,7 +16896,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1685416896 // Check if this happens to be the lazy alignment of our element type, in
1685516897 // which case we can make this 0 without resolving it.
1685616898 if (val.castTag(.lazy_align)) |payload| {
16857 if (payload.data.eql(unresolved_elem_ty, sema.mod)) {
16899 if (payload.data.eql(elem_ty, sema.mod)) {
1685816900 break :blk 0;
1685916901 }
1686016902 }
......@@ -16887,14 +16929,6 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1688716929 return sema.fail(block, bitoffset_src, "bit offset starts after end of host integer", .{});
1688816930 }
1688916931
16890 const elem_ty = if (abi_align == 0)
16891 unresolved_elem_ty
16892 else t: {
16893 const elem_ty = try sema.resolveTypeFields(unresolved_elem_ty);
16894 try sema.resolveTypeLayout(elem_ty);
16895 break :t elem_ty;
16896 };
16897
1689816932 if (elem_ty.zigTypeTag() == .NoReturn) {
1689916933 return sema.fail(block, elem_ty_src, "pointer to noreturn not allowed", .{});
1690016934 } else if (elem_ty.zigTypeTag() == .Fn) {
......@@ -20270,7 +20304,7 @@ fn analyzeShuffle(
2027020304 var buf: Value.ElemValueBuffer = undefined;
2027120305 const elem = mask.elemValueBuffer(sema.mod, i, &buf);
2027220306 if (elem.isUndef()) continue;
20273 const int = elem.toSignedInt();
20307 const int = elem.toSignedInt(sema.mod.getTarget());
2027420308 var unsigned: u32 = undefined;
2027520309 var chosen: u32 = undefined;
2027620310 if (int >= 0) {
......@@ -20312,7 +20346,7 @@ fn analyzeShuffle(
2031220346 values[i] = Value.undef;
2031320347 continue;
2031420348 }
20315 const int = mask_elem_val.toSignedInt();
20349 const int = mask_elem_val.toSignedInt(sema.mod.getTarget());
2031620350 const unsigned = if (int >= 0) @intCast(u32, int) else @intCast(u32, ~int);
2031720351 if (int >= 0) {
2031820352 values[i] = try a_val.elemValue(sema.mod, sema.arena, unsigned);
......@@ -24040,6 +24074,25 @@ const CoerceOpts = struct {
2404024074 is_ret: bool = false,
2404124075 /// Should coercion to comptime_int ermit an error message.
2404224076 no_cast_to_comptime_int: bool = false,
24077
24078 param_src: struct {
24079 func_inst: Air.Inst.Ref = .none,
24080 param_i: u32 = undefined,
24081
24082 fn get(info: @This(), sema: *Sema) !?Module.SrcLoc {
24083 if (info.func_inst == .none) return null;
24084 const fn_decl = (try sema.funcDeclSrc(info.func_inst)) orelse return null;
24085 const param_src = Module.paramSrc(0, sema.gpa, fn_decl, info.param_i);
24086 if (param_src == .node_offset_param) {
24087 return Module.SrcLoc{
24088 .file_scope = fn_decl.getFileScope(),
24089 .parent_decl_node = fn_decl.src_node,
24090 .lazy = LazySrcLoc.nodeOffset(param_src.node_offset_param),
24091 };
24092 }
24093 return param_src.toSrcLoc(fn_decl);
24094 }
24095 } = .{},
2404324096};
2404424097
2404524098fn coerceExtra(
......@@ -24699,6 +24752,10 @@ fn coerceExtra(
2469924752 }
2470024753 }
2470124754
24755 if (try opts.param_src.get(sema)) |param_src| {
24756 try sema.mod.errNoteNonLazy(param_src, msg, "parameter type declared here", .{});
24757 }
24758
2470224759 // TODO maybe add "cannot store an error in type '{}'" note
2470324760
2470424761 break :msg msg;
......@@ -28307,6 +28364,7 @@ fn cmpNumeric(
2830728364
2830828365 var lhs_bits: usize = undefined;
2830928366 if (try sema.resolveMaybeUndefVal(lhs)) |lhs_val| {
28367 try sema.resolveLazyValue(lhs_val);
2831028368 if (lhs_val.isUndef())
2831128369 return sema.addConstUndef(Type.bool);
2831228370 if (lhs_val.isNan()) switch (op) {
......@@ -28365,6 +28423,7 @@ fn cmpNumeric(
2836528423
2836628424 var rhs_bits: usize = undefined;
2836728425 if (try sema.resolveMaybeUndefVal(rhs)) |rhs_val| {
28426 try sema.resolveLazyValue(rhs_val);
2836828427 if (rhs_val.isUndef())
2836928428 return sema.addConstUndef(Type.bool);
2837028429 if (rhs_val.isNan()) switch (op) {
......@@ -29237,6 +29296,16 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
2923729296
2923829297 struct_obj.status = .have_layout;
2923929298 _ = try sema.resolveTypeRequiresComptime(resolved_ty);
29299
29300 if (struct_obj.assumed_runtime_bits and !resolved_ty.hasRuntimeBits()) {
29301 const msg = try Module.ErrorMsg.create(
29302 sema.gpa,
29303 struct_obj.srcLoc(sema.mod),
29304 "struct layout depends on it having runtime bits",
29305 .{},
29306 );
29307 return sema.failWithOwnedErrorMsg(msg);
29308 }
2924029309 }
2924129310 // otherwise it's a tuple; no need to resolve anything
2924229311}
......@@ -29401,6 +29470,16 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
2940129470 }
2940229471 union_obj.status = .have_layout;
2940329472 _ = try sema.resolveTypeRequiresComptime(resolved_ty);
29473
29474 if (union_obj.assumed_runtime_bits and !resolved_ty.hasRuntimeBits()) {
29475 const msg = try Module.ErrorMsg.create(
29476 sema.gpa,
29477 union_obj.srcLoc(sema.mod),
29478 "union layout depends on it having runtime bits",
29479 .{},
29480 );
29481 return sema.failWithOwnedErrorMsg(msg);
29482 }
2940429483}
2940529484
2940629485// In case of querying the ABI alignment of this struct, we will ask
src/Zir.zig+4-4
......@@ -519,7 +519,7 @@ pub const Inst = struct {
519519 /// Includes an operand as the return value.
520520 /// Includes a token source location.
521521 /// Uses the `un_tok` union field.
522 ret_tok,
522 ret_implicit,
523523 /// Sends control flow back to the function's callee.
524524 /// The return operand is `error.foo` where `foo` is given by the string.
525525 /// If the current function has an inferred error set, the error given by the
......@@ -1256,7 +1256,7 @@ pub const Inst = struct {
12561256 .compile_error,
12571257 .ret_node,
12581258 .ret_load,
1259 .ret_tok,
1259 .ret_implicit,
12601260 .ret_err_value,
12611261 .@"unreachable",
12621262 .repeat,
......@@ -1530,7 +1530,7 @@ pub const Inst = struct {
15301530 .compile_error,
15311531 .ret_node,
15321532 .ret_load,
1533 .ret_tok,
1533 .ret_implicit,
15341534 .ret_err_value,
15351535 .ret_ptr,
15361536 .ret_type,
......@@ -1659,7 +1659,7 @@ pub const Inst = struct {
16591659 .ref = .un_tok,
16601660 .ret_node = .un_node,
16611661 .ret_load = .un_node,
1662 .ret_tok = .un_tok,
1662 .ret_implicit = .un_tok,
16631663 .ret_err_value = .str_tok,
16641664 .ret_err_value_code = .str_tok,
16651665 .ret_ptr = .node,
src/arch/aarch64/CodeGen.zig+1-1
......@@ -6113,7 +6113,7 @@ fn genTypedValue(self: *Self, arg_tv: TypedValue) InnerError!MCValue {
61136113 if (info.bits <= 64) {
61146114 const unsigned = switch (info.signedness) {
61156115 .signed => blk: {
6116 const signed = typed_value.val.toSignedInt();
6116 const signed = typed_value.val.toSignedInt(target);
61176117 break :blk @bitCast(u64, signed);
61186118 },
61196119 .unsigned => typed_value.val.toUnsignedInt(target),
src/arch/arm/CodeGen.zig+1-1
......@@ -6070,7 +6070,7 @@ fn genTypedValue(self: *Self, arg_tv: TypedValue) InnerError!MCValue {
60706070 if (info.bits <= ptr_bits) {
60716071 const unsigned = switch (info.signedness) {
60726072 .signed => blk: {
6073 const signed = @intCast(i32, typed_value.val.toSignedInt());
6073 const signed = @intCast(i32, typed_value.val.toSignedInt(target));
60746074 break :blk @bitCast(u32, signed);
60756075 },
60766076 .unsigned => @intCast(u32, typed_value.val.toUnsignedInt(target)),
src/arch/sparc64/CodeGen.zig+1-1
......@@ -3751,7 +3751,7 @@ fn genTypedValue(self: *Self, typed_value: TypedValue) InnerError!MCValue {
37513751 if (info.bits <= 64) {
37523752 const unsigned = switch (info.signedness) {
37533753 .signed => blk: {
3754 const signed = typed_value.val.toSignedInt();
3754 const signed = typed_value.val.toSignedInt(target);
37553755 break :blk @bitCast(u64, signed);
37563756 },
37573757 .unsigned => typed_value.val.toUnsignedInt(target),
src/arch/wasm/CodeGen.zig+5-5
......@@ -2670,11 +2670,11 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue {
26702670 switch (int_info.signedness) {
26712671 .signed => switch (int_info.bits) {
26722672 0...32 => return WValue{ .imm32 = @intCast(u32, toTwosComplement(
2673 val.toSignedInt(),
2673 val.toSignedInt(target),
26742674 @intCast(u6, int_info.bits),
26752675 )) },
26762676 33...64 => return WValue{ .imm64 = toTwosComplement(
2677 val.toSignedInt(),
2677 val.toSignedInt(target),
26782678 @intCast(u7, int_info.bits),
26792679 ) },
26802680 else => unreachable,
......@@ -2841,15 +2841,15 @@ fn valueAsI32(func: *const CodeGen, val: Value, ty: Type) i32 {
28412841 }
28422842 },
28432843 .Int => switch (ty.intInfo(func.target).signedness) {
2844 .signed => return @truncate(i32, val.toSignedInt()),
2844 .signed => return @truncate(i32, val.toSignedInt(target)),
28452845 .unsigned => return @bitCast(i32, @truncate(u32, val.toUnsignedInt(target))),
28462846 },
28472847 .ErrorSet => {
28482848 const kv = func.bin_file.base.options.module.?.getErrorValue(val.getError().?) catch unreachable; // passed invalid `Value` to function
28492849 return @bitCast(i32, kv.value);
28502850 },
2851 .Bool => return @intCast(i32, val.toSignedInt()),
2852 .Pointer => return @intCast(i32, val.toSignedInt()),
2851 .Bool => return @intCast(i32, val.toSignedInt(target)),
2852 .Pointer => return @intCast(i32, val.toSignedInt(target)),
28532853 else => unreachable, // Programmer called this function for an illegal type
28542854 }
28552855}
src/arch/x86_64/CodeGen.zig+1-1
......@@ -6862,7 +6862,7 @@ fn genTypedValue(self: *Self, arg_tv: TypedValue) InnerError!MCValue {
68626862 .Int => {
68636863 const info = typed_value.ty.intInfo(self.target.*);
68646864 if (info.bits <= ptr_bits and info.signedness == .signed) {
6865 return MCValue{ .immediate = @bitCast(u64, typed_value.val.toSignedInt()) };
6865 return MCValue{ .immediate = @bitCast(u64, typed_value.val.toSignedInt(target)) };
68666866 }
68676867 if (!(info.bits > ptr_bits or info.signedness == .signed)) {
68686868 return MCValue{ .immediate = typed_value.val.toUnsignedInt(target) };
src/codegen.zig+7-7
......@@ -472,7 +472,7 @@ pub fn generateSymbol(
472472 if (info.bits <= 8) {
473473 const x: u8 = switch (info.signedness) {
474474 .unsigned => @intCast(u8, typed_value.val.toUnsignedInt(target)),
475 .signed => @bitCast(u8, @intCast(i8, typed_value.val.toSignedInt())),
475 .signed => @bitCast(u8, @intCast(i8, typed_value.val.toSignedInt(target))),
476476 };
477477 try code.append(x);
478478 return Result{ .appended = {} };
......@@ -501,13 +501,13 @@ pub fn generateSymbol(
501501 },
502502 .signed => {
503503 if (info.bits <= 16) {
504 const x = @intCast(i16, typed_value.val.toSignedInt());
504 const x = @intCast(i16, typed_value.val.toSignedInt(target));
505505 mem.writeInt(i16, try code.addManyAsArray(2), x, endian);
506506 } else if (info.bits <= 32) {
507 const x = @intCast(i32, typed_value.val.toSignedInt());
507 const x = @intCast(i32, typed_value.val.toSignedInt(target));
508508 mem.writeInt(i32, try code.addManyAsArray(4), x, endian);
509509 } else {
510 const x = typed_value.val.toSignedInt();
510 const x = typed_value.val.toSignedInt(target);
511511 mem.writeInt(i64, try code.addManyAsArray(8), x, endian);
512512 }
513513 },
......@@ -549,13 +549,13 @@ pub fn generateSymbol(
549549 },
550550 .signed => {
551551 if (info.bits <= 16) {
552 const x = @intCast(i16, int_val.toSignedInt());
552 const x = @intCast(i16, int_val.toSignedInt(target));
553553 mem.writeInt(i16, try code.addManyAsArray(2), x, endian);
554554 } else if (info.bits <= 32) {
555 const x = @intCast(i32, int_val.toSignedInt());
555 const x = @intCast(i32, int_val.toSignedInt(target));
556556 mem.writeInt(i32, try code.addManyAsArray(4), x, endian);
557557 } else {
558 const x = int_val.toSignedInt();
558 const x = int_val.toSignedInt(target);
559559 mem.writeInt(i64, try code.addManyAsArray(8), x, endian);
560560 }
561561 },
src/codegen/llvm.zig+1-1
......@@ -8932,7 +8932,7 @@ pub const FuncGen = struct {
89328932 if (elem.isUndef()) {
89338933 val.* = llvm_i32.getUndef();
89348934 } else {
8935 const int = elem.toSignedInt();
8935 const int = elem.toSignedInt(self.dg.module.getTarget());
89368936 const unsigned = if (int >= 0) @intCast(u32, int) else @intCast(u32, ~int + a_len);
89378937 val.* = llvm_i32.constInt(unsigned, .False);
89388938 }
src/codegen/spirv.zig+2-2
......@@ -360,7 +360,7 @@ pub const DeclGen = struct {
360360
361361 // Note, value is required to be sign-extended, so we don't need to mask off the upper bits.
362362 // See https://www.khronos.org/registry/SPIR-V/specs/unified1/SPIRV.html#Literal
363 var int_bits = if (ty.isSignedInt()) @bitCast(u64, val.toSignedInt()) else val.toUnsignedInt(target);
363 var int_bits = if (ty.isSignedInt()) @bitCast(u64, val.toSignedInt(target)) else val.toUnsignedInt(target);
364364
365365 const value: spec.LiteralContextDependentNumber = switch (backing_bits) {
366366 1...32 => .{ .uint32 = @truncate(u32, int_bits) },
......@@ -763,7 +763,7 @@ pub const DeclGen = struct {
763763 if (elem.isUndef()) {
764764 self.func.body.writeOperand(spec.LiteralInteger, 0xFFFF_FFFF);
765765 } else {
766 const int = elem.toSignedInt();
766 const int = elem.toSignedInt(self.getTarget());
767767 const unsigned = if (int >= 0) @intCast(u32, int) else @intCast(u32, ~int + a_len);
768768 self.func.body.writeOperand(spec.LiteralInteger, unsigned);
769769 }
src/link/Dwarf.zig+1-1
......@@ -410,7 +410,7 @@ pub const DeclState = struct {
410410 // See https://github.com/ziglang/zig/issues/645
411411 var int_buffer: Value.Payload.U64 = undefined;
412412 const field_int_val = value.enumToInt(ty, &int_buffer);
413 break :value @bitCast(u64, field_int_val.toSignedInt());
413 break :value @bitCast(u64, field_int_val.toSignedInt(target));
414414 } else @intCast(u64, field_i);
415415 mem.writeInt(u64, dbg_info_buffer.addManyAsArrayAssumeCapacity(8), value, target_endian);
416416 }
src/print_zir.zig+1-1
......@@ -235,7 +235,7 @@ const Writer = struct {
235235 => try self.writeUnNode(stream, inst),
236236
237237 .ref,
238 .ret_tok,
238 .ret_implicit,
239239 .closure_capture,
240240 .switch_capture_tag,
241241 => try self.writeUnTok(stream, inst),
src/type.zig+46-8
......@@ -160,6 +160,17 @@ pub const Type = extern union {
160160 }
161161 }
162162
163 pub fn baseZigTypeTag(self: Type) std.builtin.TypeId {
164 return switch (self.zigTypeTag()) {
165 .ErrorUnion => self.errorUnionPayload().baseZigTypeTag(),
166 .Optional => {
167 var buf: Payload.ElemType = undefined;
168 return self.optionalChild(&buf).baseZigTypeTag();
169 },
170 else => |t| t,
171 };
172 }
173
163174 pub fn isSelfComparable(ty: Type, is_equality_cmp: bool) bool {
164175 return switch (ty.zigTypeTag()) {
165176 .Int,
......@@ -2459,6 +2470,7 @@ pub const Type = extern union {
24592470 if (struct_obj.status == .field_types_wip) {
24602471 // In this case, we guess that hasRuntimeBits() for this type is true,
24612472 // and then later if our guess was incorrect, we emit a compile error.
2473 struct_obj.assumed_runtime_bits = true;
24622474 return true;
24632475 }
24642476 switch (strat) {
......@@ -2491,6 +2503,12 @@ pub const Type = extern union {
24912503
24922504 .@"union" => {
24932505 const union_obj = ty.castTag(.@"union").?.data;
2506 if (union_obj.status == .field_types_wip) {
2507 // In this case, we guess that hasRuntimeBits() for this type is true,
2508 // and then later if our guess was incorrect, we emit a compile error.
2509 union_obj.assumed_runtime_bits = true;
2510 return true;
2511 }
24942512 switch (strat) {
24952513 .sema => |sema| _ = try sema.resolveTypeFields(ty),
24962514 .eager => assert(union_obj.haveFieldTypes()),
......@@ -3027,8 +3045,9 @@ pub const Type = extern union {
30273045 const struct_obj = ty.castTag(.@"struct").?.data;
30283046 if (opt_sema) |sema| {
30293047 if (struct_obj.status == .field_types_wip) {
3030 // We'll guess "pointer-aligned" and if we guess wrong, emit
3031 // a compile error later.
3048 // We'll guess "pointer-aligned", if the struct has an
3049 // underaligned pointer field then some allocations
3050 // might require explicit alignment.
30323051 return AbiAlignmentAdvanced{ .scalar = @divExact(target.cpu.arch.ptrBitWidth(), 8) };
30333052 }
30343053 _ = try sema.resolveTypeFields(ty);
......@@ -3153,8 +3172,9 @@ pub const Type = extern union {
31533172 };
31543173 if (opt_sema) |sema| {
31553174 if (union_obj.status == .field_types_wip) {
3156 // We'll guess "pointer-aligned" and if we guess wrong, emit
3157 // a compile error later.
3175 // We'll guess "pointer-aligned", if the union has an
3176 // underaligned pointer field then some allocations
3177 // might require explicit alignment.
31583178 return AbiAlignmentAdvanced{ .scalar = @divExact(target.cpu.arch.ptrBitWidth(), 8) };
31593179 }
31603180 _ = try sema.resolveTypeFields(ty);
......@@ -5234,7 +5254,12 @@ pub const Type = extern union {
52345254 .@"struct" => {
52355255 const struct_obj = ty.castTag(.@"struct").?.data;
52365256 switch (struct_obj.requires_comptime) {
5237 .wip, .unknown => unreachable, // This function asserts types already resolved.
5257 .wip, .unknown => {
5258 // Return false to avoid incorrect dependency loops.
5259 // This will be handled correctly once merged with
5260 // `Sema.typeRequiresComptime`.
5261 return false;
5262 },
52385263 .no => return false,
52395264 .yes => return true,
52405265 }
......@@ -5243,7 +5268,12 @@ pub const Type = extern union {
52435268 .@"union", .union_safety_tagged, .union_tagged => {
52445269 const union_obj = ty.cast(Type.Payload.Union).?.data;
52455270 switch (union_obj.requires_comptime) {
5246 .wip, .unknown => unreachable, // This function asserts types already resolved.
5271 .wip, .unknown => {
5272 // Return false to avoid incorrect dependency loops.
5273 // This will be handled correctly once merged with
5274 // `Sema.typeRequiresComptime`.
5275 return false;
5276 },
52475277 .no => return false,
52485278 .yes => return true,
52495279 }
......@@ -6472,8 +6502,16 @@ pub const Type = extern union {
64726502 // type, we change it to 0 here. If this causes an assertion trip because the
64736503 // pointee type needs to be resolved more, that needs to be done before calling
64746504 // this ptr() function.
6475 if (d.@"align" != 0 and d.@"align" == d.pointee_type.abiAlignment(target)) {
6476 d.@"align" = 0;
6505 if (d.@"align" != 0) canonicalize: {
6506 if (d.pointee_type.castTag(.@"struct")) |struct_ty| {
6507 if (!struct_ty.data.haveLayout()) break :canonicalize;
6508 }
6509 if (d.pointee_type.cast(Payload.Union)) |union_ty| {
6510 if (!union_ty.data.haveLayout()) break :canonicalize;
6511 }
6512 if (d.@"align" == d.pointee_type.abiAlignment(target)) {
6513 d.@"align" = 0;
6514 }
64776515 }
64786516
64796517 // Canonicalize host_size. If it matches the bit size of the pointee type,
src/value.zig+16-7
......@@ -187,7 +187,7 @@ pub const Value = extern union {
187187 bound_fn,
188188 /// The ABI alignment of the payload type.
189189 lazy_align,
190 /// The ABI alignment of the payload type.
190 /// The ABI size of the payload type.
191191 lazy_size,
192192
193193 pub const last_no_payload_tag = Tag.empty_array;
......@@ -1201,8 +1201,8 @@ pub const Value = extern union {
12011201 }
12021202
12031203 /// Asserts the value is an integer and it fits in a i64
1204 pub fn toSignedInt(self: Value) i64 {
1205 switch (self.tag()) {
1204 pub fn toSignedInt(val: Value, target: Target) i64 {
1205 switch (val.tag()) {
12061206 .zero,
12071207 .bool_false,
12081208 .the_only_possible_value, // i0, u0
......@@ -1212,10 +1212,19 @@ pub const Value = extern union {
12121212 .bool_true,
12131213 => return 1,
12141214
1215 .int_u64 => return @intCast(i64, self.castTag(.int_u64).?.data),
1216 .int_i64 => return self.castTag(.int_i64).?.data,
1217 .int_big_positive => return self.castTag(.int_big_positive).?.asBigInt().to(i64) catch unreachable,
1218 .int_big_negative => return self.castTag(.int_big_negative).?.asBigInt().to(i64) catch unreachable,
1215 .int_u64 => return @intCast(i64, val.castTag(.int_u64).?.data),
1216 .int_i64 => return val.castTag(.int_i64).?.data,
1217 .int_big_positive => return val.castTag(.int_big_positive).?.asBigInt().to(i64) catch unreachable,
1218 .int_big_negative => return val.castTag(.int_big_negative).?.asBigInt().to(i64) catch unreachable,
1219
1220 .lazy_align => {
1221 const ty = val.castTag(.lazy_align).?.data;
1222 return @intCast(i64, ty.abiAlignment(target));
1223 },
1224 .lazy_size => {
1225 const ty = val.castTag(.lazy_size).?.data;
1226 return @intCast(i64, ty.abiSize(target));
1227 },
12191228
12201229 .undef => unreachable,
12211230 else => unreachable,
test/behavior.zig+1
......@@ -90,6 +90,7 @@ test {
9090 _ = @import("behavior/bugs/12430.zig");
9191 _ = @import("behavior/bugs/12486.zig");
9292 _ = @import("behavior/bugs/12488.zig");
93 _ = @import("behavior/bugs/12498.zig");
9394 _ = @import("behavior/bugs/12551.zig");
9495 _ = @import("behavior/bugs/12644.zig");
9596 _ = @import("behavior/bugs/12680.zig");
test/behavior/bugs/12498.zig created+8
......@@ -0,0 +1,8 @@
1const std = @import("std");
2const expect = std.testing.expect;
3
4const S = struct { a: usize };
5test "lazy abi size used in comparison" {
6 var rhs: i32 = 100;
7 try expect(@sizeOf(S) < rhs);
8}
test/behavior/struct.zig+12
......@@ -1406,3 +1406,15 @@ test "address of zero-bit field is equal to address of only field" {
14061406 try std.testing.expectEqual(&a, a_ptr);
14071407 }
14081408}
1409
1410test "struct field has a pointer to an aligned version of itself" {
1411 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
1412
1413 const E = struct {
1414 next: *align(1) @This(),
1415 };
1416 var e: E = undefined;
1417 e = .{ .next = &e };
1418
1419 try expect(&e == e.next);
1420}
test/cases/aarch64-macos/hello_world_with_updates.1.zig+2-2
......@@ -2,5 +2,5 @@ pub export fn main() noreturn {}
22
33// error
44//
5// :1:32: error: function declared 'noreturn' returns
6// :1:22: note: 'noreturn' declared here
5// :1:22: error: function declared 'noreturn' implicitly returns
6// :1:32: note: control flow reaches end of body here
test/cases/compile_errors/calling_var_args_extern_function_passing_array_instead_of_pointer.zig+1
......@@ -8,3 +8,4 @@ pub extern fn foo(format: *const u8, ...) void;
88// target=native
99//
1010// :2:16: error: expected type '*const u8', found '[5:0]u8'
11// :4:27: note: parameter type declared here
test/cases/compile_errors/casting_bit_offset_pointer_to_regular_pointer.zig+1
......@@ -21,3 +21,4 @@ export fn entry() usize { return @sizeOf(@TypeOf(&foo)); }
2121// :8:16: error: expected type '*const u3', found '*align(0:3:1) const u3'
2222// :8:16: note: pointer host size '1' cannot cast into pointer host size '0'
2323// :8:16: note: pointer bit offset '3' cannot cast into pointer bit offset '0'
24// :11:11: note: parameter type declared here
test/cases/compile_errors/closure_get_in_param_ty_instantiate_incorrectly.zig+1
......@@ -22,3 +22,4 @@ pub export fn entry() void {
2222// target=native
2323//
2424// :17:25: error: expected type 'u32', found 'type'
25// :3:21: note: parameter type declared here
test/cases/compile_errors/control_reaches_end_of_non-void_function.zig deleted-9
......@@ -1,9 +0,0 @@
1fn a() i32 {}
2export fn entry() void { _ = a(); }
3
4// error
5// backend=stage2
6// target=native
7//
8// :1:13: error: expected type 'i32', found 'void'
9// :1:8: note: function return type declared here
test/cases/compile_errors/disallow_coercion_from_non-null-terminated_pointer_to_null-terminated_pointer.zig+1
......@@ -11,3 +11,4 @@ pub export fn entry() void {
1111//
1212// :5:14: error: expected type '[*:0]const u8', found '[*]const u8'
1313// :5:14: note: destination pointer requires '0' sentinel
14// :1:20: note: parameter type declared here
test/cases/compile_errors/double_pointer_to_anyopaque_pointer.zig+1
......@@ -24,5 +24,6 @@ pub export fn entry3() void {
2424// :4:35: note: cannot implicitly cast double pointer '*const *const usize' to anyopaque pointer '*const anyopaque'
2525// :9:10: error: expected type '?*anyopaque', found '*[*:0]u8'
2626// :9:10: note: cannot implicitly cast double pointer '*[*:0]u8' to anyopaque pointer '?*anyopaque'
27// :11:12: note: parameter type declared here
2728// :15:35: error: expected type '*const anyopaque', found '*?*usize'
2829// :15:35: note: cannot implicitly cast double pointer '*?*usize' to anyopaque pointer '*const anyopaque'
test/cases/compile_errors/implicitly_increasing_pointer_alignment.zig+1
......@@ -18,3 +18,4 @@ fn bar(x: *u32) void {
1818//
1919// :8:9: error: expected type '*u32', found '*align(1) u32'
2020// :8:9: note: pointer alignment '1' cannot cast into pointer alignment '4'
21// :11:11: note: parameter type declared here
test/cases/compile_errors/invalid_compare_string.zig created+29
......@@ -0,0 +1,29 @@
1comptime {
2 var a = "foo";
3 if (a == "foo") unreachable;
4}
5comptime {
6 var a = "foo";
7 if (a == ("foo")) unreachable; // intentionally allow
8}
9comptime {
10 var a = "foo";
11 switch (a) {
12 "foo" => unreachable,
13 else => {},
14 }
15}
16comptime {
17 var a = "foo";
18 switch (a) {
19 ("foo") => unreachable, // intentionally allow
20 else => {},
21 }
22}
23
24// error
25// backend=stage2
26// target=native
27//
28// :3:11: error: cannot compare strings with ==
29// :12:9: error: cannot switch on strings
test/cases/compile_errors/invalid_dependency_on_struct_size.zig created+19
......@@ -0,0 +1,19 @@
1comptime {
2 const S = struct {
3 const Foo = struct {
4 y: Bar,
5 };
6 const Bar = struct {
7 y: if (@sizeOf(Foo) == 0) u64 else void,
8 };
9 };
10
11 _ = @sizeOf(S.Foo) + 1;
12}
13
14// error
15// backend=stage2
16// target=native
17//
18// :6:21: error: struct layout depends on it having runtime bits
19// :4:13: note: while checking this field
test/cases/compile_errors/missing_parameter_name.zig created+19
......@@ -0,0 +1,19 @@
1fn f2(u64) u64 {
2 return x;
3}
4fn f3(*x) u64 {
5 return x;
6}
7fn f1(x) u64 {
8 return x;
9}
10
11// error
12// backend=stage2
13// target=native
14//
15// :1:7: error: missing parameter name
16// :4:7: error: missing parameter name
17// :7:7: error: missing parameter name or type
18// :7:7: note: if this is a name, annotate its type 'x: T'
19// :7:7: note: if this is a type, give it a name '<name>: x'
test/cases/compile_errors/pass_const_ptr_to_mutable_ptr_fn.zig+1
......@@ -16,3 +16,4 @@ export fn entry() usize { return @sizeOf(@TypeOf(&foo)); }
1616//
1717// :4:19: error: expected type '*[]const u8', found '*const []const u8'
1818// :4:19: note: cast discards const qualifier
19// :6:14: note: parameter type declared here
test/cases/compile_errors/struct_init_passed_to_type_param.zig+1
......@@ -12,3 +12,4 @@ export const value = hi(MyStruct{ .x = 12 });
1212//
1313// :7:33: error: expected type 'type', found 'tmp.MyStruct'
1414// :1:18: note: struct declared here
15// :3:19: note: parameter type declared here
test/cases/compile_errors/struct_type_mismatch_in_arg.zig created+18
......@@ -0,0 +1,18 @@
1const Foo = struct { i: i32 };
2const Bar = struct { j: i32 };
3
4pub fn helper(_: Foo, _: Bar) void { }
5
6comptime {
7 helper(Bar { .j = 10 }, Bar { .j = 10 });
8 helper(Bar { .i = 10 }, Bar { .j = 10 });
9}
10
11// error
12// backend=stage2
13// target=native
14//
15// :7:16: error: expected type 'tmp.Foo', found 'tmp.Bar'
16// :1:13: note: struct declared here
17// :2:13: note: struct declared here
18// :4:18: note: parameter type declared here
test/cases/compile_errors/switch_on_slice.zig+1-1
......@@ -1,7 +1,7 @@
11pub export fn entry() void {
22 var a: [:0]const u8 = "foo";
33 switch (a) {
4 "--version", "version" => unreachable,
4 ("--version"), ("version") => unreachable,
55 else => {},
66 }
77}
test/cases/compile_errors/type_error_in_implicit_return.zig created+17
......@@ -0,0 +1,17 @@
1fn f1(x: bool) u32 {
2 if (x) return 1;
3}
4fn f2() noreturn {}
5pub export fn entry() void {
6 _ = f1(true);
7 _ = f2();
8}
9
10// error
11// backend=stage2
12// target=native
13//
14// :1:16: error: function with non-void return type 'u32' implicitly returns
15// :3:1: note: control flow reaches end of body here
16// :4:9: error: function declared 'noreturn' implicitly returns
17// :4:19: note: control flow reaches end of body here
test/cases/compile_errors/wrong_pointer_coerced_to_pointer_to_opaque_{}.zig+1
......@@ -12,3 +12,4 @@ export fn foo() void {
1212// :5:9: error: expected type '*tmp.Derp', found '*anyopaque'
1313// :5:9: note: pointer type child 'anyopaque' cannot cast into pointer type child 'tmp.Derp'
1414// :1:14: note: opaque declared here
15// :2:18: note: parameter type declared here
test/cases/x86_64-linux/hello_world_with_updates.1.zig+3-3
......@@ -1,6 +1,6 @@
1pub export fn _start() noreturn {}
1pub export fn main() noreturn {}
22
33// error
44//
5// :1:34: error: function declared 'noreturn' returns
6// :1:24: note: 'noreturn' declared here
5// :1:22: error: function declared 'noreturn' implicitly returns
6// :1:32: note: control flow reaches end of body here
test/cases/x86_64-macos/hello_world_with_updates.1.zig+2-2
......@@ -2,5 +2,5 @@ pub export fn main() noreturn {}
22
33// error
44//
5// :1:32: error: function declared 'noreturn' returns
6// :1:22: note: 'noreturn' declared here
5// :1:22: error: function declared 'noreturn' implicitly returns
6// :1:32: note: control flow reaches end of body here
test/cases/x86_64-windows/hello_world_with_updates.1.zig+2-2
......@@ -2,5 +2,5 @@ pub export fn main() noreturn {}
22
33// error
44//
5// :1:32: error: function declared 'noreturn' returns
6// :1:22: note: 'noreturn' declared here
5// :1:22: error: function declared 'noreturn' implicitly returns
6// :1:32: note: control flow reaches end of body here