| author | |
| committer | |
| log | 0c78ece1c95164f4a321f5705b20896415336d02 |
| tree | dff294a61dc2c004b358f49062c551892a426770 |
| parent | 6f17be063d37f5ecd9552479e65428a5c60d9152 |
| parent | 5007f727e5a2631ce55e9b44f93e69a9cb82cde8 |
| signature |
Stage2 compile error improvements92 files changed, 930 insertions(+), 744 deletions(-)
src/AstGen.zig+37-11| ... | ... | @@ -812,7 +812,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) InnerEr |
| 812 | 812 | |
| 813 | 813 | .deref => { |
| 814 | 814 | const lhs = try expr(gz, scope, .none, node_datas[node].lhs); |
| 815 | _ = try gz.addUnTok(.validate_deref, lhs, main_tokens[node]); | |
| 815 | _ = try gz.addUnNode(.validate_deref, lhs, node); | |
| 816 | 816 | switch (rl) { |
| 817 | 817 | .ref => return lhs, |
| 818 | 818 | else => { |
| ... | ... | @@ -1320,7 +1320,10 @@ fn arrayInitExpr( |
| 1320 | 1320 | const len_inst = try gz.addInt(array_init.ast.elements.len); |
| 1321 | 1321 | const elem_type = try typeExpr(gz, scope, array_type.ast.elem_type); |
| 1322 | 1322 | if (array_type.ast.sentinel == 0) { |
| 1323 | const array_type_inst = try gz.addBin(.array_type, len_inst, elem_type); | |
| 1323 | const array_type_inst = try gz.addPlNode(.array_type, array_init.ast.type_expr, Zir.Inst.Bin{ | |
| 1324 | .lhs = len_inst, | |
| 1325 | .rhs = elem_type, | |
| 1326 | }); | |
| 1324 | 1327 | break :inst .{ |
| 1325 | 1328 | .array = array_type_inst, |
| 1326 | 1329 | .elem = elem_type, |
| ... | ... | @@ -1553,7 +1556,10 @@ fn structInitExpr( |
| 1553 | 1556 | if (is_inferred_array_len) { |
| 1554 | 1557 | const elem_type = try typeExpr(gz, scope, array_type.ast.elem_type); |
| 1555 | 1558 | const array_type_inst = if (array_type.ast.sentinel == 0) blk: { |
| 1556 | break :blk try gz.addBin(.array_type, .zero_usize, elem_type); | |
| 1559 | break :blk try gz.addPlNode(.array_type, struct_init.ast.type_expr, Zir.Inst.Bin{ | |
| 1560 | .lhs = .zero_usize, | |
| 1561 | .rhs = elem_type, | |
| 1562 | }); | |
| 1557 | 1563 | } else blk: { |
| 1558 | 1564 | const sentinel = try comptimeExpr(gz, scope, .{ .ty = elem_type }, array_type.ast.sentinel); |
| 1559 | 1565 | break :blk try gz.addPlNode( |
| ... | ... | @@ -2332,8 +2338,6 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner |
| 2332 | 2338 | .error_union_type, |
| 2333 | 2339 | .bit_not, |
| 2334 | 2340 | .error_value, |
| 2335 | .error_to_int, | |
| 2336 | .int_to_error, | |
| 2337 | 2341 | .slice_start, |
| 2338 | 2342 | .slice_end, |
| 2339 | 2343 | .slice_sentinel, |
| ... | ... | @@ -2420,7 +2424,6 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner |
| 2420 | 2424 | .splat, |
| 2421 | 2425 | .reduce, |
| 2422 | 2426 | .shuffle, |
| 2423 | .select, | |
| 2424 | 2427 | .atomic_load, |
| 2425 | 2428 | .atomic_rmw, |
| 2426 | 2429 | .mul_add, |
| ... | ... | @@ -2467,6 +2470,7 @@ fn unusedResultExpr(gz: *GenZir, scope: *Scope, statement: Ast.Node.Index) Inner |
| 2467 | 2470 | .repeat, |
| 2468 | 2471 | .repeat_inline, |
| 2469 | 2472 | .panic, |
| 2473 | .panic_comptime, | |
| 2470 | 2474 | => { |
| 2471 | 2475 | noreturn_src_node = statement; |
| 2472 | 2476 | break :b true; |
| ... | ... | @@ -3100,6 +3104,10 @@ fn ptrType( |
| 3100 | 3104 | node: Ast.Node.Index, |
| 3101 | 3105 | ptr_info: Ast.full.PtrType, |
| 3102 | 3106 | ) InnerError!Zir.Inst.Ref { |
| 3107 | if (ptr_info.size == .C and ptr_info.allowzero_token != null) { | |
| 3108 | return gz.astgen.failTok(ptr_info.allowzero_token.?, "C pointers always allow address zero", .{}); | |
| 3109 | } | |
| 3110 | ||
| 3103 | 3111 | const elem_type = try typeExpr(gz, scope, ptr_info.ast.child_type); |
| 3104 | 3112 | |
| 3105 | 3113 | const simple = ptr_info.ast.align_node == 0 and |
| ... | ... | @@ -3205,7 +3213,10 @@ fn arrayType(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) !Z |
| 3205 | 3213 | const len = try expr(gz, scope, .{ .coerced_ty = .usize_type }, len_node); |
| 3206 | 3214 | const elem_type = try typeExpr(gz, scope, node_datas[node].rhs); |
| 3207 | 3215 | |
| 3208 | const result = try gz.addBin(.array_type, len, elem_type); | |
| 3216 | const result = try gz.addPlNode(.array_type, node, Zir.Inst.Bin{ | |
| 3217 | .lhs = len, | |
| 3218 | .rhs = elem_type, | |
| 3219 | }); | |
| 3209 | 3220 | return rvalue(gz, rl, result, node); |
| 3210 | 3221 | } |
| 3211 | 3222 | |
| ... | ... | @@ -7359,15 +7370,13 @@ fn builtinCall( |
| 7359 | 7370 | .align_of => return simpleUnOpType(gz, scope, rl, node, params[0], .align_of), |
| 7360 | 7371 | |
| 7361 | 7372 | .ptr_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .ptr_to_int), |
| 7362 | .error_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .error_to_int), | |
| 7363 | .int_to_error => return simpleUnOp(gz, scope, rl, node, .{ .coerced_ty = .u16_type }, params[0], .int_to_error), | |
| 7364 | 7373 | .compile_error => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .compile_error), |
| 7365 | 7374 | .set_eval_branch_quota => return simpleUnOp(gz, scope, rl, node, .{ .coerced_ty = .u32_type }, params[0], .set_eval_branch_quota), |
| 7366 | 7375 | .enum_to_int => return simpleUnOp(gz, scope, rl, node, .none, params[0], .enum_to_int), |
| 7367 | 7376 | .bool_to_int => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .bool_to_int), |
| 7368 | 7377 | .embed_file => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .embed_file), |
| 7369 | 7378 | .error_name => return simpleUnOp(gz, scope, rl, node, .{ .ty = .anyerror_type }, params[0], .error_name), |
| 7370 | .panic => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], .panic), | |
| 7379 | .panic => return simpleUnOp(gz, scope, rl, node, .{ .ty = .const_slice_u8_type }, params[0], if (gz.force_comptime) .panic_comptime else .panic), | |
| 7371 | 7380 | .set_cold => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .set_cold), |
| 7372 | 7381 | .set_runtime_safety => return simpleUnOp(gz, scope, rl, node, bool_rl, params[0], .set_runtime_safety), |
| 7373 | 7382 | .sqrt => return simpleUnOp(gz, scope, rl, node, .none, params[0], .sqrt), |
| ... | ... | @@ -7400,6 +7409,22 @@ fn builtinCall( |
| 7400 | 7409 | .truncate => return typeCast(gz, scope, rl, node, params[0], params[1], .truncate), |
| 7401 | 7410 | // zig fmt: on |
| 7402 | 7411 | |
| 7412 | .error_to_int => { | |
| 7413 | const operand = try expr(gz, scope, .none, params[0]); | |
| 7414 | const result = try gz.addExtendedPayload(.error_to_int, Zir.Inst.UnNode{ | |
| 7415 | .node = gz.nodeIndexToRelative(node), | |
| 7416 | .operand = operand, | |
| 7417 | }); | |
| 7418 | return rvalue(gz, rl, result, node); | |
| 7419 | }, | |
| 7420 | .int_to_error => { | |
| 7421 | const operand = try expr(gz, scope, .{ .coerced_ty = .u16_type }, params[0]); | |
| 7422 | const result = try gz.addExtendedPayload(.int_to_error, Zir.Inst.UnNode{ | |
| 7423 | .node = gz.nodeIndexToRelative(node), | |
| 7424 | .operand = operand, | |
| 7425 | }); | |
| 7426 | return rvalue(gz, rl, result, node); | |
| 7427 | }, | |
| 7403 | 7428 | .align_cast => { |
| 7404 | 7429 | const dest_align = try comptimeExpr(gz, scope, align_rl, params[0]); |
| 7405 | 7430 | const rhs = try expr(gz, scope, .none, params[1]); |
| ... | ... | @@ -7639,7 +7664,8 @@ fn builtinCall( |
| 7639 | 7664 | return rvalue(gz, rl, result, node); |
| 7640 | 7665 | }, |
| 7641 | 7666 | .select => { |
| 7642 | const result = try gz.addPlNode(.select, node, Zir.Inst.Select{ | |
| 7667 | const result = try gz.addExtendedPayload(.select, Zir.Inst.Select{ | |
| 7668 | .node = gz.nodeIndexToRelative(node), | |
| 7643 | 7669 | .elem_type = try typeExpr(gz, scope, params[0]), |
| 7644 | 7670 | .pred = try expr(gz, scope, .none, params[1]), |
| 7645 | 7671 | .a = try expr(gz, scope, .none, params[2]), |
src/Module.zig+49-2| ... | ... | @@ -2171,7 +2171,11 @@ pub const SrcLoc = struct { |
| 2171 | 2171 | const token_starts = tree.tokens.items(.start); |
| 2172 | 2172 | return token_starts[tok_index]; |
| 2173 | 2173 | }, |
| 2174 | .node_offset_slice_sentinel => |node_off| { | |
| 2174 | .node_offset_slice_ptr, | |
| 2175 | .node_offset_slice_start, | |
| 2176 | .node_offset_slice_end, | |
| 2177 | .node_offset_slice_sentinel, | |
| 2178 | => |node_off| { | |
| 2175 | 2179 | const tree = try src_loc.file_scope.getTree(gpa); |
| 2176 | 2180 | const node_tags = tree.nodes.items(.tag); |
| 2177 | 2181 | const node = src_loc.declRelativeToNodeIndex(node_off); |
| ... | ... | @@ -2182,7 +2186,15 @@ pub const SrcLoc = struct { |
| 2182 | 2186 | else => unreachable, |
| 2183 | 2187 | }; |
| 2184 | 2188 | const main_tokens = tree.nodes.items(.main_token); |
| 2185 | const tok_index = main_tokens[full.ast.sentinel]; | |
| 2189 | const tok_index = main_tokens[ | |
| 2190 | switch (src_loc.lazy) { | |
| 2191 | .node_offset_slice_ptr => full.ast.sliced, | |
| 2192 | .node_offset_slice_start => full.ast.start, | |
| 2193 | .node_offset_slice_end => full.ast.end, | |
| 2194 | .node_offset_slice_sentinel => full.ast.sentinel, | |
| 2195 | else => unreachable, | |
| 2196 | } | |
| 2197 | ]; | |
| 2186 | 2198 | const token_starts = tree.tokens.items(.start); |
| 2187 | 2199 | return token_starts[tok_index]; |
| 2188 | 2200 | }, |
| ... | ... | @@ -2501,6 +2513,16 @@ pub const SrcLoc = struct { |
| 2501 | 2513 | const token_starts = tree.tokens.items(.start); |
| 2502 | 2514 | return token_starts[tok_index]; |
| 2503 | 2515 | }, |
| 2516 | .node_offset_un_op => |node_off| { | |
| 2517 | const tree = try src_loc.file_scope.getTree(gpa); | |
| 2518 | const node_datas = tree.nodes.items(.data); | |
| 2519 | const node = src_loc.declRelativeToNodeIndex(node_off); | |
| 2520 | ||
| 2521 | const main_tokens = tree.nodes.items(.main_token); | |
| 2522 | const tok_index = main_tokens[node_datas[node].lhs]; | |
| 2523 | const token_starts = tree.tokens.items(.start); | |
| 2524 | return token_starts[tok_index]; | |
| 2525 | }, | |
| 2504 | 2526 | } |
| 2505 | 2527 | } |
| 2506 | 2528 | |
| ... | ... | @@ -2614,6 +2636,24 @@ pub const LazySrcLoc = union(enum) { |
| 2614 | 2636 | /// to the index expression. |
| 2615 | 2637 | /// The Decl is determined contextually. |
| 2616 | 2638 | node_offset_array_access_index: i32, |
| 2639 | /// The source location points to the LHS of a slice expression | |
| 2640 | /// expression, found by taking this AST node index offset from the containing | |
| 2641 | /// Decl AST node, which points to a slice AST node. Next, navigate | |
| 2642 | /// to the sentinel expression. | |
| 2643 | /// The Decl is determined contextually. | |
| 2644 | node_offset_slice_ptr: i32, | |
| 2645 | /// The source location points to start expression of a slice expression | |
| 2646 | /// expression, found by taking this AST node index offset from the containing | |
| 2647 | /// Decl AST node, which points to a slice AST node. Next, navigate | |
| 2648 | /// to the sentinel expression. | |
| 2649 | /// The Decl is determined contextually. | |
| 2650 | node_offset_slice_start: i32, | |
| 2651 | /// The source location points to the end expression of a slice | |
| 2652 | /// expression, found by taking this AST node index offset from the containing | |
| 2653 | /// Decl AST node, which points to a slice AST node. Next, navigate | |
| 2654 | /// to the sentinel expression. | |
| 2655 | /// The Decl is determined contextually. | |
| 2656 | node_offset_slice_end: i32, | |
| 2617 | 2657 | /// The source location points to the sentinel expression of a slice |
| 2618 | 2658 | /// expression, found by taking this AST node index offset from the containing |
| 2619 | 2659 | /// Decl AST node, which points to a slice AST node. Next, navigate |
| ... | ... | @@ -2728,6 +2768,9 @@ pub const LazySrcLoc = union(enum) { |
| 2728 | 2768 | /// to the elem expression. |
| 2729 | 2769 | /// The Decl is determined contextually. |
| 2730 | 2770 | node_offset_array_type_elem: i32, |
| 2771 | /// The source location points to the operand of an unary expression. | |
| 2772 | /// The Decl is determined contextually. | |
| 2773 | node_offset_un_op: i32, | |
| 2731 | 2774 | |
| 2732 | 2775 | pub const nodeOffset = if (TracedOffset.want_tracing) nodeOffsetDebug else nodeOffsetRelease; |
| 2733 | 2776 | |
| ... | ... | @@ -2768,6 +2811,9 @@ pub const LazySrcLoc = union(enum) { |
| 2768 | 2811 | .node_offset_builtin_call_arg4, |
| 2769 | 2812 | .node_offset_builtin_call_arg5, |
| 2770 | 2813 | .node_offset_array_access_index, |
| 2814 | .node_offset_slice_ptr, | |
| 2815 | .node_offset_slice_start, | |
| 2816 | .node_offset_slice_end, | |
| 2771 | 2817 | .node_offset_slice_sentinel, |
| 2772 | 2818 | .node_offset_call_func, |
| 2773 | 2819 | .node_offset_field_name, |
| ... | ... | @@ -2788,6 +2834,7 @@ pub const LazySrcLoc = union(enum) { |
| 2788 | 2834 | .node_offset_array_type_len, |
| 2789 | 2835 | .node_offset_array_type_sentinel, |
| 2790 | 2836 | .node_offset_array_type_elem, |
| 2837 | .node_offset_un_op, | |
| 2791 | 2838 | => .{ |
| 2792 | 2839 | .file_scope = decl.getFileScope(), |
| 2793 | 2840 | .parent_decl_node = decl.src_node, |
src/Sema.zig+189-115| ... | ... | @@ -739,8 +739,6 @@ fn analyzeBodyInner( |
| 739 | 739 | .err_union_payload_unsafe_ptr => try sema.zirErrUnionPayloadPtr(block, inst, false), |
| 740 | 740 | .error_union_type => try sema.zirErrorUnionType(block, inst), |
| 741 | 741 | .error_value => try sema.zirErrorValue(block, inst), |
| 742 | .error_to_int => try sema.zirErrorToInt(block, inst), | |
| 743 | .int_to_error => try sema.zirIntToError(block, inst), | |
| 744 | 742 | .field_ptr => try sema.zirFieldPtr(block, inst), |
| 745 | 743 | .field_ptr_named => try sema.zirFieldPtrNamed(block, inst), |
| 746 | 744 | .field_val => try sema.zirFieldVal(block, inst), |
| ... | ... | @@ -835,7 +833,6 @@ fn analyzeBodyInner( |
| 835 | 833 | .splat => try sema.zirSplat(block, inst), |
| 836 | 834 | .reduce => try sema.zirReduce(block, inst), |
| 837 | 835 | .shuffle => try sema.zirShuffle(block, inst), |
| 838 | .select => try sema.zirSelect(block, inst), | |
| 839 | 836 | .atomic_load => try sema.zirAtomicLoad(block, inst), |
| 840 | 837 | .atomic_rmw => try sema.zirAtomicRmw(block, inst), |
| 841 | 838 | .mul_add => try sema.zirMulAdd(block, inst), |
| ... | ... | @@ -906,7 +903,8 @@ fn analyzeBodyInner( |
| 906 | 903 | .ret_load => break sema.zirRetLoad(block, inst), |
| 907 | 904 | .ret_err_value => break sema.zirRetErrValue(block, inst), |
| 908 | 905 | .@"unreachable" => break sema.zirUnreachable(block, inst), |
| 909 | .panic => break sema.zirPanic(block, inst), | |
| 906 | .panic => break sema.zirPanic(block, inst, false), | |
| 907 | .panic_comptime => break sema.zirPanic(block, inst, true), | |
| 910 | 908 | // zig fmt: on |
| 911 | 909 | |
| 912 | 910 | .extended => ext: { |
| ... | ... | @@ -942,6 +940,9 @@ fn analyzeBodyInner( |
| 942 | 940 | .field_call_bind_named => try sema.zirFieldCallBindNamed(block, extended), |
| 943 | 941 | .err_set_cast => try sema.zirErrSetCast( block, extended), |
| 944 | 942 | .await_nosuspend => try sema.zirAwaitNosuspend( block, extended), |
| 943 | .select => try sema.zirSelect( block, extended), | |
| 944 | .error_to_int => try sema.zirErrorToInt( block, extended), | |
| 945 | .int_to_error => try sema.zirIntToError( block, extended), | |
| 945 | 946 | // zig fmt: on |
| 946 | 947 | .fence => { |
| 947 | 948 | try sema.zirFence(block, extended); |
| ... | ... | @@ -1685,7 +1686,9 @@ fn resolveMaybeUndefValAllowVariables( |
| 1685 | 1686 | switch (air_tags[i]) { |
| 1686 | 1687 | .constant => { |
| 1687 | 1688 | const ty_pl = sema.air_instructions.items(.data)[i].ty_pl; |
| 1688 | return sema.air_values.items[ty_pl.payload]; | |
| 1689 | const val = sema.air_values.items[ty_pl.payload]; | |
| 1690 | if (val.tag() == .runtime_int) return null; | |
| 1691 | return val; | |
| 1689 | 1692 | }, |
| 1690 | 1693 | .const_ty => { |
| 1691 | 1694 | return try sema.air_instructions.items(.data)[i].ty.toValue(sema.arena); |
| ... | ... | @@ -1717,9 +1720,17 @@ fn failWithExpectedOptionalType(sema: *Sema, block: *Block, src: LazySrcLoc, opt |
| 1717 | 1720 | } |
| 1718 | 1721 | |
| 1719 | 1722 | fn failWithArrayInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError { |
| 1720 | return sema.fail(block, src, "type '{}' does not support array initialization syntax", .{ | |
| 1721 | ty.fmt(sema.mod), | |
| 1722 | }); | |
| 1723 | const msg = msg: { | |
| 1724 | const msg = try sema.errMsg(block, src, "type '{}' does not support array initialization syntax", .{ | |
| 1725 | ty.fmt(sema.mod), | |
| 1726 | }); | |
| 1727 | errdefer msg.destroy(sema.gpa); | |
| 1728 | if (ty.isSlice()) { | |
| 1729 | try sema.errNote(block, src, msg, "inferred array length is specified with an underscore: '[_]{}'", .{ty.elemType2().fmt(sema.mod)}); | |
| 1730 | } | |
| 1731 | break :msg msg; | |
| 1732 | }; | |
| 1733 | return sema.failWithOwnedErrorMsg(block, msg); | |
| 1723 | 1734 | } |
| 1724 | 1735 | |
| 1725 | 1736 | fn failWithStructInitNotSupported(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError { |
| ... | ... | @@ -2804,7 +2815,7 @@ fn zirAllocExtended( |
| 2804 | 2815 | ) CompileError!Air.Inst.Ref { |
| 2805 | 2816 | const extra = sema.code.extraData(Zir.Inst.AllocExtended, extended.operand); |
| 2806 | 2817 | const src = LazySrcLoc.nodeOffset(extra.data.src_node); |
| 2807 | const ty_src = src; // TODO better source location | |
| 2818 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = extra.data.src_node }; | |
| 2808 | 2819 | const align_src = src; // TODO better source location |
| 2809 | 2820 | const small = @bitCast(Zir.Inst.AllocExtended.Small, extended.small); |
| 2810 | 2821 | |
| ... | ... | @@ -3856,9 +3867,9 @@ fn zirValidateArrayInit( |
| 3856 | 3867 | } |
| 3857 | 3868 | |
| 3858 | 3869 | fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void { |
| 3859 | const inst_data = sema.code.instructions.items(.data)[inst].un_tok; | |
| 3870 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | |
| 3860 | 3871 | const src = inst_data.src(); |
| 3861 | const operand_src: LazySrcLoc = .{ .token_offset = inst_data.src_tok + 1 }; | |
| 3872 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; | |
| 3862 | 3873 | const operand = try sema.resolveInst(inst_data.operand); |
| 3863 | 3874 | const operand_ty = sema.typeOf(operand); |
| 3864 | 3875 | |
| ... | ... | @@ -3870,10 +3881,26 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 3870 | 3881 | .Slice => return sema.fail(block, src, "index syntax required for slice type '{}'", .{operand_ty.fmt(sema.mod)}), |
| 3871 | 3882 | } |
| 3872 | 3883 | |
| 3884 | const elem_ty = operand_ty.elemType2(); | |
| 3873 | 3885 | if (try sema.resolveMaybeUndefVal(block, operand_src, operand)) |val| { |
| 3874 | 3886 | if (val.isUndef()) { |
| 3875 | 3887 | return sema.fail(block, src, "cannot dereference undefined value", .{}); |
| 3876 | 3888 | } |
| 3889 | } else if (!(try sema.validateRunTimeType(block, src, elem_ty, false))) { | |
| 3890 | const msg = msg: { | |
| 3891 | const msg = try sema.errMsg( | |
| 3892 | block, | |
| 3893 | src, | |
| 3894 | "values of type '{}' must be comptime known, but operand value is runtime known", | |
| 3895 | .{elem_ty.fmt(sema.mod)}, | |
| 3896 | ); | |
| 3897 | errdefer msg.destroy(sema.gpa); | |
| 3898 | ||
| 3899 | const src_decl = sema.mod.declPtr(block.src_decl); | |
| 3900 | try sema.explainWhyTypeIsComptime(block, src, msg, src.toSrcLoc(src_decl), elem_ty); | |
| 3901 | break :msg msg; | |
| 3902 | }; | |
| 3903 | return sema.failWithOwnedErrorMsg(block, msg); | |
| 3877 | 3904 | } |
| 3878 | 3905 | } |
| 3879 | 3906 | |
| ... | ... | @@ -4308,11 +4335,15 @@ fn zirCompileLog( |
| 4308 | 4335 | return Air.Inst.Ref.void_value; |
| 4309 | 4336 | } |
| 4310 | 4337 | |
| 4311 | fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Zir.Inst.Index { | |
| 4338 | fn zirPanic(sema: *Sema, block: *Block, inst: Zir.Inst.Index, force_comptime: bool) CompileError!Zir.Inst.Index { | |
| 4312 | 4339 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 4313 | const src: LazySrcLoc = inst_data.src(); | |
| 4340 | const src = inst_data.src(); | |
| 4314 | 4341 | const msg_inst = try sema.resolveInst(inst_data.operand); |
| 4315 | 4342 | |
| 4343 | if (block.is_comptime or force_comptime) { | |
| 4344 | return sema.fail(block, src, "encountered @panic at comptime", .{}); | |
| 4345 | } | |
| 4346 | try sema.requireRuntimeBlock(block, src); | |
| 4316 | 4347 | return sema.panicWithMsg(block, src, msg_inst); |
| 4317 | 4348 | } |
| 4318 | 4349 | |
| ... | ... | @@ -4796,14 +4827,16 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst |
| 4796 | 4827 | alignment, |
| 4797 | 4828 | }); |
| 4798 | 4829 | } |
| 4799 | const func = sema.owner_func orelse | |
| 4830 | const func = sema.func orelse | |
| 4800 | 4831 | return sema.fail(block, src, "@setAlignStack outside function body", .{}); |
| 4801 | 4832 | |
| 4802 | 4833 | const fn_owner_decl = sema.mod.declPtr(func.owner_decl); |
| 4803 | 4834 | switch (fn_owner_decl.ty.fnCallingConvention()) { |
| 4804 | 4835 | .Naked => return sema.fail(block, src, "@setAlignStack in naked function", .{}), |
| 4805 | 4836 | .Inline => return sema.fail(block, src, "@setAlignStack in inline function", .{}), |
| 4806 | else => {}, | |
| 4837 | else => if (block.inlining != null) { | |
| 4838 | return sema.fail(block, src, "@setAlignStack in inline call", .{}); | |
| 4839 | }, | |
| 4807 | 4840 | } |
| 4808 | 4841 | |
| 4809 | 4842 | const gop = try sema.mod.align_stack_fns.getOrPut(sema.mod.gpa, func); |
| ... | ... | @@ -6161,11 +6194,12 @@ fn zirArrayType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A |
| 6161 | 6194 | const tracy = trace(@src()); |
| 6162 | 6195 | defer tracy.end(); |
| 6163 | 6196 | |
| 6164 | const bin_inst = sema.code.instructions.items(.data)[inst].bin; | |
| 6165 | const len_src = sema.src; // TODO better source location | |
| 6166 | const elem_src = sema.src; // TODO better source location | |
| 6167 | const len = try sema.resolveInt(block, len_src, bin_inst.lhs, Type.usize); | |
| 6168 | const elem_type = try sema.resolveType(block, elem_src, bin_inst.rhs); | |
| 6197 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | |
| 6198 | const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data; | |
| 6199 | const len_src: LazySrcLoc = .{ .node_offset_array_type_len = inst_data.src_node }; | |
| 6200 | const elem_src: LazySrcLoc = .{ .node_offset_array_type_elem = inst_data.src_node }; | |
| 6201 | const len = try sema.resolveInt(block, len_src, extra.lhs, Type.usize); | |
| 6202 | const elem_type = try sema.resolveType(block, elem_src, extra.rhs); | |
| 6169 | 6203 | const array_ty = try Type.array(sema.arena, len, null, elem_type, sema.mod); |
| 6170 | 6204 | |
| 6171 | 6205 | return sema.addType(array_ty); |
| ... | ... | @@ -6240,18 +6274,18 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 6240 | 6274 | ); |
| 6241 | 6275 | } |
| 6242 | 6276 | |
| 6243 | fn zirErrorToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | |
| 6277 | fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | |
| 6244 | 6278 | const tracy = trace(@src()); |
| 6245 | 6279 | defer tracy.end(); |
| 6246 | 6280 | |
| 6247 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | |
| 6248 | const src = inst_data.src(); | |
| 6249 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | |
| 6250 | const op = try sema.resolveInst(inst_data.operand); | |
| 6251 | const op_coerced = try sema.coerce(block, Type.anyerror, op, operand_src); | |
| 6281 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | |
| 6282 | const src = LazySrcLoc.nodeOffset(extra.node); | |
| 6283 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | |
| 6284 | const uncasted_operand = try sema.resolveInst(extra.operand); | |
| 6285 | const operand = try sema.coerce(block, Type.anyerror, uncasted_operand, operand_src); | |
| 6252 | 6286 | const result_ty = Type.u16; |
| 6253 | 6287 | |
| 6254 | if (try sema.resolveMaybeUndefVal(block, src, op_coerced)) |val| { | |
| 6288 | if (try sema.resolveMaybeUndefVal(block, src, operand)) |val| { | |
| 6255 | 6289 | if (val.isUndef()) { |
| 6256 | 6290 | return sema.addConstUndef(result_ty); |
| 6257 | 6291 | } |
| ... | ... | @@ -6273,7 +6307,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 6273 | 6307 | } |
| 6274 | 6308 | } |
| 6275 | 6309 | |
| 6276 | const op_ty = sema.typeOf(op); | |
| 6310 | const op_ty = sema.typeOf(uncasted_operand); | |
| 6277 | 6311 | try sema.resolveInferredErrorSetTy(block, src, op_ty); |
| 6278 | 6312 | if (!op_ty.isAnyError()) { |
| 6279 | 6313 | const names = op_ty.errorSetNames(); |
| ... | ... | @@ -6285,17 +6319,17 @@ fn zirErrorToInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 6285 | 6319 | } |
| 6286 | 6320 | |
| 6287 | 6321 | try sema.requireRuntimeBlock(block, src); |
| 6288 | return block.addBitCast(result_ty, op_coerced); | |
| 6322 | return block.addBitCast(result_ty, operand); | |
| 6289 | 6323 | } |
| 6290 | 6324 | |
| 6291 | fn zirIntToError(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | |
| 6325 | fn zirIntToError(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | |
| 6292 | 6326 | const tracy = trace(@src()); |
| 6293 | 6327 | defer tracy.end(); |
| 6294 | 6328 | |
| 6295 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; | |
| 6296 | const src = inst_data.src(); | |
| 6297 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | |
| 6298 | const uncasted_operand = try sema.resolveInst(inst_data.operand); | |
| 6329 | const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data; | |
| 6330 | const src = LazySrcLoc.nodeOffset(extra.node); | |
| 6331 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | |
| 6332 | const uncasted_operand = try sema.resolveInst(extra.operand); | |
| 6299 | 6333 | const operand = try sema.coerce(block, Type.u16, uncasted_operand, operand_src); |
| 6300 | 6334 | const target = sema.mod.getTarget(); |
| 6301 | 6335 | |
| ... | ... | @@ -7432,6 +7466,9 @@ fn analyzeAs( |
| 7432 | 7466 | const dest_ty = try sema.resolveType(block, src, zir_dest_type); |
| 7433 | 7467 | const operand = try sema.resolveInst(zir_operand); |
| 7434 | 7468 | if (dest_ty.tag() == .var_args_param) return operand; |
| 7469 | if (dest_ty.zigTypeTag() == .NoReturn) { | |
| 7470 | return sema.fail(block, src, "cannot cast to noreturn", .{}); | |
| 7471 | } | |
| 7435 | 7472 | return sema.coerce(block, dest_ty, operand, src); |
| 7436 | 7473 | } |
| 7437 | 7474 | |
| ... | ... | @@ -8099,9 +8136,11 @@ fn zirSwitchCond( |
| 8099 | 8136 | const union_ty = try sema.resolveTypeFields(block, operand_src, operand_ty); |
| 8100 | 8137 | const enum_ty = union_ty.unionTagType() orelse { |
| 8101 | 8138 | const msg = msg: { |
| 8102 | const msg = try sema.errMsg(block, src, "switch on untagged union", .{}); | |
| 8139 | const msg = try sema.errMsg(block, src, "switch on union with no attached enum", .{}); | |
| 8103 | 8140 | errdefer msg.destroy(sema.gpa); |
| 8104 | try sema.addDeclaredHereNote(msg, union_ty); | |
| 8141 | if (union_ty.declSrcLocOrNull(sema.mod)) |union_src| { | |
| 8142 | try sema.mod.errNoteNonLazy(union_src, msg, "consider 'union(enum)' here", .{}); | |
| 8143 | } | |
| 8105 | 8144 | break :msg msg; |
| 8106 | 8145 | }; |
| 8107 | 8146 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -8357,7 +8396,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8357 | 8396 | return sema.fail( |
| 8358 | 8397 | block, |
| 8359 | 8398 | src, |
| 8360 | "switch must handle all possibilities", | |
| 8399 | "else prong required when switching on type 'anyerror'", | |
| 8361 | 8400 | .{}, |
| 8362 | 8401 | ); |
| 8363 | 8402 | } |
| ... | ... | @@ -8592,7 +8631,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 8592 | 8631 | if (true_count + false_count == 2) { |
| 8593 | 8632 | return sema.fail( |
| 8594 | 8633 | block, |
| 8595 | src, | |
| 8634 | special_prong_src, | |
| 8596 | 8635 | "unreachable else prong; all cases already handled", |
| 8597 | 8636 | .{}, |
| 8598 | 8637 | ); |
| ... | ... | @@ -9720,7 +9759,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 9720 | 9759 | |
| 9721 | 9760 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 9722 | 9761 | const src = inst_data.src(); |
| 9723 | const operand_src = src; // TODO put this on the operand, not the '~' | |
| 9762 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; | |
| 9724 | 9763 | |
| 9725 | 9764 | const operand = try sema.resolveInst(inst_data.operand); |
| 9726 | 9765 | const operand_type = sema.typeOf(operand); |
| ... | ... | @@ -10219,7 +10258,7 @@ fn zirNegate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 10219 | 10258 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 10220 | 10259 | const src = inst_data.src(); |
| 10221 | 10260 | const lhs_src = src; |
| 10222 | const rhs_src = src; // TODO better source location | |
| 10261 | const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; | |
| 10223 | 10262 | |
| 10224 | 10263 | const rhs = try sema.resolveInst(inst_data.operand); |
| 10225 | 10264 | const rhs_ty = sema.typeOf(rhs); |
| ... | ... | @@ -10255,7 +10294,7 @@ fn zirNegateWrap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError! |
| 10255 | 10294 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 10256 | 10295 | const src = inst_data.src(); |
| 10257 | 10296 | const lhs_src = src; |
| 10258 | const rhs_src = src; // TODO better source location | |
| 10297 | const rhs_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; | |
| 10259 | 10298 | |
| 10260 | 10299 | const rhs = try sema.resolveInst(inst_data.operand); |
| 10261 | 10300 | const rhs_ty = sema.typeOf(rhs); |
| ... | ... | @@ -10532,18 +10571,17 @@ fn analyzeArithmetic( |
| 10532 | 10571 | if (lhs_zig_ty_tag == .Pointer) switch (lhs_ty.ptrSize()) { |
| 10533 | 10572 | .One, .Slice => {}, |
| 10534 | 10573 | .Many, .C => { |
| 10535 | const op_src = src; // TODO better source location | |
| 10536 | 10574 | const air_tag: Air.Inst.Tag = switch (zir_tag) { |
| 10537 | 10575 | .add => .ptr_add, |
| 10538 | 10576 | .sub => .ptr_sub, |
| 10539 | 10577 | else => return sema.fail( |
| 10540 | 10578 | block, |
| 10541 | op_src, | |
| 10579 | src, | |
| 10542 | 10580 | "invalid pointer arithmetic operand: '{s}''", |
| 10543 | 10581 | .{@tagName(zir_tag)}, |
| 10544 | 10582 | ), |
| 10545 | 10583 | }; |
| 10546 | return analyzePtrArithmetic(sema, block, op_src, lhs, rhs, air_tag, lhs_src, rhs_src); | |
| 10584 | return analyzePtrArithmetic(sema, block, src, lhs, rhs, air_tag, lhs_src, rhs_src); | |
| 10547 | 10585 | }, |
| 10548 | 10586 | }; |
| 10549 | 10587 | |
| ... | ... | @@ -11941,7 +11979,6 @@ fn runtimeBoolCmp( |
| 11941 | 11979 | |
| 11942 | 11980 | fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 11943 | 11981 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 11944 | const src = inst_data.src(); | |
| 11945 | 11982 | const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 11946 | 11983 | const ty = try sema.resolveType(block, operand_src, inst_data.operand); |
| 11947 | 11984 | switch (ty.zigTypeTag()) { |
| ... | ... | @@ -11951,7 +11988,7 @@ fn zirSizeOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 11951 | 11988 | .Null, |
| 11952 | 11989 | .BoundFn, |
| 11953 | 11990 | .Opaque, |
| 11954 | => return sema.fail(block, src, "no size available for type '{}'", .{ty.fmt(sema.mod)}), | |
| 11991 | => return sema.fail(block, operand_src, "no size available for type '{}'", .{ty.fmt(sema.mod)}), | |
| 11955 | 11992 | |
| 11956 | 11993 | .Type, |
| 11957 | 11994 | .EnumLiteral, |
| ... | ... | @@ -12077,7 +12114,7 @@ fn zirBuiltinSrc( |
| 12077 | 12114 | const tracy = trace(@src()); |
| 12078 | 12115 | defer tracy.end(); |
| 12079 | 12116 | |
| 12080 | const src = LazySrcLoc.nodeOffset(@bitCast(i32, extended.operand)); | |
| 12117 | const src = sema.src; // TODO better source location | |
| 12081 | 12118 | const extra = sema.code.extraData(Zir.Inst.LineColumn, extended.operand).data; |
| 12082 | 12119 | const func = sema.func orelse return sema.fail(block, src, "@src outside function", .{}); |
| 12083 | 12120 | const fn_owner_decl = sema.mod.declPtr(func.owner_decl); |
| ... | ... | @@ -12116,9 +12153,8 @@ fn zirBuiltinSrc( |
| 12116 | 12153 | field_values[0] = file_name_val; |
| 12117 | 12154 | // fn_name: [:0]const u8, |
| 12118 | 12155 | field_values[1] = func_name_val; |
| 12119 | // TODO these should be runtime only! | |
| 12120 | 12156 | // line: u32 |
| 12121 | field_values[2] = try Value.Tag.int_u64.create(sema.arena, extra.line + 1); | |
| 12157 | field_values[2] = try Value.Tag.runtime_int.create(sema.arena, extra.line + 1); | |
| 12122 | 12158 | // column: u32, |
| 12123 | 12159 | field_values[3] = try Value.Tag.int_u64.create(sema.arena, extra.column + 1); |
| 12124 | 12160 | |
| ... | ... | @@ -13123,7 +13159,7 @@ fn zirBoolNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 13123 | 13159 | |
| 13124 | 13160 | const inst_data = sema.code.instructions.items(.data)[inst].un_node; |
| 13125 | 13161 | const src = inst_data.src(); |
| 13126 | const operand_src = src; // TODO put this on the operand, not the `!` | |
| 13162 | const operand_src: LazySrcLoc = .{ .node_offset_un_op = inst_data.src_node }; | |
| 13127 | 13163 | const uncasted_operand = try sema.resolveInst(inst_data.operand); |
| 13128 | 13164 | |
| 13129 | 13165 | const operand = try sema.coerce(block, Type.bool, uncasted_operand, operand_src); |
| ... | ... | @@ -13667,7 +13703,8 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 13667 | 13703 | defer tracy.end(); |
| 13668 | 13704 | |
| 13669 | 13705 | const inst_data = sema.code.instructions.items(.data)[inst].ptr_type_simple; |
| 13670 | const elem_type = try sema.resolveType(block, .unneeded, inst_data.elem_type); | |
| 13706 | const elem_ty_src = sema.src; // TODO better source location | |
| 13707 | const elem_type = try sema.resolveType(block, elem_ty_src, inst_data.elem_type); | |
| 13671 | 13708 | const ty = try Type.ptr(sema.arena, sema.mod, .{ |
| 13672 | 13709 | .pointee_type = elem_type, |
| 13673 | 13710 | .@"addrspace" = .generic, |
| ... | ... | @@ -13676,6 +13713,7 @@ fn zirPtrTypeSimple(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 13676 | 13713 | .@"volatile" = inst_data.is_volatile, |
| 13677 | 13714 | .size = inst_data.size, |
| 13678 | 13715 | }); |
| 13716 | try sema.validatePtrTy(block, elem_ty_src, ty); | |
| 13679 | 13717 | return sema.addType(ty); |
| 13680 | 13718 | } |
| 13681 | 13719 | |
| ... | ... | @@ -13683,9 +13721,12 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 13683 | 13721 | const tracy = trace(@src()); |
| 13684 | 13722 | defer tracy.end(); |
| 13685 | 13723 | |
| 13686 | // TODO better source location | |
| 13687 | const src: LazySrcLoc = sema.src; | |
| 13688 | const elem_ty_src: LazySrcLoc = .unneeded; | |
| 13724 | const src: LazySrcLoc = sema.src; // TODO better source location | |
| 13725 | const elem_ty_src: LazySrcLoc = sema.src; // TODO better source location | |
| 13726 | const sentinel_src: LazySrcLoc = sema.src; // TODO better source location | |
| 13727 | const addrspace_src: LazySrcLoc = sema.src; // TODO better source location | |
| 13728 | const bitoffset_src: LazySrcLoc = sema.src; // TODO better source location | |
| 13729 | const hostsize_src: LazySrcLoc = sema.src; // TODO better source location | |
| 13689 | 13730 | const inst_data = sema.code.instructions.items(.data)[inst].ptr_type; |
| 13690 | 13731 | const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index); |
| 13691 | 13732 | const unresolved_elem_ty = try sema.resolveType(block, elem_ty_src, extra.data.elem_type); |
| ... | ... | @@ -13696,7 +13737,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 13696 | 13737 | const sentinel = if (inst_data.flags.has_sentinel) blk: { |
| 13697 | 13738 | const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); |
| 13698 | 13739 | extra_i += 1; |
| 13699 | break :blk (try sema.resolveInstConst(block, .unneeded, ref)).val; | |
| 13740 | break :blk (try sema.resolveInstConst(block, sentinel_src, ref)).val; | |
| 13700 | 13741 | } else null; |
| 13701 | 13742 | |
| 13702 | 13743 | const abi_align: u32 = if (inst_data.flags.has_align) blk: { |
| ... | ... | @@ -13718,20 +13759,20 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 13718 | 13759 | const address_space = if (inst_data.flags.has_addrspace) blk: { |
| 13719 | 13760 | const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); |
| 13720 | 13761 | extra_i += 1; |
| 13721 | break :blk try sema.analyzeAddrspace(block, .unneeded, ref, .pointer); | |
| 13762 | break :blk try sema.analyzeAddrspace(block, addrspace_src, ref, .pointer); | |
| 13722 | 13763 | } else .generic; |
| 13723 | 13764 | |
| 13724 | 13765 | const bit_offset = if (inst_data.flags.has_bit_range) blk: { |
| 13725 | 13766 | const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); |
| 13726 | 13767 | extra_i += 1; |
| 13727 | const bit_offset = try sema.resolveInt(block, .unneeded, ref, Type.u16); | |
| 13768 | const bit_offset = try sema.resolveInt(block, bitoffset_src, ref, Type.u16); | |
| 13728 | 13769 | break :blk @intCast(u16, bit_offset); |
| 13729 | 13770 | } else 0; |
| 13730 | 13771 | |
| 13731 | 13772 | const host_size: u16 = if (inst_data.flags.has_bit_range) blk: { |
| 13732 | 13773 | const ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_i]); |
| 13733 | 13774 | extra_i += 1; |
| 13734 | const host_size = try sema.resolveInt(block, .unneeded, ref, Type.u16); | |
| 13775 | const host_size = try sema.resolveInt(block, hostsize_src, ref, Type.u16); | |
| 13735 | 13776 | break :blk @intCast(u16, host_size); |
| 13736 | 13777 | } else 0; |
| 13737 | 13778 | |
| ... | ... | @@ -13758,9 +13799,25 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 13758 | 13799 | .@"volatile" = inst_data.flags.is_volatile, |
| 13759 | 13800 | .size = inst_data.size, |
| 13760 | 13801 | }); |
| 13802 | try sema.validatePtrTy(block, elem_ty_src, ty); | |
| 13761 | 13803 | return sema.addType(ty); |
| 13762 | 13804 | } |
| 13763 | 13805 | |
| 13806 | fn validatePtrTy(sema: *Sema, block: *Block, elem_src: LazySrcLoc, ty: Type) CompileError!void { | |
| 13807 | const ptr_info = ty.ptrInfo().data; | |
| 13808 | const pointee_tag = ptr_info.pointee_type.zigTypeTag(); | |
| 13809 | if (pointee_tag == .NoReturn) { | |
| 13810 | return sema.fail(block, elem_src, "pointer to noreturn not allowed", .{}); | |
| 13811 | } else if (ptr_info.size == .Many and pointee_tag == .Opaque) { | |
| 13812 | return sema.fail(block, elem_src, "unknown-length pointer to opaque not allowed", .{}); | |
| 13813 | } else if (ptr_info.size == .C) { | |
| 13814 | // TODO check extern type | |
| 13815 | if (pointee_tag == .Opaque) { | |
| 13816 | return sema.fail(block, elem_src, "C pointers cannot point to opaque types", .{}); | |
| 13817 | } | |
| 13818 | } | |
| 13819 | } | |
| 13820 | ||
| 13764 | 13821 | fn zirStructInitEmpty(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| 13765 | 13822 | const tracy = trace(@src()); |
| 13766 | 13823 | defer tracy.end(); |
| ... | ... | @@ -14559,14 +14616,12 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 14559 | 14616 | }, |
| 14560 | 14617 | .Enum => operand_ty, |
| 14561 | 14618 | .Union => operand_ty.unionTagType() orelse { |
| 14562 | const decl_index = operand_ty.getOwnerDecl(); | |
| 14563 | const decl = mod.declPtr(decl_index); | |
| 14564 | 14619 | const msg = msg: { |
| 14565 | const msg = try sema.errMsg(block, src, "union '{s}' is untagged", .{ | |
| 14566 | decl.name, | |
| 14620 | const msg = try sema.errMsg(block, src, "union '{}' is untagged", .{ | |
| 14621 | operand_ty.fmt(sema.mod), | |
| 14567 | 14622 | }); |
| 14568 | 14623 | errdefer msg.destroy(sema.gpa); |
| 14569 | try mod.errNoteNonLazy(decl.srcLoc(), msg, "declared here", .{}); | |
| 14624 | try sema.addDeclaredHereNote(msg, operand_ty); | |
| 14570 | 14625 | break :msg msg; |
| 14571 | 14626 | }; |
| 14572 | 14627 | return sema.failWithOwnedErrorMsg(block, msg); |
| ... | ... | @@ -16703,14 +16758,13 @@ fn analyzeShuffle( |
| 16703 | 16758 | }); |
| 16704 | 16759 | } |
| 16705 | 16760 | |
| 16706 | fn zirSelect(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { | |
| 16707 | const inst_data = sema.code.instructions.items(.data)[inst].pl_node; | |
| 16708 | const extra = sema.code.extraData(Zir.Inst.Select, inst_data.payload_index).data; | |
| 16761 | fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref { | |
| 16762 | const extra = sema.code.extraData(Zir.Inst.Select, extended.operand).data; | |
| 16709 | 16763 | |
| 16710 | const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; | |
| 16711 | const pred_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node }; | |
| 16712 | const a_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = inst_data.src_node }; | |
| 16713 | const b_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = inst_data.src_node }; | |
| 16764 | const elem_ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node }; | |
| 16765 | const pred_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = extra.node }; | |
| 16766 | const a_src: LazySrcLoc = .{ .node_offset_builtin_call_arg2 = extra.node }; | |
| 16767 | const b_src: LazySrcLoc = .{ .node_offset_builtin_call_arg3 = extra.node }; | |
| 16714 | 16768 | |
| 16715 | 16769 | const elem_ty = try sema.resolveType(block, elem_ty_src, extra.elem_type); |
| 16716 | 16770 | try sema.checkVectorElemType(block, elem_ty_src, elem_ty); |
| ... | ... | @@ -17417,7 +17471,7 @@ fn zirVarExtended( |
| 17417 | 17471 | const extra = sema.code.extraData(Zir.Inst.ExtendedVar, extended.operand); |
| 17418 | 17472 | const src = sema.src; |
| 17419 | 17473 | const ty_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at type |
| 17420 | const mut_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at mut token | |
| 17474 | const name_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at the name token | |
| 17421 | 17475 | const init_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at init expr |
| 17422 | 17476 | const small = @bitCast(Zir.Inst.ExtendedVar.Small, extended.small); |
| 17423 | 17477 | |
| ... | ... | @@ -17461,7 +17515,7 @@ fn zirVarExtended( |
| 17461 | 17515 | return sema.failWithNeededComptime(block, init_src); |
| 17462 | 17516 | } else Value.initTag(.unreachable_value); |
| 17463 | 17517 | |
| 17464 | try sema.validateVarType(block, mut_src, var_ty, small.is_extern); | |
| 17518 | try sema.validateVarType(block, name_src, var_ty, small.is_extern); | |
| 17465 | 17519 | |
| 17466 | 17520 | const new_var = try sema.gpa.create(Module.Var); |
| 17467 | 17521 | errdefer sema.gpa.destroy(new_var); |
| ... | ... | @@ -17958,6 +18012,9 @@ fn validateVarType( |
| 17958 | 18012 | |
| 17959 | 18013 | const src_decl = mod.declPtr(block.src_decl); |
| 17960 | 18014 | try sema.explainWhyTypeIsComptime(block, src, msg, src.toSrcLoc(src_decl), var_ty); |
| 18015 | if (var_ty.zigTypeTag() == .ComptimeInt or var_ty.zigTypeTag() == .ComptimeFloat) { | |
| 18016 | try sema.errNote(block, src, msg, "to modify this variable at runtime, it must be given an explicit fixed-size number type", .{}); | |
| 18017 | } | |
| 17961 | 18018 | |
| 17962 | 18019 | break :msg msg; |
| 17963 | 18020 | }; |
| ... | ... | @@ -19445,6 +19502,34 @@ fn elemVal( |
| 19445 | 19502 | } |
| 19446 | 19503 | } |
| 19447 | 19504 | |
| 19505 | fn validateRuntimeElemAccess( | |
| 19506 | sema: *Sema, | |
| 19507 | block: *Block, | |
| 19508 | elem_index_src: LazySrcLoc, | |
| 19509 | elem_ty: Type, | |
| 19510 | parent_ty: Type, | |
| 19511 | parent_src: LazySrcLoc, | |
| 19512 | ) CompileError!void { | |
| 19513 | const valid_rt = try sema.validateRunTimeType(block, elem_index_src, elem_ty, false); | |
| 19514 | if (!valid_rt) { | |
| 19515 | const msg = msg: { | |
| 19516 | const msg = try sema.errMsg( | |
| 19517 | block, | |
| 19518 | elem_index_src, | |
| 19519 | "values of type '{}' must be comptime known, but index value is runtime known", | |
| 19520 | .{parent_ty.fmt(sema.mod)}, | |
| 19521 | ); | |
| 19522 | errdefer msg.destroy(sema.gpa); | |
| 19523 | ||
| 19524 | const src_decl = sema.mod.declPtr(block.src_decl); | |
| 19525 | try sema.explainWhyTypeIsComptime(block, elem_index_src, msg, parent_src.toSrcLoc(src_decl), parent_ty); | |
| 19526 | ||
| 19527 | break :msg msg; | |
| 19528 | }; | |
| 19529 | return sema.failWithOwnedErrorMsg(block, msg); | |
| 19530 | } | |
| 19531 | } | |
| 19532 | ||
| 19448 | 19533 | fn tupleFieldPtr( |
| 19449 | 19534 | sema: *Sema, |
| 19450 | 19535 | block: *Block, |
| ... | ... | @@ -19485,6 +19570,8 @@ fn tupleFieldPtr( |
| 19485 | 19570 | ); |
| 19486 | 19571 | } |
| 19487 | 19572 | |
| 19573 | try sema.validateRuntimeElemAccess(block, field_index_src, field_ty, tuple_ty, tuple_ptr_src); | |
| 19574 | ||
| 19488 | 19575 | try sema.requireRuntimeBlock(block, tuple_ptr_src); |
| 19489 | 19576 | return block.addStructFieldPtr(tuple_ptr, field_index, ptr_field_ty); |
| 19490 | 19577 | } |
| ... | ... | @@ -19523,6 +19610,8 @@ fn tupleField( |
| 19523 | 19610 | return sema.addConstant(field_ty, field_values[field_index]); |
| 19524 | 19611 | } |
| 19525 | 19612 | |
| 19613 | try sema.validateRuntimeElemAccess(block, field_index_src, field_ty, tuple_ty, tuple_src); | |
| 19614 | ||
| 19526 | 19615 | try sema.requireRuntimeBlock(block, tuple_src); |
| 19527 | 19616 | return block.addStructFieldVal(tuple, field_index, field_ty); |
| 19528 | 19617 | } |
| ... | ... | @@ -19573,24 +19662,7 @@ fn elemValArray( |
| 19573 | 19662 | } |
| 19574 | 19663 | } |
| 19575 | 19664 | |
| 19576 | const valid_rt = try sema.validateRunTimeType(block, elem_index_src, elem_ty, false); | |
| 19577 | if (!valid_rt) { | |
| 19578 | const msg = msg: { | |
| 19579 | const msg = try sema.errMsg( | |
| 19580 | block, | |
| 19581 | elem_index_src, | |
| 19582 | "values of type '{}' must be comptime known, but index value is runtime known", | |
| 19583 | .{array_ty.fmt(sema.mod)}, | |
| 19584 | ); | |
| 19585 | errdefer msg.destroy(sema.gpa); | |
| 19586 | ||
| 19587 | const src_decl = sema.mod.declPtr(block.src_decl); | |
| 19588 | try sema.explainWhyTypeIsComptime(block, elem_index_src, msg, array_src.toSrcLoc(src_decl), array_ty); | |
| 19589 | ||
| 19590 | break :msg msg; | |
| 19591 | }; | |
| 19592 | return sema.failWithOwnedErrorMsg(block, msg); | |
| 19593 | } | |
| 19665 | try sema.validateRuntimeElemAccess(block, elem_index_src, elem_ty, array_ty, array_src); | |
| 19594 | 19666 | |
| 19595 | 19667 | const runtime_src = if (maybe_undef_array_val != null) elem_index_src else array_src; |
| 19596 | 19668 | try sema.requireRuntimeBlock(block, runtime_src); |
| ... | ... | @@ -19648,23 +19720,8 @@ fn elemPtrArray( |
| 19648 | 19720 | } |
| 19649 | 19721 | } |
| 19650 | 19722 | |
| 19651 | const valid_rt = try sema.validateRunTimeType(block, elem_index_src, array_ty.elemType2(), false); | |
| 19652 | if (!valid_rt and !init) { | |
| 19653 | const msg = msg: { | |
| 19654 | const msg = try sema.errMsg( | |
| 19655 | block, | |
| 19656 | elem_index_src, | |
| 19657 | "values of type '{}' must be comptime known, but index value is runtime known", | |
| 19658 | .{array_ty.fmt(sema.mod)}, | |
| 19659 | ); | |
| 19660 | errdefer msg.destroy(sema.gpa); | |
| 19661 | ||
| 19662 | const src_decl = sema.mod.declPtr(block.src_decl); | |
| 19663 | try sema.explainWhyTypeIsComptime(block, elem_index_src, msg, array_ptr_src.toSrcLoc(src_decl), array_ty); | |
| 19664 | ||
| 19665 | break :msg msg; | |
| 19666 | }; | |
| 19667 | return sema.failWithOwnedErrorMsg(block, msg); | |
| 19723 | if (!init) { | |
| 19724 | try sema.validateRuntimeElemAccess(block, elem_index_src, array_ty.elemType2(), array_ty, array_ptr_src); | |
| 19668 | 19725 | } |
| 19669 | 19726 | |
| 19670 | 19727 | const runtime_src = if (maybe_undef_array_ptr_val != null) elem_index_src else array_ptr_src; |
| ... | ... | @@ -19720,6 +19777,8 @@ fn elemValSlice( |
| 19720 | 19777 | } |
| 19721 | 19778 | } |
| 19722 | 19779 | |
| 19780 | try sema.validateRuntimeElemAccess(block, elem_index_src, elem_ty, slice_ty, slice_src); | |
| 19781 | ||
| 19723 | 19782 | try sema.requireRuntimeBlock(block, runtime_src); |
| 19724 | 19783 | if (block.wantSafety()) { |
| 19725 | 19784 | const len_inst = if (maybe_slice_val) |slice_val| |
| ... | ... | @@ -19773,6 +19832,8 @@ fn elemPtrSlice( |
| 19773 | 19832 | } |
| 19774 | 19833 | } |
| 19775 | 19834 | |
| 19835 | try sema.validateRuntimeElemAccess(block, elem_index_src, elem_ptr_ty, slice_ty, slice_src); | |
| 19836 | ||
| 19776 | 19837 | const runtime_src = if (maybe_undef_slice_val != null) elem_index_src else slice_src; |
| 19777 | 19838 | try sema.requireRuntimeBlock(block, runtime_src); |
| 19778 | 19839 | if (block.wantSafety()) { |
| ... | ... | @@ -20042,6 +20103,15 @@ fn coerce( |
| 20042 | 20103 | }); |
| 20043 | 20104 | return sema.addConstant(dest_ty, slice_val); |
| 20044 | 20105 | } |
| 20106 | ||
| 20107 | if (inst_ty.zigTypeTag() == .Array) { | |
| 20108 | return sema.fail( | |
| 20109 | block, | |
| 20110 | inst_src, | |
| 20111 | "array literal requires address-of operator (&) to coerce to slice type '{}'", | |
| 20112 | .{dest_ty.fmt(sema.mod)}, | |
| 20113 | ); | |
| 20114 | } | |
| 20045 | 20115 | }, |
| 20046 | 20116 | .Many => p: { |
| 20047 | 20117 | if (!inst_ty.isSlice()) break :p; |
| ... | ... | @@ -22368,7 +22438,7 @@ fn analyzeLoad( |
| 22368 | 22438 | } |
| 22369 | 22439 | |
| 22370 | 22440 | if (try sema.resolveDefinedValue(block, ptr_src, ptr)) |ptr_val| { |
| 22371 | if (try sema.pointerDeref(block, ptr_src, ptr_val, ptr_ty)) |elem_val| { | |
| 22441 | if (try sema.pointerDeref(block, src, ptr_val, ptr_ty)) |elem_val| { | |
| 22372 | 22442 | return sema.addConstant(elem_ty, elem_val); |
| 22373 | 22443 | } |
| 22374 | 22444 | if (block.is_typeof) { |
| ... | ... | @@ -22543,9 +22613,9 @@ fn analyzeSlice( |
| 22543 | 22613 | sentinel_opt: Air.Inst.Ref, |
| 22544 | 22614 | sentinel_src: LazySrcLoc, |
| 22545 | 22615 | ) CompileError!Air.Inst.Ref { |
| 22546 | const ptr_src = src; // TODO better source location | |
| 22547 | const start_src = src; // TODO better source location | |
| 22548 | const end_src = src; // TODO better source location | |
| 22616 | const ptr_src: LazySrcLoc = .{ .node_offset_slice_ptr = src.node_offset.x }; | |
| 22617 | const start_src: LazySrcLoc = .{ .node_offset_slice_start = src.node_offset.x }; | |
| 22618 | const end_src: LazySrcLoc = .{ .node_offset_slice_end = src.node_offset.x }; | |
| 22549 | 22619 | // Slice expressions can operate on a variable whose type is an array. This requires |
| 22550 | 22620 | // the slice operand to be a pointer. In the case of a non-array, it will be a double pointer. |
| 22551 | 22621 | const ptr_ptr_ty = sema.typeOf(ptr_ptr); |
| ... | ... | @@ -22575,7 +22645,7 @@ fn analyzeSlice( |
| 22575 | 22645 | array_ty = double_child_ty; |
| 22576 | 22646 | elem_ty = double_child_ty.childType(); |
| 22577 | 22647 | } else { |
| 22578 | return sema.fail(block, ptr_src, "slice of single-item pointer", .{}); | |
| 22648 | return sema.fail(block, src, "slice of single-item pointer", .{}); | |
| 22579 | 22649 | } |
| 22580 | 22650 | }, |
| 22581 | 22651 | .Many, .C => { |
| ... | ... | @@ -22588,7 +22658,7 @@ fn analyzeSlice( |
| 22588 | 22658 | if (ptr_ptr_child_ty.ptrSize() == .C) { |
| 22589 | 22659 | if (try sema.resolveDefinedValue(block, ptr_src, ptr_or_slice)) |ptr_val| { |
| 22590 | 22660 | if (ptr_val.isNull()) { |
| 22591 | return sema.fail(block, ptr_src, "slice of null pointer", .{}); | |
| 22661 | return sema.fail(block, src, "slice of null pointer", .{}); | |
| 22592 | 22662 | } |
| 22593 | 22663 | } |
| 22594 | 22664 | } |
| ... | ... | @@ -22601,7 +22671,7 @@ fn analyzeSlice( |
| 22601 | 22671 | elem_ty = ptr_ptr_child_ty.childType(); |
| 22602 | 22672 | }, |
| 22603 | 22673 | }, |
| 22604 | else => return sema.fail(block, ptr_src, "slice of non-array type '{}'", .{ptr_ptr_child_ty.fmt(mod)}), | |
| 22674 | else => return sema.fail(block, src, "slice of non-array type '{}'", .{ptr_ptr_child_ty.fmt(mod)}), | |
| 22605 | 22675 | } |
| 22606 | 22676 | |
| 22607 | 22677 | const ptr = if (slice_ty.isSlice()) |
| ... | ... | @@ -22774,7 +22844,7 @@ fn analyzeSlice( |
| 22774 | 22844 | return sema.addConstUndef(return_ty); |
| 22775 | 22845 | } |
| 22776 | 22846 | |
| 22777 | return sema.fail(block, ptr_src, "non-zero length slice of undefined pointer", .{}); | |
| 22847 | return sema.fail(block, src, "non-zero length slice of undefined pointer", .{}); | |
| 22778 | 22848 | } |
| 22779 | 22849 | |
| 22780 | 22850 | const return_ty = try Type.ptr(sema.arena, mod, .{ |
| ... | ... | @@ -24434,6 +24504,10 @@ fn semaUnionFields(block: *Block, mod: *Module, union_obj: *Module.Union) Compil |
| 24434 | 24504 | } else { |
| 24435 | 24505 | // The provided type is the enum tag type. |
| 24436 | 24506 | union_obj.tag_ty = try provided_ty.copy(decl_arena_allocator); |
| 24507 | if (union_obj.tag_ty.zigTypeTag() != .Enum) { | |
| 24508 | const tag_ty_src = src; // TODO better source location | |
| 24509 | return sema.fail(block, tag_ty_src, "expected enum tag type, found '{}'", .{union_obj.tag_ty.fmt(sema.mod)}); | |
| 24510 | } | |
| 24437 | 24511 | // The fields of the union must match the enum exactly. |
| 24438 | 24512 | // Store a copy of the enum field names so we can check for |
| 24439 | 24513 | // missing or extraneous fields later. |
src/TypedValue.zig+1| ... | ... | @@ -495,5 +495,6 @@ pub fn print( |
| 495 | 495 | }, |
| 496 | 496 | .generic_poison_type => return writer.writeAll("(generic poison type)"), |
| 497 | 497 | .generic_poison => return writer.writeAll("(generic poison)"), |
| 498 | .runtime_int => return writer.writeAll("[runtime value]"), | |
| 498 | 499 | }; |
| 499 | 500 | } |
src/Zir.zig+21-22| ... | ... | @@ -212,7 +212,7 @@ pub const Inst = struct { |
| 212 | 212 | /// Uses the `pl_node` union field. Payload is `Bin`. |
| 213 | 213 | array_mul, |
| 214 | 214 | /// `[N]T` syntax. No source location provided. |
| 215 | /// Uses the `bin` union field. lhs is length, rhs is element type. | |
| 215 | /// Uses the `pl_node` union field. Payload is `Bin`. lhs is length, rhs is element type. | |
| 216 | 216 | array_type, |
| 217 | 217 | /// `[N:S]T` syntax. Source location is the array type expression node. |
| 218 | 218 | /// Uses the `pl_node` union field. Payload is `ArrayTypeSentinel`. |
| ... | ... | @@ -244,7 +244,7 @@ pub const Inst = struct { |
| 244 | 244 | /// Uses the pl_node field with payload `Bin`. |
| 245 | 245 | bitcast, |
| 246 | 246 | /// Bitwise NOT. `~` |
| 247 | /// Uses `un_node`. | |
| 247 | /// Uses `un_tok`. | |
| 248 | 248 | bit_not, |
| 249 | 249 | /// Bitwise OR. `|` |
| 250 | 250 | bit_or, |
| ... | ... | @@ -260,7 +260,7 @@ pub const Inst = struct { |
| 260 | 260 | /// Uses the `pl_node` union field. Payload is `Block`. |
| 261 | 261 | suspend_block, |
| 262 | 262 | /// Boolean NOT. See also `bit_not`. |
| 263 | /// Uses the `un_node` field. | |
| 263 | /// Uses the `un_tok` field. | |
| 264 | 264 | bool_not, |
| 265 | 265 | /// Short-circuiting boolean `and`. `lhs` is a boolean `Ref` and the other operand |
| 266 | 266 | /// is a block, which is evaluated if `lhs` is `true`. |
| ... | ... | @@ -729,7 +729,7 @@ pub const Inst = struct { |
| 729 | 729 | /// resulting array initialization value is within a comptime scope. |
| 730 | 730 | validate_array_init_comptime, |
| 731 | 731 | /// Check that operand type supports the dereference operand (.*). |
| 732 | /// Uses the `un_tok` field. | |
| 732 | /// Uses the `un_node` field. | |
| 733 | 733 | validate_deref, |
| 734 | 734 | /// A struct literal with a specified type, with no fields. |
| 735 | 735 | /// Uses the `un_node` field. |
| ... | ... | @@ -778,10 +778,6 @@ pub const Inst = struct { |
| 778 | 778 | /// Implement builtin `@ptrToInt`. Uses `un_node`. |
| 779 | 779 | /// Convert a pointer to a `usize` integer. |
| 780 | 780 | ptr_to_int, |
| 781 | /// Implement builtin `@errToInt`. Uses `un_node`. | |
| 782 | error_to_int, | |
| 783 | /// Implement builtin `@intToError`. Uses `un_node`. | |
| 784 | int_to_error, | |
| 785 | 781 | /// Emit an error message and fail compilation. |
| 786 | 782 | /// Uses the `un_node` field. |
| 787 | 783 | compile_error, |
| ... | ... | @@ -802,6 +798,8 @@ pub const Inst = struct { |
| 802 | 798 | error_name, |
| 803 | 799 | /// Implement builtin `@panic`. Uses `un_node`. |
| 804 | 800 | panic, |
| 801 | /// Same as `panic` but forces comptime. | |
| 802 | panic_comptime, | |
| 805 | 803 | /// Implement builtin `@setCold`. Uses `un_node`. |
| 806 | 804 | set_cold, |
| 807 | 805 | /// Implement builtin `@setRuntimeSafety`. Uses `un_node`. |
| ... | ... | @@ -916,9 +914,6 @@ pub const Inst = struct { |
| 916 | 914 | /// Implements the `@shuffle` builtin. |
| 917 | 915 | /// Uses the `pl_node` union field with payload `Shuffle`. |
| 918 | 916 | shuffle, |
| 919 | /// Implements the `@select` builtin. | |
| 920 | /// Uses the `pl_node` union field with payload `Select`. | |
| 921 | select, | |
| 922 | 917 | /// Implements the `@atomicLoad` builtin. |
| 923 | 918 | /// Uses the `pl_node` union field with payload `AtomicLoad`. |
| 924 | 919 | atomic_load, |
| ... | ... | @@ -1125,8 +1120,6 @@ pub const Inst = struct { |
| 1125 | 1120 | .err_union_payload_unsafe_ptr, |
| 1126 | 1121 | .err_union_code, |
| 1127 | 1122 | .err_union_code_ptr, |
| 1128 | .error_to_int, | |
| 1129 | .int_to_error, | |
| 1130 | 1123 | .ptr_type, |
| 1131 | 1124 | .ptr_type_simple, |
| 1132 | 1125 | .ensure_err_payload_void, |
| ... | ... | @@ -1230,7 +1223,6 @@ pub const Inst = struct { |
| 1230 | 1223 | .splat, |
| 1231 | 1224 | .reduce, |
| 1232 | 1225 | .shuffle, |
| 1233 | .select, | |
| 1234 | 1226 | .atomic_load, |
| 1235 | 1227 | .atomic_rmw, |
| 1236 | 1228 | .atomic_store, |
| ... | ... | @@ -1270,6 +1262,7 @@ pub const Inst = struct { |
| 1270 | 1262 | .repeat, |
| 1271 | 1263 | .repeat_inline, |
| 1272 | 1264 | .panic, |
| 1265 | .panic_comptime, | |
| 1273 | 1266 | => true, |
| 1274 | 1267 | }; |
| 1275 | 1268 | } |
| ... | ... | @@ -1423,8 +1416,6 @@ pub const Inst = struct { |
| 1423 | 1416 | .err_union_payload_unsafe_ptr, |
| 1424 | 1417 | .err_union_code, |
| 1425 | 1418 | .err_union_code_ptr, |
| 1426 | .error_to_int, | |
| 1427 | .int_to_error, | |
| 1428 | 1419 | .ptr_type, |
| 1429 | 1420 | .ptr_type_simple, |
| 1430 | 1421 | .enum_literal, |
| ... | ... | @@ -1516,7 +1507,6 @@ pub const Inst = struct { |
| 1516 | 1507 | .splat, |
| 1517 | 1508 | .reduce, |
| 1518 | 1509 | .shuffle, |
| 1519 | .select, | |
| 1520 | 1510 | .atomic_load, |
| 1521 | 1511 | .atomic_rmw, |
| 1522 | 1512 | .mul_add, |
| ... | ... | @@ -1546,6 +1536,7 @@ pub const Inst = struct { |
| 1546 | 1536 | .repeat, |
| 1547 | 1537 | .repeat_inline, |
| 1548 | 1538 | .panic, |
| 1539 | .panic_comptime, | |
| 1549 | 1540 | .@"try", |
| 1550 | 1541 | .try_ptr, |
| 1551 | 1542 | //.try_inline, |
| ... | ... | @@ -1580,7 +1571,7 @@ pub const Inst = struct { |
| 1580 | 1571 | .param_anytype_comptime = .str_tok, |
| 1581 | 1572 | .array_cat = .pl_node, |
| 1582 | 1573 | .array_mul = .pl_node, |
| 1583 | .array_type = .bin, | |
| 1574 | .array_type = .pl_node, | |
| 1584 | 1575 | .array_type_sentinel = .pl_node, |
| 1585 | 1576 | .vector_type = .pl_node, |
| 1586 | 1577 | .elem_type_index = .bin, |
| ... | ... | @@ -1713,7 +1704,7 @@ pub const Inst = struct { |
| 1713 | 1704 | .validate_struct_init_comptime = .pl_node, |
| 1714 | 1705 | .validate_array_init = .pl_node, |
| 1715 | 1706 | .validate_array_init_comptime = .pl_node, |
| 1716 | .validate_deref = .un_tok, | |
| 1707 | .validate_deref = .un_node, | |
| 1717 | 1708 | .struct_init_empty = .un_node, |
| 1718 | 1709 | .field_type = .pl_node, |
| 1719 | 1710 | .field_type_ref = .pl_node, |
| ... | ... | @@ -1731,8 +1722,6 @@ pub const Inst = struct { |
| 1731 | 1722 | .bit_size_of = .un_node, |
| 1732 | 1723 | |
| 1733 | 1724 | .ptr_to_int = .un_node, |
| 1734 | .error_to_int = .un_node, | |
| 1735 | .int_to_error = .un_node, | |
| 1736 | 1725 | .compile_error = .un_node, |
| 1737 | 1726 | .set_eval_branch_quota = .un_node, |
| 1738 | 1727 | .enum_to_int = .un_node, |
| ... | ... | @@ -1741,6 +1730,7 @@ pub const Inst = struct { |
| 1741 | 1730 | .embed_file = .un_node, |
| 1742 | 1731 | .error_name = .un_node, |
| 1743 | 1732 | .panic = .un_node, |
| 1733 | .panic_comptime = .un_node, | |
| 1744 | 1734 | .set_cold = .un_node, |
| 1745 | 1735 | .set_runtime_safety = .un_node, |
| 1746 | 1736 | .sqrt = .un_node, |
| ... | ... | @@ -1802,7 +1792,6 @@ pub const Inst = struct { |
| 1802 | 1792 | .splat = .pl_node, |
| 1803 | 1793 | .reduce = .pl_node, |
| 1804 | 1794 | .shuffle = .pl_node, |
| 1805 | .select = .pl_node, | |
| 1806 | 1795 | .atomic_load = .pl_node, |
| 1807 | 1796 | .atomic_rmw = .pl_node, |
| 1808 | 1797 | .atomic_store = .pl_node, |
| ... | ... | @@ -1971,6 +1960,15 @@ pub const Inst = struct { |
| 1971 | 1960 | await_nosuspend, |
| 1972 | 1961 | /// `operand` is `src_node: i32`. |
| 1973 | 1962 | breakpoint, |
| 1963 | /// Implements the `@select` builtin. | |
| 1964 | /// operand` is payload index to `Select`. | |
| 1965 | select, | |
| 1966 | /// Implement builtin `@errToInt`. | |
| 1967 | /// `operand` is payload index to `UnNode`. | |
| 1968 | error_to_int, | |
| 1969 | /// Implement builtin `@intToError`. | |
| 1970 | /// `operand` is payload index to `UnNode`. | |
| 1971 | int_to_error, | |
| 1974 | 1972 | |
| 1975 | 1973 | pub const InstData = struct { |
| 1976 | 1974 | opcode: Extended, |
| ... | ... | @@ -3448,6 +3446,7 @@ pub const Inst = struct { |
| 3448 | 3446 | }; |
| 3449 | 3447 | |
| 3450 | 3448 | pub const Select = struct { |
| 3449 | node: i32, | |
| 3451 | 3450 | elem_type: Ref, |
| 3452 | 3451 | pred: Ref, |
| 3453 | 3452 | a: Ref, |
src/print_zir.zig+9-8| ... | ... | @@ -142,7 +142,6 @@ const Writer = struct { |
| 142 | 142 | const tag = tags[inst]; |
| 143 | 143 | try stream.print("= {s}(", .{@tagName(tags[inst])}); |
| 144 | 144 | switch (tag) { |
| 145 | .array_type, | |
| 146 | 145 | .as, |
| 147 | 146 | .store, |
| 148 | 147 | .store_to_block_ptr, |
| ... | ... | @@ -189,8 +188,6 @@ const Writer = struct { |
| 189 | 188 | .typeof_log2_int_type, |
| 190 | 189 | .log2_int_type, |
| 191 | 190 | .ptr_to_int, |
| 192 | .error_to_int, | |
| 193 | .int_to_error, | |
| 194 | 191 | .compile_error, |
| 195 | 192 | .set_eval_branch_quota, |
| 196 | 193 | .enum_to_int, |
| ... | ... | @@ -199,6 +196,7 @@ const Writer = struct { |
| 199 | 196 | .embed_file, |
| 200 | 197 | .error_name, |
| 201 | 198 | .panic, |
| 199 | .panic_comptime, | |
| 202 | 200 | .set_cold, |
| 203 | 201 | .set_runtime_safety, |
| 204 | 202 | .sqrt, |
| ... | ... | @@ -284,7 +282,6 @@ const Writer = struct { |
| 284 | 282 | .memcpy => try self.writeMemcpy(stream, inst), |
| 285 | 283 | .memset => try self.writeMemset(stream, inst), |
| 286 | 284 | .shuffle => try self.writeShuffle(stream, inst), |
| 287 | .select => try self.writeSelect(stream, inst), | |
| 288 | 285 | .mul_add => try self.writeMulAdd(stream, inst), |
| 289 | 286 | .field_parent_ptr => try self.writeFieldParentPtr(stream, inst), |
| 290 | 287 | .builtin_call => try self.writeBuiltinCall(stream, inst), |
| ... | ... | @@ -356,6 +353,7 @@ const Writer = struct { |
| 356 | 353 | .elem_ptr, |
| 357 | 354 | .elem_val, |
| 358 | 355 | .coerce_result_ptr, |
| 356 | .array_type, | |
| 359 | 357 | => try self.writePlNodeBin(stream, inst), |
| 360 | 358 | |
| 361 | 359 | .elem_ptr_imm => try self.writeElemPtrImm(stream, inst), |
| ... | ... | @@ -478,6 +476,8 @@ const Writer = struct { |
| 478 | 476 | .compile_log => try self.writeNodeMultiOp(stream, extended), |
| 479 | 477 | .typeof_peer => try self.writeTypeofPeer(stream, extended), |
| 480 | 478 | |
| 479 | .select => try self.writeSelect(stream, extended), | |
| 480 | ||
| 481 | 481 | .add_with_overflow, |
| 482 | 482 | .sub_with_overflow, |
| 483 | 483 | .mul_with_overflow, |
| ... | ... | @@ -496,6 +496,8 @@ const Writer = struct { |
| 496 | 496 | .set_float_mode, |
| 497 | 497 | .set_align_stack, |
| 498 | 498 | .wasm_memory_size, |
| 499 | .error_to_int, | |
| 500 | .int_to_error, | |
| 499 | 501 | => { |
| 500 | 502 | const inst_data = self.code.extraData(Zir.Inst.UnNode, extended.operand).data; |
| 501 | 503 | const src = LazySrcLoc.nodeOffset(inst_data.node); |
| ... | ... | @@ -772,9 +774,8 @@ const Writer = struct { |
| 772 | 774 | try self.writeSrc(stream, inst_data.src()); |
| 773 | 775 | } |
| 774 | 776 | |
| 775 | fn writeSelect(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { | |
| 776 | const inst_data = self.code.instructions.items(.data)[inst].pl_node; | |
| 777 | const extra = self.code.extraData(Zir.Inst.Select, inst_data.payload_index).data; | |
| 777 | fn writeSelect(self: *Writer, stream: anytype, extended: Zir.Inst.Extended.InstData) !void { | |
| 778 | const extra = self.code.extraData(Zir.Inst.Select, extended.operand).data; | |
| 778 | 779 | try self.writeInstRef(stream, extra.elem_type); |
| 779 | 780 | try stream.writeAll(", "); |
| 780 | 781 | try self.writeInstRef(stream, extra.pred); |
| ... | ... | @@ -783,7 +784,7 @@ const Writer = struct { |
| 783 | 784 | try stream.writeAll(", "); |
| 784 | 785 | try self.writeInstRef(stream, extra.b); |
| 785 | 786 | try stream.writeAll(") "); |
| 786 | try self.writeSrc(stream, inst_data.src()); | |
| 787 | try self.writeSrc(stream, LazySrcLoc.nodeOffset(extra.node)); | |
| 787 | 788 | } |
| 788 | 789 | |
| 789 | 790 | fn writeMulAdd(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void { |
src/value.zig+8| ... | ... | @@ -111,6 +111,7 @@ pub const Value = extern union { |
| 111 | 111 | int_i64, |
| 112 | 112 | int_big_positive, |
| 113 | 113 | int_big_negative, |
| 114 | runtime_int, | |
| 114 | 115 | function, |
| 115 | 116 | extern_fn, |
| 116 | 117 | variable, |
| ... | ... | @@ -304,6 +305,7 @@ pub const Value = extern union { |
| 304 | 305 | .int_type => Payload.IntType, |
| 305 | 306 | .int_u64 => Payload.U64, |
| 306 | 307 | .int_i64 => Payload.I64, |
| 308 | .runtime_int => Payload.U64, | |
| 307 | 309 | .function => Payload.Function, |
| 308 | 310 | .variable => Payload.Variable, |
| 309 | 311 | .decl_ref_mut => Payload.DeclRefMut, |
| ... | ... | @@ -483,6 +485,7 @@ pub const Value = extern union { |
| 483 | 485 | }, |
| 484 | 486 | .int_type => return self.copyPayloadShallow(arena, Payload.IntType), |
| 485 | 487 | .int_u64 => return self.copyPayloadShallow(arena, Payload.U64), |
| 488 | .runtime_int => return self.copyPayloadShallow(arena, Payload.U64), | |
| 486 | 489 | .int_i64 => return self.copyPayloadShallow(arena, Payload.I64), |
| 487 | 490 | .int_big_positive, .int_big_negative => { |
| 488 | 491 | const old_payload = self.cast(Payload.BigInt).?; |
| ... | ... | @@ -762,6 +765,7 @@ pub const Value = extern union { |
| 762 | 765 | .int_i64 => return std.fmt.formatIntValue(val.castTag(.int_i64).?.data, "", options, out_stream), |
| 763 | 766 | .int_big_positive => return out_stream.print("{}", .{val.castTag(.int_big_positive).?.asBigInt()}), |
| 764 | 767 | .int_big_negative => return out_stream.print("{}", .{val.castTag(.int_big_negative).?.asBigInt()}), |
| 768 | .runtime_int => return out_stream.writeAll("[runtime value]"), | |
| 765 | 769 | .function => return out_stream.print("(function decl={d})", .{val.castTag(.function).?.data.owner_decl}), |
| 766 | 770 | .extern_fn => return out_stream.writeAll("(extern function)"), |
| 767 | 771 | .variable => return out_stream.writeAll("(variable)"), |
| ... | ... | @@ -1077,6 +1081,8 @@ pub const Value = extern union { |
| 1077 | 1081 | .int_big_positive => return val.castTag(.int_big_positive).?.asBigInt(), |
| 1078 | 1082 | .int_big_negative => return val.castTag(.int_big_negative).?.asBigInt(), |
| 1079 | 1083 | |
| 1084 | .runtime_int => return BigIntMutable.init(&space.limbs, val.castTag(.runtime_int).?.data).toConst(), | |
| 1085 | ||
| 1080 | 1086 | .undef => unreachable, |
| 1081 | 1087 | |
| 1082 | 1088 | .lazy_align => { |
| ... | ... | @@ -1132,6 +1138,8 @@ pub const Value = extern union { |
| 1132 | 1138 | .int_big_positive => return val.castTag(.int_big_positive).?.asBigInt().to(u64) catch null, |
| 1133 | 1139 | .int_big_negative => return val.castTag(.int_big_negative).?.asBigInt().to(u64) catch null, |
| 1134 | 1140 | |
| 1141 | .runtime_int => return val.castTag(.runtime_int).?.data, | |
| 1142 | ||
| 1135 | 1143 | .undef => unreachable, |
| 1136 | 1144 | |
| 1137 | 1145 | .lazy_align => { |
test/cases/compile_errors/array_access_of_type.zig created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | export fn foo() void { | |
| 2 | var b: u8[40] = undefined; | |
| 3 | _ = b; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage2 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // :2:14: error: element access of non-indexable type 'type' |
test/cases/compile_errors/invalid_array_elem_ty.zig+1-1| ... | ... | @@ -9,4 +9,4 @@ pub export fn entry() void { |
| 9 | 9 | // target=native |
| 10 | 10 | // backend=stage2 |
| 11 | 11 | // |
| 12 | // :4:1: error: expected type 'type', found 'fn() type' | |
| 12 | // :5:12: error: expected type 'type', found 'fn() type' |
test/cases/compile_errors/method_call_with_first_arg_type_primitive.zig created+21| ... | ... | @@ -0,0 +1,21 @@ |
| 1 | const Foo = struct { | |
| 2 | x: i32, | |
| 3 | ||
| 4 | fn init(x: i32) Foo { | |
| 5 | return Foo { | |
| 6 | .x = x, | |
| 7 | }; | |
| 8 | } | |
| 9 | }; | |
| 10 | ||
| 11 | export fn f() void { | |
| 12 | const derp = Foo.init(3); | |
| 13 | ||
| 14 | derp.init(); | |
| 15 | } | |
| 16 | ||
| 17 | // error | |
| 18 | // backend=stage2 | |
| 19 | // target=native | |
| 20 | // | |
| 21 | // :14:9: error: type 'tmp.Foo' has no field or member function named 'init' |
test/cases/compile_errors/method_call_with_first_arg_type_wrong_container.zig created+30| ... | ... | @@ -0,0 +1,30 @@ |
| 1 | pub const List = struct { | |
| 2 | len: usize, | |
| 3 | allocator: *Allocator, | |
| 4 | ||
| 5 | pub fn init(allocator: *Allocator) List { | |
| 6 | return List { | |
| 7 | .len = 0, | |
| 8 | .allocator = allocator, | |
| 9 | }; | |
| 10 | } | |
| 11 | }; | |
| 12 | ||
| 13 | pub var global_allocator = Allocator { | |
| 14 | .field = 1234, | |
| 15 | }; | |
| 16 | ||
| 17 | pub const Allocator = struct { | |
| 18 | field: i32, | |
| 19 | }; | |
| 20 | ||
| 21 | export fn foo() void { | |
| 22 | var x = List.init(&global_allocator); | |
| 23 | x.init(); | |
| 24 | } | |
| 25 | ||
| 26 | // error | |
| 27 | // backend=llvm | |
| 28 | // target=native | |
| 29 | // | |
| 30 | // :23:6: error: type 'tmp.List' has no field or member function named 'init' |
test/cases/compile_errors/missing_const_in_slice_with_nested_array_type.zig created+18| ... | ... | @@ -0,0 +1,18 @@ |
| 1 | const Geo3DTex2D = struct { vertices: [][2]f32 }; | |
| 2 | pub fn getGeo3DTex2D() Geo3DTex2D { | |
| 3 | return Geo3DTex2D{ | |
| 4 | .vertices = [_][2]f32{ | |
| 5 | [_]f32{ -0.5, -0.5}, | |
| 6 | }, | |
| 7 | }; | |
| 8 | } | |
| 9 | export fn entry() void { | |
| 10 | var geo_data = getGeo3DTex2D(); | |
| 11 | _ = geo_data; | |
| 12 | } | |
| 13 | ||
| 14 | // error | |
| 15 | // backend=llvm | |
| 16 | // target=native | |
| 17 | // | |
| 18 | // :4:30: error: array literal requires address-of operator (&) to coerce to slice type '[][2]f32' |
test/cases/compile_errors/mul_overflow_in_function_evaluation.zig created+14| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | const y = mul(300, 6000); | |
| 2 | fn mul(a: u16, b: u16) u16 { | |
| 3 | return a * b; | |
| 4 | } | |
| 5 | ||
| 6 | export fn entry() usize { return @sizeOf(@TypeOf(&y)); } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage2 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // :3:14: error: overflow of integer type 'u16' with value '1800000' | |
| 13 | // :1:14: note: called from here | |
| 14 |
test/cases/compile_errors/negation_overflow_in_function_evaluation.zig created+13| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | const y = neg(-128); | |
| 2 | fn neg(x: i8) i8 { | |
| 3 | return -x; | |
| 4 | } | |
| 5 | ||
| 6 | export fn entry() usize { return @sizeOf(@TypeOf(&y)); } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage2 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // :3:12: error: overflow of integer type 'i8' with value '128' | |
| 13 | // :1:14: note: called from here |
test/cases/compile_errors/no_else_prong_on_switch_on_global_error_set.zig created+14| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | export fn entry() void { | |
| 2 | foo(error.A); | |
| 3 | } | |
| 4 | fn foo(a: anyerror) void { | |
| 5 | switch (a) { | |
| 6 | error.A => {}, | |
| 7 | } | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage2 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // :5:5: error: else prong required when switching on type 'anyerror' |
test/cases/compile_errors/non-const_variables_of_things_that_require_const_variables.zig created+44| ... | ... | @@ -0,0 +1,44 @@ |
| 1 | export fn entry1() void { | |
| 2 | var m2 = &2; | |
| 3 | _ = m2; | |
| 4 | } | |
| 5 | export fn entry2() void { | |
| 6 | var a = undefined; | |
| 7 | _ = a; | |
| 8 | } | |
| 9 | export fn entry3() void { | |
| 10 | var b = 1; | |
| 11 | _ = b; | |
| 12 | } | |
| 13 | export fn entry4() void { | |
| 14 | var c = 1.0; | |
| 15 | _ = c; | |
| 16 | } | |
| 17 | export fn entry5() void { | |
| 18 | var d = null; | |
| 19 | _ = d; | |
| 20 | } | |
| 21 | export fn entry6(opaque_: *Opaque) void { | |
| 22 | var e = opaque_.*; | |
| 23 | _ = e; | |
| 24 | } | |
| 25 | export fn entry7() void { | |
| 26 | var f = i32; | |
| 27 | _ = f; | |
| 28 | } | |
| 29 | const Opaque = opaque {}; | |
| 30 | ||
| 31 | // error | |
| 32 | // backend=stage2 | |
| 33 | // target=native | |
| 34 | // | |
| 35 | // :2:8: error: variable of type '*const comptime_int' must be const or comptime | |
| 36 | // :6:8: error: variable of type '@TypeOf(undefined)' must be const or comptime | |
| 37 | // :10:8: error: variable of type 'comptime_int' must be const or comptime | |
| 38 | // :10:8: note: to modify this variable at runtime, it must be given an explicit fixed-size number type | |
| 39 | // :14:8: error: variable of type 'comptime_float' must be const or comptime | |
| 40 | // :14:8: note: to modify this variable at runtime, it must be given an explicit fixed-size number type | |
| 41 | // :18:8: error: variable of type '@TypeOf(null)' must be const or comptime | |
| 42 | // :22:19: error: values of type 'tmp.Opaque' must be comptime known, but operand value is runtime known | |
| 43 | // :26:8: error: variable of type 'type' must be const or comptime | |
| 44 | // :26:8: note: types are not available at runtime |
test/cases/compile_errors/non-inline_for_loop_on_a_type_that_requires_comptime.zig created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | const Foo = struct { | |
| 2 | name: []const u8, | |
| 3 | T: type, | |
| 4 | }; | |
| 5 | export fn entry() void { | |
| 6 | const xx: [2]Foo = .{ .{ .name = "", .T = u8 }, .{ .name = "", .T = u8 } }; | |
| 7 | for (xx) |f| { _ = f;} | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage2 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // :7:10: error: values of type '[2]tmp.Foo' must be comptime known, but index value is runtime known | |
| 15 | // :3:8: note: struct requires comptime because of this field | |
| 16 | // :3:8: note: types are not available at runtime |
test/cases/compile_errors/non_constant_expression_in_array_size.zig created+14| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | const Foo = struct { | |
| 2 | y: [get()]u8, | |
| 3 | }; | |
| 4 | var global_var: usize = 1; | |
| 5 | fn get() usize { return global_var; } | |
| 6 | ||
| 7 | export fn entry() usize { return @offsetOf(Foo, "y"); } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage2 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // :5:25: error: unable to resolve comptime value | |
| 14 | // :2:15: note: called from here |
test/cases/compile_errors/non_error_sets_used_in_merge_error_sets_operator.zig created+15| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | export fn foo() void { | |
| 2 | const Errors = u8 || u16; | |
| 3 | _ = Errors; | |
| 4 | } | |
| 5 | export fn bar() void { | |
| 6 | const Errors = error{} || u16; | |
| 7 | _ = Errors; | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage2 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // :2:20: error: expected error set type, found 'u8' | |
| 15 | // :6:31: error: expected error set type, found 'u16' |
test/cases/compile_errors/panic_called_at_compile_time.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | export fn entry() void { | |
| 2 | comptime { | |
| 3 | @panic("aoeu",); | |
| 4 | } | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage2 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // :3:9: error: encountered @panic at comptime |
test/cases/compile_errors/range_operator_in_switch_used_on_error_set.zig created+20| ... | ... | @@ -0,0 +1,20 @@ |
| 1 | export fn entry() void { | |
| 2 | foo(452) catch |err| switch (err) { | |
| 3 | error.Foo ... error.Bar => {}, | |
| 4 | else => {}, | |
| 5 | }; | |
| 6 | } | |
| 7 | fn foo(x: i32) !void { | |
| 8 | switch (x) { | |
| 9 | 0 ... 10 => return error.Foo, | |
| 10 | 11 ... 20 => return error.Bar, | |
| 11 | else => {}, | |
| 12 | } | |
| 13 | } | |
| 14 | ||
| 15 | // error | |
| 16 | // backend=llvm | |
| 17 | // target=native | |
| 18 | // | |
| 19 | // :2:34: error: ranges not allowed when switching on type '@typeInfo(@typeInfo(@TypeOf(tmp.foo)).Fn.return_type.?).ErrorUnion.error_set' | |
| 20 | // :3:19: note: range here |
test/cases/compile_errors/reading_past_end_of_pointer_casted_array.zig created+13| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | comptime { | |
| 2 | const array: [4]u8 = "aoeu".*; | |
| 3 | const sub_array = array[1..]; | |
| 4 | const int_ptr = @ptrCast(*const u24, sub_array); | |
| 5 | const deref = int_ptr.*; | |
| 6 | _ = deref; | |
| 7 | } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage2 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // :5:26: error: dereference of '*const u24' exceeds bounds of containing decl of type '[4]u8' |
test/cases/compile_errors/runtime_index_into_comptime_type_slice.zig created+19| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | const Struct = struct { | |
| 2 | a: u32, | |
| 3 | }; | |
| 4 | fn getIndex() usize { | |
| 5 | return 2; | |
| 6 | } | |
| 7 | export fn entry() void { | |
| 8 | const index = getIndex(); | |
| 9 | const field = @typeInfo(Struct).Struct.fields[index]; | |
| 10 | _ = field; | |
| 11 | } | |
| 12 | ||
| 13 | // error | |
| 14 | // backend=stage2 | |
| 15 | // target=native | |
| 16 | // | |
| 17 | // :9:51: error: values of type '[]const builtin.Type.StructField' must be comptime known, but index value is runtime known | |
| 18 | // :?:21: note: struct requires comptime because of this field | |
| 19 | // :?:21: note: types are not available at runtime |
test/cases/compile_errors/setAlignStack_in_inline_function.zig created+23| ... | ... | @@ -0,0 +1,23 @@ |
| 1 | export fn entry() void { | |
| 2 | foo(); | |
| 3 | } | |
| 4 | fn foo() callconv(.Inline) void { | |
| 5 | @setAlignStack(16); | |
| 6 | } | |
| 7 | ||
| 8 | export fn entry1() void { | |
| 9 | comptime bar(); | |
| 10 | } | |
| 11 | fn bar() void { | |
| 12 | @setAlignStack(16); | |
| 13 | } | |
| 14 | ||
| 15 | ||
| 16 | // error | |
| 17 | // backend=stage2 | |
| 18 | // target=native | |
| 19 | // | |
| 20 | // :5:5: error: @setAlignStack in inline function | |
| 21 | // :2:8: note: called from here | |
| 22 | // :12:5: error: @setAlignStack in inline call | |
| 23 | // :9:17: note: called from here |
test/cases/compile_errors/signed_integer_remainder_division.zig created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | export fn foo(a: i32, b: i32) i32 { | |
| 2 | return a % b; | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage2 | |
| 7 | // target=native | |
| 8 | // | |
| 9 | // :2:12: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod |
test/cases/compile_errors/sizeOf_bad_type.zig created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | export fn entry() usize { | |
| 2 | return @sizeOf(@TypeOf(null)); | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage2 | |
| 7 | // target=native | |
| 8 | // | |
| 9 | // :2:20: error: no size available for type '@TypeOf(null)' |
test/cases/compile_errors/slice_cannot_have_its_bytes_reinterpreted.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | export fn foo() void { | |
| 2 | const bytes = [1]u8{ 0xfa } ** 16; | |
| 3 | var value = @ptrCast(*const []const u8, &bytes).*; | |
| 4 | _ = value; | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage2 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // :3:52: error: comptime dereference requires '[]const u8' to have a well-defined layout, but it does not. |
test/cases/compile_errors/slice_passed_as_array_init_type.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | export fn entry() void { | |
| 2 | const x = []u8{}; | |
| 3 | _ = x; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage2 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // :2:19: error: type '[]u8' does not support array initialization syntax | |
| 11 | // :2:19: note: inferred array length is specified with an underscore: '[_]u8' |
test/cases/compile_errors/slice_passed_as_array_init_type_with_elems.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | export fn entry() void { | |
| 2 | const x = []u8{1, 2}; | |
| 3 | _ = x; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage2 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // :2:19: error: type '[]u8' does not support array initialization syntax | |
| 11 | // :2:19: note: inferred array length is specified with an underscore: '[_]u8' |
test/cases/compile_errors/src_fields_runtime.zig created+14| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | pub export fn entry1() void { | |
| 2 | const s = @src(); | |
| 3 | comptime var a: []const u8 = s.file; | |
| 4 | comptime var b: []const u8 = s.fn_name; | |
| 5 | comptime var c: u32 = s.column; | |
| 6 | comptime var d: u32 = s.line; | |
| 7 | _ = a; _ = b; _ = c; _ = d; | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage2 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // :6:28: error: cannot store runtime value in compile time variable |
test/cases/compile_errors/stage1/non_compile_time_array_concatenation.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | fn f() []u8 { | |
| 2 | return s ++ "foo"; | |
| 3 | } | |
| 4 | var s: [10]u8 = undefined; | |
| 5 | export fn entry() usize { return @sizeOf(@TypeOf(f)); } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage1 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // tmp.zig:2:12: error: unable to evaluate constant expression |
test/cases/compile_errors/stage1/obj/array_access_of_type.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | export fn foo() void { | |
| 2 | var b: u8[40] = undefined; | |
| 3 | _ = b; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // tmp.zig:2:14: error: array access of non-array type 'type' |
test/cases/compile_errors/stage1/obj/method_call_with_first_arg_type_primitive.zig deleted-21| ... | ... | @@ -1,21 +0,0 @@ |
| 1 | const Foo = struct { | |
| 2 | x: i32, | |
| 3 | ||
| 4 | fn init(x: i32) Foo { | |
| 5 | return Foo { | |
| 6 | .x = x, | |
| 7 | }; | |
| 8 | } | |
| 9 | }; | |
| 10 | ||
| 11 | export fn f() void { | |
| 12 | const derp = Foo.init(3); | |
| 13 | ||
| 14 | derp.init(); | |
| 15 | } | |
| 16 | ||
| 17 | // error | |
| 18 | // backend=stage1 | |
| 19 | // target=native | |
| 20 | // | |
| 21 | // tmp.zig:14:5: error: expected type 'i32', found 'Foo' |
test/cases/compile_errors/stage1/obj/method_call_with_first_arg_type_wrong_container.zig deleted-30| ... | ... | @@ -1,30 +0,0 @@ |
| 1 | pub const List = struct { | |
| 2 | len: usize, | |
| 3 | allocator: *Allocator, | |
| 4 | ||
| 5 | pub fn init(allocator: *Allocator) List { | |
| 6 | return List { | |
| 7 | .len = 0, | |
| 8 | .allocator = allocator, | |
| 9 | }; | |
| 10 | } | |
| 11 | }; | |
| 12 | ||
| 13 | pub var global_allocator = Allocator { | |
| 14 | .field = 1234, | |
| 15 | }; | |
| 16 | ||
| 17 | pub const Allocator = struct { | |
| 18 | field: i32, | |
| 19 | }; | |
| 20 | ||
| 21 | export fn foo() void { | |
| 22 | var x = List.init(&global_allocator); | |
| 23 | x.init(); | |
| 24 | } | |
| 25 | ||
| 26 | // error | |
| 27 | // backend=stage1 | |
| 28 | // target=native | |
| 29 | // | |
| 30 | // tmp.zig:23:5: error: expected type '*Allocator', found '*List' |
test/cases/compile_errors/stage1/obj/missing_const_in_slice_with_nested_array_type.zig deleted-18| ... | ... | @@ -1,18 +0,0 @@ |
| 1 | const Geo3DTex2D = struct { vertices: [][2]f32 }; | |
| 2 | pub fn getGeo3DTex2D() Geo3DTex2D { | |
| 3 | return Geo3DTex2D{ | |
| 4 | .vertices = [_][2]f32{ | |
| 5 | [_]f32{ -0.5, -0.5}, | |
| 6 | }, | |
| 7 | }; | |
| 8 | } | |
| 9 | export fn entry() void { | |
| 10 | var geo_data = getGeo3DTex2D(); | |
| 11 | _ = geo_data; | |
| 12 | } | |
| 13 | ||
| 14 | // error | |
| 15 | // backend=stage1 | |
| 16 | // target=native | |
| 17 | // | |
| 18 | // tmp.zig:4:30: error: array literal requires address-of operator (&) to coerce to slice type '[][2]f32' |
test/cases/compile_errors/stage1/obj/mul_overflow_in_function_evaluation.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | const y = mul(300, 6000); | |
| 2 | fn mul(a: u16, b: u16) u16 { | |
| 3 | return a * b; | |
| 4 | } | |
| 5 | ||
| 6 | export fn entry() usize { return @sizeOf(@TypeOf(y)); } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:3:14: error: operation caused overflow |
test/cases/compile_errors/stage1/obj/negation_overflow_in_function_evaluation.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | const y = neg(-128); | |
| 2 | fn neg(x: i8) i8 { | |
| 3 | return -x; | |
| 4 | } | |
| 5 | ||
| 6 | export fn entry() usize { return @sizeOf(@TypeOf(y)); } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:3:12: error: negation caused overflow |
test/cases/compile_errors/stage1/obj/no_else_prong_on_switch_on_global_error_set.zig deleted-14| ... | ... | @@ -1,14 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | foo(error.A); | |
| 3 | } | |
| 4 | fn foo(a: anyerror) void { | |
| 5 | switch (a) { | |
| 6 | error.A => {}, | |
| 7 | } | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage1 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // tmp.zig:5:5: error: else prong required when switching on type 'anyerror' |
test/cases/compile_errors/stage1/obj/non-const_variables_of_things_that_require_const_variables.zig deleted-51| ... | ... | @@ -1,51 +0,0 @@ |
| 1 | export fn entry1() void { | |
| 2 | var m2 = &2; | |
| 3 | _ = m2; | |
| 4 | } | |
| 5 | export fn entry2() void { | |
| 6 | var a = undefined; | |
| 7 | _ = a; | |
| 8 | } | |
| 9 | export fn entry3() void { | |
| 10 | var b = 1; | |
| 11 | _ = b; | |
| 12 | } | |
| 13 | export fn entry4() void { | |
| 14 | var c = 1.0; | |
| 15 | _ = c; | |
| 16 | } | |
| 17 | export fn entry5() void { | |
| 18 | var d = null; | |
| 19 | _ = d; | |
| 20 | } | |
| 21 | export fn entry6(opaque_: *Opaque) void { | |
| 22 | var e = opaque_.*; | |
| 23 | _ = e; | |
| 24 | } | |
| 25 | export fn entry7() void { | |
| 26 | var f = i32; | |
| 27 | _ = f; | |
| 28 | } | |
| 29 | export fn entry8() void { | |
| 30 | var h = (Foo {}).bar; | |
| 31 | _ = h; | |
| 32 | } | |
| 33 | const Opaque = opaque {}; | |
| 34 | const Foo = struct { | |
| 35 | fn bar(self: *const Foo) void {_ = self;} | |
| 36 | }; | |
| 37 | ||
| 38 | // error | |
| 39 | // backend=stage1 | |
| 40 | // target=native | |
| 41 | // | |
| 42 | // tmp.zig:2:4: error: variable of type '*const comptime_int' must be const or comptime | |
| 43 | // tmp.zig:6:4: error: variable of type '@Type(.Undefined)' must be const or comptime | |
| 44 | // tmp.zig:10:4: error: variable of type 'comptime_int' must be const or comptime | |
| 45 | // tmp.zig:10:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type | |
| 46 | // tmp.zig:14:4: error: variable of type 'comptime_float' must be const or comptime | |
| 47 | // tmp.zig:14:4: note: to modify this variable at runtime, it must be given an explicit fixed-size number type | |
| 48 | // tmp.zig:18:4: error: variable of type '@Type(.Null)' must be const or comptime | |
| 49 | // tmp.zig:22:4: error: variable of type 'Opaque' not allowed | |
| 50 | // tmp.zig:26:4: error: variable of type 'type' must be const or comptime | |
| 51 | // tmp.zig:30:4: error: variable of type '(bound fn(*const Foo) void)' must be const or comptime |
test/cases/compile_errors/stage1/obj/non-inline_for_loop_on_a_type_that_requires_comptime.zig deleted-14| ... | ... | @@ -1,14 +0,0 @@ |
| 1 | const Foo = struct { | |
| 2 | name: []const u8, | |
| 3 | T: type, | |
| 4 | }; | |
| 5 | export fn entry() void { | |
| 6 | const xx: [2]Foo = undefined; | |
| 7 | for (xx) |f| { _ = f;} | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage1 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // tmp.zig:7:5: error: values of type 'Foo' must be comptime known, but index value is runtime known |
test/cases/compile_errors/stage1/obj/non_compile_time_array_concatenation.zig deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | fn f() []u8 { | |
| 2 | return s ++ "foo"; | |
| 3 | } | |
| 4 | var s: [10]u8 = undefined; | |
| 5 | export fn entry() usize { return @sizeOf(@TypeOf(f)); } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage1 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // tmp.zig:2:12: error: unable to evaluate constant expression |
test/cases/compile_errors/stage1/obj/non_constant_expression_in_array_size.zig deleted-14| ... | ... | @@ -1,14 +0,0 @@ |
| 1 | const Foo = struct { | |
| 2 | y: [get()]u8, | |
| 3 | }; | |
| 4 | var global_var: usize = 1; | |
| 5 | fn get() usize { return global_var; } | |
| 6 | ||
| 7 | export fn entry() usize { return @sizeOf(@TypeOf(Foo)); } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage1 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // tmp.zig:5:25: error: cannot store runtime value in compile time variable | |
| 14 | // tmp.zig:2:12: note: called from here |
test/cases/compile_errors/stage1/obj/non_error_sets_used_in_merge_error_sets_operator.zig deleted-17| ... | ... | @@ -1,17 +0,0 @@ |
| 1 | export fn foo() void { | |
| 2 | const Errors = u8 || u16; | |
| 3 | _ = Errors; | |
| 4 | } | |
| 5 | export fn bar() void { | |
| 6 | const Errors = error{} || u16; | |
| 7 | _ = Errors; | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage1 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // tmp.zig:2:20: error: expected error set type, found type 'u8' | |
| 15 | // tmp.zig:2:23: note: `||` merges error sets; `or` performs boolean OR | |
| 16 | // tmp.zig:6:31: error: expected error set type, found type 'u16' | |
| 17 | // tmp.zig:6:28: note: `||` merges error sets; `or` performs boolean OR |
test/cases/compile_errors/stage1/obj/panic_called_at_compile_time.zig deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | comptime { | |
| 3 | @panic("aoeu",); | |
| 4 | } | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage1 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // tmp.zig:3:9: error: encountered @panic at compile-time |
test/cases/compile_errors/stage1/obj/ptrCast_a_0_bit_type_to_a_non-_0_bit_type.zig deleted-13| ... | ... | @@ -1,13 +0,0 @@ |
| 1 | export fn entry() bool { | |
| 2 | var x: u0 = 0; | |
| 3 | const p = @ptrCast(?*u0, &x); | |
| 4 | return p == null; | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage1 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // tmp.zig:3:15: error: '*u0' and '?*u0' do not have the same in-memory representation | |
| 12 | // tmp.zig:3:31: note: '*u0' has no in-memory bits | |
| 13 | // tmp.zig:3:24: note: '?*u0' has in-memory bits |
test/cases/compile_errors/stage1/obj/ptrToInt_on_void.zig deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | export fn entry() bool { | |
| 2 | return @ptrToInt(&{}) == @ptrToInt(&{}); | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage1 | |
| 7 | // target=native | |
| 8 | // | |
| 9 | // tmp.zig:2:23: error: pointer to size 0 type has no address |
test/cases/compile_errors/stage1/obj/range_operator_in_switch_used_on_error_set.zig deleted-19| ... | ... | @@ -1,19 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | try foo(452) catch |err| switch (err) { | |
| 3 | error.A ... error.B => {}, | |
| 4 | else => {}, | |
| 5 | }; | |
| 6 | } | |
| 7 | fn foo(x: i32) !void { | |
| 8 | switch (x) { | |
| 9 | 0 ... 10 => return error.Foo, | |
| 10 | 11 ... 20 => return error.Bar, | |
| 11 | else => {}, | |
| 12 | } | |
| 13 | } | |
| 14 | ||
| 15 | // error | |
| 16 | // backend=stage1 | |
| 17 | // target=native | |
| 18 | // | |
| 19 | // tmp.zig:3:17: error: operator not allowed for errors |
test/cases/compile_errors/stage1/obj/reading_past_end_of_pointer_casted_array.zig deleted-13| ... | ... | @@ -1,13 +0,0 @@ |
| 1 | comptime { | |
| 2 | const array: [4]u8 = "aoeu".*; | |
| 3 | const sub_array = array[1..]; | |
| 4 | const int_ptr = @ptrCast(*const u24, sub_array); | |
| 5 | const deref = int_ptr.*; | |
| 6 | _ = deref; | |
| 7 | } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage1 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // tmp.zig:5:26: error: attempt to read 4 bytes from [4]u8 at index 1 which is 3 bytes |
test/cases/compile_errors/stage1/obj/recursive_inferred_error_set.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | foo() catch unreachable; | |
| 3 | } | |
| 4 | fn foo() !void { | |
| 5 | try foo(); | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:5:5: error: cannot resolve inferred error set '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set': function 'foo' not fully analyzed yet |
test/cases/compile_errors/stage1/obj/runtime_index_into_comptime_type_slice.zig deleted-17| ... | ... | @@ -1,17 +0,0 @@ |
| 1 | const Struct = struct { | |
| 2 | a: u32, | |
| 3 | }; | |
| 4 | fn getIndex() usize { | |
| 5 | return 2; | |
| 6 | } | |
| 7 | export fn entry() void { | |
| 8 | const index = getIndex(); | |
| 9 | const field = @typeInfo(Struct).Struct.fields[index]; | |
| 10 | _ = field; | |
| 11 | } | |
| 12 | ||
| 13 | // error | |
| 14 | // backend=stage1 | |
| 15 | // target=native | |
| 16 | // | |
| 17 | // tmp.zig:9:51: error: values of type 'std.builtin.Type.StructField' must be comptime known, but index value is runtime known |
test/cases/compile_errors/stage1/obj/setAlignStack_in_inline_function.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | foo(); | |
| 3 | } | |
| 4 | fn foo() callconv(.Inline) void { | |
| 5 | @setAlignStack(16); | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:5:5: error: @setAlignStack in inline function |
test/cases/compile_errors/stage1/obj/signed_integer_remainder_division.zig deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | export fn foo(a: i32, b: i32) i32 { | |
| 2 | return a % b; | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage1 | |
| 7 | // target=native | |
| 8 | // | |
| 9 | // tmp.zig:2:14: error: remainder division with 'i32' and 'i32': signed integers and floats must use @rem or @mod |
test/cases/compile_errors/stage1/obj/sizeOf_bad_type.zig deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | export fn entry() usize { | |
| 2 | return @sizeOf(@TypeOf(null)); | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage1 | |
| 7 | // target=native | |
| 8 | // | |
| 9 | // tmp.zig:2:20: error: no size available for type '@Type(.Null)' |
test/cases/compile_errors/stage1/obj/slice_cannot_have_its_bytes_reinterpreted.zig deleted-11| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | export fn foo() void { | |
| 2 | const bytes = [1]u8{ 0xfa } ** 16; | |
| 3 | var value = @ptrCast(*const []const u8, &bytes).*; | |
| 4 | _ = value; | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage1 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // :3:52: error: slice '[]const u8' cannot have its bytes reinterpreted |
test/cases/compile_errors/stage1/obj/slice_passed_as_array_init_type.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | const x = []u8{}; | |
| 3 | _ = x; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // tmp.zig:2:15: error: array literal requires address-of operator (&) to coerce to slice type '[]u8' |
test/cases/compile_errors/stage1/obj/slice_passed_as_array_init_type_with_elems.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | const x = []u8{1, 2}; | |
| 3 | _ = x; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // tmp.zig:2:15: error: array literal requires address-of operator (&) to coerce to slice type '[]u8' |
test/cases/compile_errors/stage1/obj/slicing_of_global_undefined_pointer.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | var buf: *[1]u8 = undefined; | |
| 2 | export fn entry() void { | |
| 3 | _ = buf[0..1]; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // tmp.zig:3:12: error: non-zero length slice of undefined pointer |
test/cases/compile_errors/stage1/obj/sub_overflow_in_function_evaluation.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | const y = sub(10, 20); | |
| 2 | fn sub(a: u16, b: u16) u16 { | |
| 3 | return a - b; | |
| 4 | } | |
| 5 | ||
| 6 | export fn entry() usize { return @sizeOf(@TypeOf(y)); } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:3:14: error: operation caused overflow |
test/cases/compile_errors/stage1/obj/switch_expression-duplicate_or_overlapping_integer_value.zig deleted-16| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | fn foo(x: u8) u8 { | |
| 2 | return switch (x) { | |
| 3 | 0 ... 100 => @as(u8, 0), | |
| 4 | 101 ... 200 => 1, | |
| 5 | 201, 203 ... 207 => 2, | |
| 6 | 206 ... 255 => 3, | |
| 7 | }; | |
| 8 | } | |
| 9 | export fn entry() usize { return @sizeOf(@TypeOf(foo)); } | |
| 10 | ||
| 11 | // error | |
| 12 | // backend=stage1 | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // tmp.zig:6:9: error: duplicate switch value | |
| 16 | // tmp.zig:5:14: note: previous value here |
test/cases/compile_errors/stage1/obj/switch_expression-switch_on_pointer_type_with_no_else.zig deleted-13| ... | ... | @@ -1,13 +0,0 @@ |
| 1 | fn foo(x: *u8) void { | |
| 2 | switch (x) { | |
| 3 | &y => {}, | |
| 4 | } | |
| 5 | } | |
| 6 | const y: u8 = 100; | |
| 7 | export fn entry() usize { return @sizeOf(@TypeOf(foo)); } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage1 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // tmp.zig:2:5: error: else prong required when switching on type '*u8' |
test/cases/compile_errors/stage1/obj/switch_expression-unreachable_else_prong_bool.zig deleted-14| ... | ... | @@ -1,14 +0,0 @@ |
| 1 | fn foo(x: bool) void { | |
| 2 | switch (x) { | |
| 3 | true => {}, | |
| 4 | false => {}, | |
| 5 | else => {}, | |
| 6 | } | |
| 7 | } | |
| 8 | export fn entry() usize { return @sizeOf(@TypeOf(foo)); } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage1 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // tmp.zig:5:9: error: unreachable else prong, all cases already handled |
test/cases/compile_errors/stage1/obj/switch_on_union_with_no_attached_enum.zig deleted-22| ... | ... | @@ -1,22 +0,0 @@ |
| 1 | const Payload = union { | |
| 2 | A: i32, | |
| 3 | B: f64, | |
| 4 | C: bool, | |
| 5 | }; | |
| 6 | export fn entry() void { | |
| 7 | const a = Payload { .A = 1234 }; | |
| 8 | foo(a); | |
| 9 | } | |
| 10 | fn foo(a: *const Payload) void { | |
| 11 | switch (a.*) { | |
| 12 | Payload.A => {}, | |
| 13 | else => unreachable, | |
| 14 | } | |
| 15 | } | |
| 16 | ||
| 17 | // error | |
| 18 | // backend=stage1 | |
| 19 | // target=native | |
| 20 | // | |
| 21 | // tmp.zig:11:14: error: switch on union which has no attached enum | |
| 22 | // tmp.zig:1:17: note: consider 'union(enum)' here |
test/cases/compile_errors/stage1/obj/switch_with_invalid_expression_parameter.zig deleted-17| ... | ... | @@ -1,17 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | Test(i32); | |
| 3 | } | |
| 4 | fn Test(comptime T: type) void { | |
| 5 | const x = switch (T) { | |
| 6 | []u8 => |x| x, | |
| 7 | i32 => |x| x, | |
| 8 | else => unreachable, | |
| 9 | }; | |
| 10 | _ = x; | |
| 11 | } | |
| 12 | ||
| 13 | // error | |
| 14 | // backend=stage1 | |
| 15 | // target=native | |
| 16 | // | |
| 17 | // tmp.zig:7:17: error: switch on type 'type' provides no expression parameter |
test/cases/compile_errors/stage1/obj/switch_with_overlapping_case_ranges.zig deleted-13| ... | ... | @@ -1,13 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | var q: u8 = 0; | |
| 3 | switch (q) { | |
| 4 | 1...2 => {}, | |
| 5 | 0...255 => {}, | |
| 6 | } | |
| 7 | } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage1 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // tmp.zig:5:9: error: duplicate switch value |
test/cases/compile_errors/stage1/obj/tagName_used_on_union_with_no_associated_enum_tag.zig deleted-16| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | const FloatInt = extern union { | |
| 2 | Float: f32, | |
| 3 | Int: i32, | |
| 4 | }; | |
| 5 | export fn entry() void { | |
| 6 | var fi = FloatInt{.Float = 123.45}; | |
| 7 | var tagName = @tagName(fi); | |
| 8 | _ = tagName; | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // backend=stage1 | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // tmp.zig:7:19: error: union has no associated enum | |
| 16 | // tmp.zig:1:18: note: declared here |
test/cases/compile_errors/stage1/obj/type_variables_must_be_constant.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | var foo = u8; | |
| 2 | export fn entry() foo { | |
| 3 | return 1; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // :1:1: error: variable of type 'type' must be constant |
test/cases/compile_errors/stage1/obj/unreachable_executed_at_comptime.zig deleted-16| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | fn foo(comptime x: i32) i32 { | |
| 2 | comptime { | |
| 3 | if (x >= 0) return -x; | |
| 4 | unreachable; | |
| 5 | } | |
| 6 | } | |
| 7 | export fn entry() void { | |
| 8 | _ = foo(-42); | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // backend=stage1 | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // tmp.zig:4:9: error: reached unreachable code | |
| 16 | // tmp.zig:8:12: note: called from here |
test/cases/compile_errors/stage1/obj/use_of_comptime-known_undefined_function_value.zig deleted-13| ... | ... | @@ -1,13 +0,0 @@ |
| 1 | const Cmd = struct { | |
| 2 | exec: fn () void, | |
| 3 | }; | |
| 4 | export fn entry() void { | |
| 5 | const command = Cmd{ .exec = undefined }; | |
| 6 | command.exec(); | |
| 7 | } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage1 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // tmp.zig:6:12: error: use of undefined value here causes undefined behavior |
test/cases/compile_errors/stage1/obj/wasmMemoryGrow_is_a_compile_error_in_non-Wasm_targets.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | export fn foo() void { | |
| 2 | _ = @wasmMemoryGrow(0, 1); | |
| 3 | return; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // tmp.zig:2:9: error: @wasmMemoryGrow is a wasm32 feature only |
test/cases/compile_errors/stage1/obj/wasmMemorySize_is_a_compile_error_in_non-Wasm_targets.zig deleted-10| ... | ... | @@ -1,10 +0,0 @@ |
| 1 | export fn foo() void { | |
| 2 | _ = @wasmMemorySize(0); | |
| 3 | return; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // tmp.zig:2:9: error: @wasmMemorySize is a wasm32 feature only |
test/cases/compile_errors/stage1/obj/wrong_type_for_reify_type.zig deleted-9| ... | ... | @@ -1,9 +0,0 @@ |
| 1 | export fn entry() void { | |
| 2 | _ = @Type(0); | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage1 | |
| 7 | // target=native | |
| 8 | // | |
| 9 | // tmp.zig:2:15: error: expected type 'std.builtin.Type', found 'comptime_int' |
test/cases/compile_errors/stage1/ptrCast_a_0_bit_type_to_a_non-_0_bit_type.zig created+13| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | export fn entry() bool { | |
| 2 | var x: u0 = 0; | |
| 3 | const p = @ptrCast(?*u0, &x); | |
| 4 | return p == null; | |
| 5 | } | |
| 6 | ||
| 7 | // error | |
| 8 | // backend=stage1 | |
| 9 | // target=native | |
| 10 | // | |
| 11 | // tmp.zig:3:15: error: '*u0' and '?*u0' do not have the same in-memory representation | |
| 12 | // tmp.zig:3:31: note: '*u0' has no in-memory bits | |
| 13 | // tmp.zig:3:24: note: '?*u0' has in-memory bits |
test/cases/compile_errors/stage1/ptrToInt_on_void.zig created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | export fn entry() bool { | |
| 2 | return @ptrToInt(&{}) == @ptrToInt(&{}); | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage1 | |
| 7 | // target=native | |
| 8 | // | |
| 9 | // tmp.zig:2:23: error: pointer to size 0 type has no address |
test/cases/compile_errors/stage1/recursive_inferred_error_set.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | export fn entry() void { | |
| 2 | foo() catch unreachable; | |
| 3 | } | |
| 4 | fn foo() !void { | |
| 5 | try foo(); | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:5:5: error: cannot resolve inferred error set '@typeInfo(@typeInfo(@TypeOf(foo)).Fn.return_type.?).ErrorUnion.error_set': function 'foo' not fully analyzed yet |
test/cases/compile_errors/stage1/slicing_of_global_undefined_pointer.zig created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | var buf: *[1]u8 = undefined; | |
| 2 | export fn entry() void { | |
| 3 | _ = buf[0..1]; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage1 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // tmp.zig:3:12: error: non-zero length slice of undefined pointer |
test/cases/compile_errors/stage1/switch_with_invalid_expression_parameter.zig created+17| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | export fn entry() void { | |
| 2 | Test(i32); | |
| 3 | } | |
| 4 | fn Test(comptime T: type) void { | |
| 5 | const x = switch (T) { | |
| 6 | []u8 => |x| x, | |
| 7 | i32 => |x| x, | |
| 8 | else => unreachable, | |
| 9 | }; | |
| 10 | _ = x; | |
| 11 | } | |
| 12 | ||
| 13 | // error | |
| 14 | // backend=stage1 | |
| 15 | // target=native | |
| 16 | // | |
| 17 | // tmp.zig:7:17: error: switch on type 'type' provides no expression parameter |
test/cases/compile_errors/stage1/use_of_comptime-known_undefined_function_value.zig created+13| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | const Cmd = struct { | |
| 2 | exec: fn () void, | |
| 3 | }; | |
| 4 | export fn entry() void { | |
| 5 | const command = Cmd{ .exec = undefined }; | |
| 6 | command.exec(); | |
| 7 | } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage1 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // tmp.zig:6:12: error: use of undefined value here causes undefined behavior |
test/cases/compile_errors/stage2/out_of_bounds_index.zig+4-4| ... | ... | @@ -23,7 +23,7 @@ comptime { |
| 23 | 23 | // error |
| 24 | 24 | // target=native |
| 25 | 25 | // |
| 26 | // :4:26: error: end index 6 out of bounds for slice of length 4 +1 (sentinel) | |
| 27 | // :9:22: error: end index 6 out of bounds for array of length 4 +1 (sentinel) | |
| 28 | // :14:22: error: end index 5 out of bounds for array of length 4 | |
| 29 | // :19:22: error: start index 3 is larger than end index 2 | |
| 26 | // :4:30: error: end index 6 out of bounds for slice of length 4 +1 (sentinel) | |
| 27 | // :9:26: error: end index 6 out of bounds for array of length 4 +1 (sentinel) | |
| 28 | // :14:26: error: end index 5 out of bounds for array of length 4 | |
| 29 | // :19:23: error: start index 3 is larger than end index 2 |
test/cases/compile_errors/sub_overflow_in_function_evaluation.zig created+13| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | const y = sub(10, 20); | |
| 2 | fn sub(a: u16, b: u16) u16 { | |
| 3 | return a - b; | |
| 4 | } | |
| 5 | ||
| 6 | export fn entry() usize { return @sizeOf(@TypeOf(&y)); } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage2 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // :3:14: error: overflow of integer type 'u16' with value '-10' | |
| 13 | // :1:14: note: called from here |
test/cases/compile_errors/switch_expression-duplicate_or_overlapping_integer_value.zig created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | fn foo(x: u8) u8 { | |
| 2 | return switch (x) { | |
| 3 | 0 ... 100 => @as(u8, 0), | |
| 4 | 101 ... 200 => 1, | |
| 5 | 201, 203 ... 207 => 2, | |
| 6 | 206 ... 255 => 3, | |
| 7 | }; | |
| 8 | } | |
| 9 | export fn entry() usize { return @sizeOf(@TypeOf(&foo)); } | |
| 10 | ||
| 11 | // error | |
| 12 | // backend=stage2 | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // :6:13: error: duplicate switch value | |
| 16 | // :5:18: note: previous value here |
test/cases/compile_errors/switch_expression-switch_on_pointer_type_with_no_else.zig created+13| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | fn foo(x: *u8) void { | |
| 2 | switch (x) { | |
| 3 | &y => {}, | |
| 4 | } | |
| 5 | } | |
| 6 | var y: u8 = 100; | |
| 7 | export fn entry() usize { return @sizeOf(@TypeOf(&foo)); } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage2 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // :2:5: error: else prong required when switching on type '*u8' |
test/cases/compile_errors/switch_expression-unreachable_else_prong_bool.zig created+14| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | fn foo(x: bool) void { | |
| 2 | switch (x) { | |
| 3 | true => {}, | |
| 4 | false => {}, | |
| 5 | else => {}, | |
| 6 | } | |
| 7 | } | |
| 8 | export fn entry() usize { return @sizeOf(@TypeOf(&foo)); } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage2 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // :5:14: error: unreachable else prong; all cases already handled |
test/cases/compile_errors/switch_on_union_with_no_attached_enum.zig created+22| ... | ... | @@ -0,0 +1,22 @@ |
| 1 | const Payload = union { | |
| 2 | A: i32, | |
| 3 | B: f64, | |
| 4 | C: bool, | |
| 5 | }; | |
| 6 | export fn entry() void { | |
| 7 | const a = Payload { .A = 1234 }; | |
| 8 | foo(&a); | |
| 9 | } | |
| 10 | fn foo(a: *const Payload) void { | |
| 11 | switch (a.*) { | |
| 12 | Payload.A => {}, | |
| 13 | else => unreachable, | |
| 14 | } | |
| 15 | } | |
| 16 | ||
| 17 | // error | |
| 18 | // backend=stage2 | |
| 19 | // target=native | |
| 20 | // | |
| 21 | // :11:14: error: switch on union with no attached enum | |
| 22 | // :1:17: note: consider 'union(enum)' here |
test/cases/compile_errors/switch_with_overlapping_case_ranges.zig created+14| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | export fn entry() void { | |
| 2 | var q: u8 = 0; | |
| 3 | switch (q) { | |
| 4 | 1...2 => {}, | |
| 5 | 0...255 => {}, | |
| 6 | } | |
| 7 | } | |
| 8 | ||
| 9 | // error | |
| 10 | // backend=stage2 | |
| 11 | // target=native | |
| 12 | // | |
| 13 | // :5:10: error: duplicate switch value | |
| 14 | // :4:10: note: previous value here |
test/cases/compile_errors/tagName_used_on_union_with_no_associated_enum_tag.zig created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | const FloatInt = extern union { | |
| 2 | Float: f32, | |
| 3 | Int: i32, | |
| 4 | }; | |
| 5 | export fn entry() void { | |
| 6 | var fi = FloatInt{.Float = 123.45}; | |
| 7 | var tagName = @tagName(fi); | |
| 8 | _ = tagName; | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // backend=stage2 | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // :7:19: error: union 'tmp.FloatInt' is untagged | |
| 16 | // :1:25: note: union declared here |
test/cases/compile_errors/type_variables_must_be_constant.zig created+11| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | var foo = u8; | |
| 2 | export fn entry() foo { | |
| 3 | return 1; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage2 | |
| 8 | // target=native | |
| 9 | // | |
| 10 | // :1:1: error: variable of type 'type' must be const or comptime | |
| 11 | // :1:1: note: types are not available at runtime |
test/cases/compile_errors/unreachable_executed_at_comptime.zig created+16| ... | ... | @@ -0,0 +1,16 @@ |
| 1 | fn foo(comptime x: i32) i32 { | |
| 2 | comptime { | |
| 3 | if (x >= 0) return -x; | |
| 4 | unreachable; | |
| 5 | } | |
| 6 | } | |
| 7 | export fn entry() void { | |
| 8 | _ = comptime foo(-42); | |
| 9 | } | |
| 10 | ||
| 11 | // error | |
| 12 | // backend=stage2 | |
| 13 | // target=native | |
| 14 | // | |
| 15 | // :4:9: error: reached unreachable code | |
| 16 | // :8:21: note: called from here |
test/cases/compile_errors/unreachable_variable.zig+1-1| ... | ... | @@ -7,4 +7,4 @@ export fn f() void { |
| 7 | 7 | // backend=stage2 |
| 8 | 8 | // target=native |
| 9 | 9 | // |
| 10 | // :2:25: error: expected type 'noreturn', found 'void' | |
| 10 | // :2:25: error: cannot cast to noreturn |
test/cases/compile_errors/use_invalid_number_literal_as_array_index.zig+1| ... | ... | @@ -9,3 +9,4 @@ export fn entry() void { |
| 9 | 9 | // target=native |
| 10 | 10 | // |
| 11 | 11 | // :1:1: error: variable of type 'comptime_int' must be const or comptime |
| 12 | // :1:1: note: to modify this variable at runtime, it must be given an explicit fixed-size number type |
test/cases/compile_errors/wasmMemoryGrow_is_a_compile_error_in_non-Wasm_targets.zig created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | export fn foo() void { | |
| 2 | _ = @wasmMemoryGrow(0, 1); | |
| 3 | return; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage2 | |
| 8 | // target=x86_64-native | |
| 9 | // | |
| 10 | // :2:9: error: builtin @wasmMemoryGrow is available when targeting WebAssembly; targeted CPU architecture is x86_64 |
test/cases/compile_errors/wasmMemorySize_is_a_compile_error_in_non-Wasm_targets.zig created+10| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | export fn foo() void { | |
| 2 | _ = @wasmMemorySize(0); | |
| 3 | return; | |
| 4 | } | |
| 5 | ||
| 6 | // error | |
| 7 | // backend=stage2 | |
| 8 | // target=x86_64-native | |
| 9 | // | |
| 10 | // :2:9: error: builtin @wasmMemorySize is available when targeting WebAssembly; targeted CPU architecture is x86_64 |
test/cases/compile_errors/wrong_type_for_reify_type.zig created+9| ... | ... | @@ -0,0 +1,9 @@ |
| 1 | export fn entry() void { | |
| 2 | _ = @Type(0); | |
| 3 | } | |
| 4 | ||
| 5 | // error | |
| 6 | // backend=stage2 | |
| 7 | // target=native | |
| 8 | // | |
| 9 | // :2:15: error: expected type 'builtin.Type', found 'comptime_int' |