| author | |
| committer | |
| log | 6bf193af192ffaf3465958a243ec8fc8941cfe4d |
| tree | 7271c30c7c6657765535002421c65a2377171477 |
| parent | 60025a37045835c8bbf914eccdbeba6d6e2c275f |
| signature |
somewhere along this branch, #1901 has been fixed.14 files changed, 281 insertions(+), 169 deletions(-)
BRANCH_TODO+1-4| ... | ... | @@ -4,10 +4,7 @@ Scratch pad for stuff to do before merging master |
| 4 | 4 | uncomment all the behavior tests |
| 5 | 5 | diff master branch to make sure |
| 6 | 6 | |
| 7 | restore test_runner.zig to master branch | |
| 8 | - also the default panic function and unexpected_error_tracing. see the commit | |
| 9 | that adds this text to BRANCH_TODO file. | |
| 10 | - and std/specia/bootstrap.zig | |
| 7 | restore bootstrap.zig to master | |
| 11 | 8 | |
| 12 | 9 | get an empty file compiling successfully (with no panic fn override) |
| 13 | 10 |
src/all_types.hpp+21-3| ... | ... | @@ -2257,7 +2257,8 @@ enum IrInstructionId { |
| 2257 | 2257 | IrInstructionIdHandle, |
| 2258 | 2258 | IrInstructionIdAlignOf, |
| 2259 | 2259 | IrInstructionIdOverflowOp, |
| 2260 | IrInstructionIdTestErr, | |
| 2260 | IrInstructionIdTestErrSrc, | |
| 2261 | IrInstructionIdTestErrGen, | |
| 2261 | 2262 | IrInstructionIdUnwrapErrCode, |
| 2262 | 2263 | IrInstructionIdUnwrapErrPayload, |
| 2263 | 2264 | IrInstructionIdErrWrapCode, |
| ... | ... | @@ -2292,6 +2293,7 @@ enum IrInstructionId { |
| 2292 | 2293 | IrInstructionIdAlignCast, |
| 2293 | 2294 | IrInstructionIdImplicitCast, |
| 2294 | 2295 | IrInstructionIdResolveResult, |
| 2296 | IrInstructionIdResultPtr, | |
| 2295 | 2297 | IrInstructionIdOpaqueType, |
| 2296 | 2298 | IrInstructionIdSetAlignStack, |
| 2297 | 2299 | IrInstructionIdArgType, |
| ... | ... | @@ -3082,10 +3084,16 @@ struct IrInstructionAlignOf { |
| 3082 | 3084 | }; |
| 3083 | 3085 | |
| 3084 | 3086 | // returns true if error, returns false if not error |
| 3085 | struct IrInstructionTestErr { | |
| 3087 | struct IrInstructionTestErrSrc { | |
| 3086 | 3088 | IrInstruction base; |
| 3087 | 3089 | |
| 3088 | IrInstruction *value; | |
| 3090 | IrInstruction *base_ptr; | |
| 3091 | }; | |
| 3092 | ||
| 3093 | struct IrInstructionTestErrGen { | |
| 3094 | IrInstruction base; | |
| 3095 | ||
| 3096 | IrInstruction *err_union; | |
| 3089 | 3097 | }; |
| 3090 | 3098 | |
| 3091 | 3099 | // Takes an error union pointer, returns a pointer to the error code. |
| ... | ... | @@ -3596,6 +3604,7 @@ struct IrInstructionImplicitCast { |
| 3596 | 3604 | ResultLoc *result_loc; |
| 3597 | 3605 | }; |
| 3598 | 3606 | |
| 3607 | // This one is for writing through the result pointer. | |
| 3599 | 3608 | struct IrInstructionResolveResult { |
| 3600 | 3609 | IrInstruction base; |
| 3601 | 3610 | |
| ... | ... | @@ -3603,6 +3612,15 @@ struct IrInstructionResolveResult { |
| 3603 | 3612 | IrInstruction *ty; |
| 3604 | 3613 | }; |
| 3605 | 3614 | |
| 3615 | // This one is when you want to read the value of the result. | |
| 3616 | // You have to give the value in case it is comptime. | |
| 3617 | struct IrInstructionResultPtr { | |
| 3618 | IrInstruction base; | |
| 3619 | ||
| 3620 | ResultLoc *result_loc; | |
| 3621 | IrInstruction *result; | |
| 3622 | }; | |
| 3623 | ||
| 3606 | 3624 | struct IrInstructionPtrOfArrayToSlice { |
| 3607 | 3625 | IrInstruction base; |
| 3608 | 3626 |
src/codegen.cpp+25-11| ... | ... | @@ -1323,7 +1323,9 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) { |
| 1323 | 1323 | LLVMBuildRetVoid(g->builder); |
| 1324 | 1324 | |
| 1325 | 1325 | LLVMPositionBuilderAtEnd(g->builder, prev_block); |
| 1326 | LLVMSetCurrentDebugLocation(g->builder, prev_debug_location); | |
| 1326 | if (!g->strip_debug_symbols) { | |
| 1327 | LLVMSetCurrentDebugLocation(g->builder, prev_debug_location); | |
| 1328 | } | |
| 1327 | 1329 | |
| 1328 | 1330 | g->add_error_return_trace_addr_fn_val = fn_val; |
| 1329 | 1331 | return fn_val; |
| ... | ... | @@ -1454,7 +1456,9 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) { |
| 1454 | 1456 | LLVMBuildBr(g->builder, loop_block); |
| 1455 | 1457 | |
| 1456 | 1458 | LLVMPositionBuilderAtEnd(g->builder, prev_block); |
| 1457 | LLVMSetCurrentDebugLocation(g->builder, prev_debug_location); | |
| 1459 | if (!g->strip_debug_symbols) { | |
| 1460 | LLVMSetCurrentDebugLocation(g->builder, prev_debug_location); | |
| 1461 | } | |
| 1458 | 1462 | |
| 1459 | 1463 | g->merge_err_ret_traces_fn_val = fn_val; |
| 1460 | 1464 | return fn_val; |
| ... | ... | @@ -1510,7 +1514,9 @@ static LLVMValueRef get_return_err_fn(CodeGen *g) { |
| 1510 | 1514 | LLVMBuildRetVoid(g->builder); |
| 1511 | 1515 | |
| 1512 | 1516 | LLVMPositionBuilderAtEnd(g->builder, prev_block); |
| 1513 | LLVMSetCurrentDebugLocation(g->builder, prev_debug_location); | |
| 1517 | if (!g->strip_debug_symbols) { | |
| 1518 | LLVMSetCurrentDebugLocation(g->builder, prev_debug_location); | |
| 1519 | } | |
| 1514 | 1520 | |
| 1515 | 1521 | g->return_err_fn = fn_val; |
| 1516 | 1522 | return fn_val; |
| ... | ... | @@ -1638,7 +1644,9 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) { |
| 1638 | 1644 | gen_panic(g, msg_slice, err_ret_trace_arg); |
| 1639 | 1645 | |
| 1640 | 1646 | LLVMPositionBuilderAtEnd(g->builder, prev_block); |
| 1641 | LLVMSetCurrentDebugLocation(g->builder, prev_debug_location); | |
| 1647 | if (!g->strip_debug_symbols) { | |
| 1648 | LLVMSetCurrentDebugLocation(g->builder, prev_debug_location); | |
| 1649 | } | |
| 1642 | 1650 | |
| 1643 | 1651 | g->safety_crash_err_fn = fn_val; |
| 1644 | 1652 | return fn_val; |
| ... | ... | @@ -4353,7 +4361,9 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) { |
| 4353 | 4361 | g->cur_fn = prev_cur_fn; |
| 4354 | 4362 | g->cur_fn_val = prev_cur_fn_val; |
| 4355 | 4363 | LLVMPositionBuilderAtEnd(g->builder, prev_block); |
| 4356 | LLVMSetCurrentDebugLocation(g->builder, prev_debug_location); | |
| 4364 | if (!g->strip_debug_symbols) { | |
| 4365 | LLVMSetCurrentDebugLocation(g->builder, prev_debug_location); | |
| 4366 | } | |
| 4357 | 4367 | |
| 4358 | 4368 | enum_type->data.enumeration.name_function = fn_val; |
| 4359 | 4369 | return fn_val; |
| ... | ... | @@ -4880,10 +4890,10 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable, |
| 4880 | 4890 | return overflow_bit; |
| 4881 | 4891 | } |
| 4882 | 4892 | |
| 4883 | static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrInstructionTestErr *instruction) { | |
| 4884 | ZigType *err_union_type = instruction->value->value.type; | |
| 4893 | static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrInstructionTestErrGen *instruction) { | |
| 4894 | ZigType *err_union_type = instruction->err_union->value.type; | |
| 4885 | 4895 | ZigType *payload_type = err_union_type->data.error_union.payload_type; |
| 4886 | LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->value); | |
| 4896 | LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->err_union); | |
| 4887 | 4897 | |
| 4888 | 4898 | LLVMValueRef err_val; |
| 4889 | 4899 | if (type_has_bits(payload_type)) { |
| ... | ... | @@ -5276,7 +5286,9 @@ static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_f |
| 5276 | 5286 | g->cur_fn = prev_cur_fn; |
| 5277 | 5287 | g->cur_fn_val = prev_cur_fn_val; |
| 5278 | 5288 | LLVMPositionBuilderAtEnd(g->builder, prev_block); |
| 5279 | LLVMSetCurrentDebugLocation(g->builder, prev_debug_location); | |
| 5289 | if (!g->strip_debug_symbols) { | |
| 5290 | LLVMSetCurrentDebugLocation(g->builder, prev_debug_location); | |
| 5291 | } | |
| 5280 | 5292 | |
| 5281 | 5293 | g->coro_alloc_helper_fn_val = fn_val; |
| 5282 | 5294 | return fn_val; |
| ... | ... | @@ -5549,10 +5561,12 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, |
| 5549 | 5561 | case IrInstructionIdAllocaGen: |
| 5550 | 5562 | case IrInstructionIdImplicitCast: |
| 5551 | 5563 | case IrInstructionIdResolveResult: |
| 5564 | case IrInstructionIdResultPtr: | |
| 5552 | 5565 | case IrInstructionIdContainerInitList: |
| 5553 | 5566 | case IrInstructionIdSliceSrc: |
| 5554 | 5567 | case IrInstructionIdRef: |
| 5555 | 5568 | case IrInstructionIdBitCastSrc: |
| 5569 | case IrInstructionIdTestErrSrc: | |
| 5556 | 5570 | zig_unreachable(); |
| 5557 | 5571 | |
| 5558 | 5572 | case IrInstructionIdDeclVarGen: |
| ... | ... | @@ -5635,8 +5649,8 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, |
| 5635 | 5649 | return ir_render_handle(g, executable, (IrInstructionHandle *)instruction); |
| 5636 | 5650 | case IrInstructionIdOverflowOp: |
| 5637 | 5651 | return ir_render_overflow_op(g, executable, (IrInstructionOverflowOp *)instruction); |
| 5638 | case IrInstructionIdTestErr: | |
| 5639 | return ir_render_test_err(g, executable, (IrInstructionTestErr *)instruction); | |
| 5652 | case IrInstructionIdTestErrGen: | |
| 5653 | return ir_render_test_err(g, executable, (IrInstructionTestErrGen *)instruction); | |
| 5640 | 5654 | case IrInstructionIdUnwrapErrCode: |
| 5641 | 5655 | return ir_render_unwrap_err_code(g, executable, (IrInstructionUnwrapErrCode *)instruction); |
| 5642 | 5656 | case IrInstructionIdUnwrapErrPayload: |
src/ir.cpp+86-28| ... | ... | @@ -756,8 +756,12 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionOverflowOp *) { |
| 756 | 756 | return IrInstructionIdOverflowOp; |
| 757 | 757 | } |
| 758 | 758 | |
| 759 | static constexpr IrInstructionId ir_instruction_id(IrInstructionTestErr *) { | |
| 760 | return IrInstructionIdTestErr; | |
| 759 | static constexpr IrInstructionId ir_instruction_id(IrInstructionTestErrSrc *) { | |
| 760 | return IrInstructionIdTestErrSrc; | |
| 761 | } | |
| 762 | ||
| 763 | static constexpr IrInstructionId ir_instruction_id(IrInstructionTestErrGen *) { | |
| 764 | return IrInstructionIdTestErrGen; | |
| 761 | 765 | } |
| 762 | 766 | |
| 763 | 767 | static constexpr IrInstructionId ir_instruction_id(IrInstructionUnwrapErrCode *) { |
| ... | ... | @@ -900,6 +904,10 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionResolveResult *) |
| 900 | 904 | return IrInstructionIdResolveResult; |
| 901 | 905 | } |
| 902 | 906 | |
| 907 | static constexpr IrInstructionId ir_instruction_id(IrInstructionResultPtr *) { | |
| 908 | return IrInstructionIdResultPtr; | |
| 909 | } | |
| 910 | ||
| 903 | 911 | static constexpr IrInstructionId ir_instruction_id(IrInstructionPtrOfArrayToSlice *) { |
| 904 | 912 | return IrInstructionIdPtrOfArrayToSlice; |
| 905 | 913 | } |
| ... | ... | @@ -2418,13 +2426,26 @@ static IrInstruction *ir_build_align_of(IrBuilder *irb, Scope *scope, AstNode *s |
| 2418 | 2426 | return &instruction->base; |
| 2419 | 2427 | } |
| 2420 | 2428 | |
| 2421 | static IrInstruction *ir_build_test_err(IrBuilder *irb, Scope *scope, AstNode *source_node, | |
| 2422 | IrInstruction *value) | |
| 2429 | static IrInstruction *ir_build_test_err_src(IrBuilder *irb, Scope *scope, AstNode *source_node, | |
| 2430 | IrInstruction *base_ptr) | |
| 2423 | 2431 | { |
| 2424 | IrInstructionTestErr *instruction = ir_build_instruction<IrInstructionTestErr>(irb, scope, source_node); | |
| 2425 | instruction->value = value; | |
| 2432 | IrInstructionTestErrSrc *instruction = ir_build_instruction<IrInstructionTestErrSrc>(irb, scope, source_node); | |
| 2433 | instruction->base_ptr = base_ptr; | |
| 2426 | 2434 | |
| 2427 | ir_ref_instruction(value, irb->current_basic_block); | |
| 2435 | ir_ref_instruction(base_ptr, irb->current_basic_block); | |
| 2436 | ||
| 2437 | return &instruction->base; | |
| 2438 | } | |
| 2439 | ||
| 2440 | static IrInstruction *ir_build_test_err_gen(IrAnalyze *ira, IrInstruction *source_instruction, | |
| 2441 | IrInstruction *err_union) | |
| 2442 | { | |
| 2443 | IrInstructionTestErrGen *instruction = ir_build_instruction<IrInstructionTestErrGen>( | |
| 2444 | &ira->new_irb, source_instruction->scope, source_instruction->source_node); | |
| 2445 | instruction->base.value.type = ira->codegen->builtin_types.entry_bool; | |
| 2446 | instruction->err_union = err_union; | |
| 2447 | ||
| 2448 | ir_ref_instruction(err_union, ira->new_irb.current_basic_block); | |
| 2428 | 2449 | |
| 2429 | 2450 | return &instruction->base; |
| 2430 | 2451 | } |
| ... | ... | @@ -2844,6 +2865,18 @@ static IrInstruction *ir_build_resolve_result(IrBuilder *irb, Scope *scope, AstN |
| 2844 | 2865 | return &instruction->base; |
| 2845 | 2866 | } |
| 2846 | 2867 | |
| 2868 | static IrInstruction *ir_build_result_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, | |
| 2869 | ResultLoc *result_loc, IrInstruction *result) | |
| 2870 | { | |
| 2871 | IrInstructionResultPtr *instruction = ir_build_instruction<IrInstructionResultPtr>(irb, scope, source_node); | |
| 2872 | instruction->result_loc = result_loc; | |
| 2873 | instruction->result = result; | |
| 2874 | ||
| 2875 | ir_ref_instruction(result, irb->current_basic_block); | |
| 2876 | ||
| 2877 | return &instruction->base; | |
| 2878 | } | |
| 2879 | ||
| 2847 | 2880 | static IrInstruction *ir_build_opaque_type(IrBuilder *irb, Scope *scope, AstNode *source_node) { |
| 2848 | 2881 | IrInstructionOpaqueType *instruction = ir_build_instruction<IrInstructionOpaqueType>(irb, scope, source_node); |
| 2849 | 2882 | |
| ... | ... | @@ -3531,7 +3564,9 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 3531 | 3564 | ir_gen_defers_for_block(irb, scope, outer_scope, false); |
| 3532 | 3565 | } |
| 3533 | 3566 | |
| 3534 | IrInstruction *is_err = ir_build_test_err(irb, scope, node, return_value); | |
| 3567 | IrInstruction *ret_ptr = ir_build_result_ptr(irb, scope, node, &result_loc_ret->base, | |
| 3568 | return_value); | |
| 3569 | IrInstruction *is_err = ir_build_test_err_src(irb, scope, node, ret_ptr); | |
| 3535 | 3570 | |
| 3536 | 3571 | bool should_inline = ir_should_inline(irb->exec, scope); |
| 3537 | 3572 | IrInstruction *is_comptime; |
| ... | ... | @@ -3577,8 +3612,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, |
| 3577 | 3612 | IrInstruction *err_union_ptr = ir_gen_node_extra(irb, expr_node, scope, LValPtr, nullptr); |
| 3578 | 3613 | if (err_union_ptr == irb->codegen->invalid_instruction) |
| 3579 | 3614 | return irb->codegen->invalid_instruction; |
| 3580 | IrInstruction *err_union_val = ir_build_load_ptr(irb, scope, node, err_union_ptr); | |
| 3581 | IrInstruction *is_err_val = ir_build_test_err(irb, scope, node, err_union_val); | |
| 3615 | IrInstruction *is_err_val = ir_build_test_err_src(irb, scope, node, err_union_ptr); | |
| 3582 | 3616 | |
| 3583 | 3617 | IrBasicBlock *return_block = ir_create_basic_block(irb, scope, "ErrRetReturn"); |
| 3584 | 3618 | IrBasicBlock *continue_block = ir_create_basic_block(irb, scope, "ErrRetContinue"); |
| ... | ... | @@ -5940,8 +5974,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n |
| 5940 | 5974 | LValPtr, nullptr); |
| 5941 | 5975 | if (err_val_ptr == irb->codegen->invalid_instruction) |
| 5942 | 5976 | return err_val_ptr; |
| 5943 | IrInstruction *err_val = ir_build_load_ptr(irb, scope, node->data.while_expr.condition, err_val_ptr); | |
| 5944 | IrInstruction *is_err = ir_build_test_err(irb, scope, node->data.while_expr.condition, err_val); | |
| 5977 | IrInstruction *is_err = ir_build_test_err_src(irb, scope, node->data.while_expr.condition, err_val_ptr); | |
| 5945 | 5978 | IrBasicBlock *after_cond_block = irb->current_basic_block; |
| 5946 | 5979 | IrInstruction *void_else_result = else_node ? nullptr : ir_mark_gen(ir_build_const_void(irb, scope, node)); |
| 5947 | 5980 | IrInstruction *cond_br_inst; |
| ... | ... | @@ -6722,7 +6755,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * |
| 6722 | 6755 | return err_val_ptr; |
| 6723 | 6756 | |
| 6724 | 6757 | IrInstruction *err_val = ir_build_load_ptr(irb, scope, node, err_val_ptr); |
| 6725 | IrInstruction *is_err = ir_build_test_err(irb, scope, node, err_val); | |
| 6758 | IrInstruction *is_err = ir_build_test_err_src(irb, scope, node, err_val_ptr); | |
| 6726 | 6759 | |
| 6727 | 6760 | IrBasicBlock *ok_block = ir_create_basic_block(irb, scope, "TryOk"); |
| 6728 | 6761 | IrBasicBlock *else_block = ir_create_basic_block(irb, scope, "TryElse"); |
| ... | ... | @@ -7330,8 +7363,7 @@ static IrInstruction *ir_gen_catch(IrBuilder *irb, Scope *parent_scope, AstNode |
| 7330 | 7363 | if (err_union_ptr == irb->codegen->invalid_instruction) |
| 7331 | 7364 | return irb->codegen->invalid_instruction; |
| 7332 | 7365 | |
| 7333 | IrInstruction *err_union_val = ir_build_load_ptr(irb, parent_scope, node, err_union_ptr); | |
| 7334 | IrInstruction *is_err = ir_build_test_err(irb, parent_scope, node, err_union_val); | |
| 7366 | IrInstruction *is_err = ir_build_test_err_src(irb, parent_scope, node, err_union_ptr); | |
| 7335 | 7367 | |
| 7336 | 7368 | IrInstruction *is_comptime; |
| 7337 | 7369 | if (ir_should_inline(irb->exec, parent_scope)) { |
| ... | ... | @@ -15010,7 +15042,9 @@ static IrInstruction *ir_resolve_result(IrAnalyze *ira, IrInstruction *suspend_s |
| 15010 | 15042 | return result_loc; |
| 15011 | 15043 | ir_assert(result_loc->value.type->id == ZigTypeIdPointer, suspend_source_instr); |
| 15012 | 15044 | ZigType *actual_elem_type = result_loc->value.type->data.pointer.child_type; |
| 15013 | if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional) { | |
| 15045 | if (actual_elem_type->id == ZigTypeIdOptional && value_type->id != ZigTypeIdOptional && | |
| 15046 | value_type->id != ZigTypeIdNull) | |
| 15047 | { | |
| 15014 | 15048 | return ir_analyze_unwrap_optional_payload(ira, suspend_source_instr, result_loc, false, true); |
| 15015 | 15049 | } else if (actual_elem_type->id == ZigTypeIdErrorUnion && value_type->id != ZigTypeIdErrorUnion) { |
| 15016 | 15050 | if (value_type->id == ZigTypeIdErrorSet) { |
| ... | ... | @@ -22190,15 +22224,34 @@ static IrInstruction *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstr |
| 22190 | 22224 | return result; |
| 22191 | 22225 | } |
| 22192 | 22226 | |
| 22193 | static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErr *instruction) { | |
| 22194 | IrInstruction *value = instruction->value->child; | |
| 22195 | if (type_is_invalid(value->value.type)) | |
| 22227 | static IrInstruction *ir_analyze_instruction_result_ptr(IrAnalyze *ira, IrInstructionResultPtr *instruction) { | |
| 22228 | IrInstruction *result = instruction->result->child; | |
| 22229 | if (type_is_invalid(result->value.type)) | |
| 22230 | return result; | |
| 22231 | ||
| 22232 | if (instruction->result_loc->written && instruction->result_loc->resolved_loc != nullptr && | |
| 22233 | !instr_is_comptime(result)) | |
| 22234 | { | |
| 22235 | IrInstruction *result_ptr = instruction->result_loc->resolved_loc; | |
| 22236 | // Convert the pointer to the result type. They should be the same, except this will resolve | |
| 22237 | // inferred error sets. | |
| 22238 | ZigType *new_ptr_type = get_pointer_to_type(ira->codegen, result->value.type, true); | |
| 22239 | return ir_analyze_ptr_cast(ira, &instruction->base, result_ptr, new_ptr_type, &instruction->base, false); | |
| 22240 | } | |
| 22241 | return ir_get_ref(ira, &instruction->base, result, true, false); | |
| 22242 | } | |
| 22243 | ||
| 22244 | static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErrSrc *instruction) { | |
| 22245 | IrInstruction *base_ptr = instruction->base_ptr->child; | |
| 22246 | if (type_is_invalid(base_ptr->value.type)) | |
| 22196 | 22247 | return ira->codegen->invalid_instruction; |
| 22197 | 22248 | |
| 22249 | IrInstruction *value = ir_get_deref(ira, &instruction->base, base_ptr, nullptr); | |
| 22198 | 22250 | ZigType *type_entry = value->value.type; |
| 22199 | if (type_is_invalid(type_entry)) { | |
| 22251 | if (type_is_invalid(type_entry)) | |
| 22200 | 22252 | return ira->codegen->invalid_instruction; |
| 22201 | } else if (type_entry->id == ZigTypeIdErrorUnion) { | |
| 22253 | ||
| 22254 | if (type_entry->id == ZigTypeIdErrorUnion) { | |
| 22202 | 22255 | if (instr_is_comptime(value)) { |
| 22203 | 22256 | ConstExprValue *err_union_val = ir_resolve_const(ira, value, UndefBad); |
| 22204 | 22257 | if (!err_union_val) |
| ... | ... | @@ -22221,10 +22274,7 @@ static IrInstruction *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruct |
| 22221 | 22274 | return ir_const_bool(ira, &instruction->base, false); |
| 22222 | 22275 | } |
| 22223 | 22276 | |
| 22224 | IrInstruction *result = ir_build_test_err(&ira->new_irb, | |
| 22225 | instruction->base.scope, instruction->base.source_node, value); | |
| 22226 | result->value.type = ira->codegen->builtin_types.entry_bool; | |
| 22227 | return result; | |
| 22277 | return ir_build_test_err_gen(ira, &instruction->base, value); | |
| 22228 | 22278 | } else if (type_entry->id == ZigTypeIdErrorSet) { |
| 22229 | 22279 | return ir_const_bool(ira, &instruction->base, true); |
| 22230 | 22280 | } else { |
| ... | ... | @@ -24343,6 +24393,7 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction |
| 24343 | 24393 | case IrInstructionIdAllocaGen: |
| 24344 | 24394 | case IrInstructionIdSliceGen: |
| 24345 | 24395 | case IrInstructionIdRefGen: |
| 24396 | case IrInstructionIdTestErrGen: | |
| 24346 | 24397 | zig_unreachable(); |
| 24347 | 24398 | |
| 24348 | 24399 | case IrInstructionIdReturn: |
| ... | ... | @@ -24497,8 +24548,8 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction |
| 24497 | 24548 | return ir_analyze_instruction_align_of(ira, (IrInstructionAlignOf *)instruction); |
| 24498 | 24549 | case IrInstructionIdOverflowOp: |
| 24499 | 24550 | return ir_analyze_instruction_overflow_op(ira, (IrInstructionOverflowOp *)instruction); |
| 24500 | case IrInstructionIdTestErr: | |
| 24501 | return ir_analyze_instruction_test_err(ira, (IrInstructionTestErr *)instruction); | |
| 24551 | case IrInstructionIdTestErrSrc: | |
| 24552 | return ir_analyze_instruction_test_err(ira, (IrInstructionTestErrSrc *)instruction); | |
| 24502 | 24553 | case IrInstructionIdUnwrapErrCode: |
| 24503 | 24554 | return ir_analyze_instruction_unwrap_err_code(ira, (IrInstructionUnwrapErrCode *)instruction); |
| 24504 | 24555 | case IrInstructionIdUnwrapErrPayload: |
| ... | ... | @@ -24543,6 +24594,8 @@ static IrInstruction *ir_analyze_instruction_base(IrAnalyze *ira, IrInstruction |
| 24543 | 24594 | return ir_analyze_instruction_implicit_cast(ira, (IrInstructionImplicitCast *)instruction); |
| 24544 | 24595 | case IrInstructionIdResolveResult: |
| 24545 | 24596 | return ir_analyze_instruction_resolve_result(ira, (IrInstructionResolveResult *)instruction); |
| 24597 | case IrInstructionIdResultPtr: | |
| 24598 | return ir_analyze_instruction_result_ptr(ira, (IrInstructionResultPtr *)instruction); | |
| 24546 | 24599 | case IrInstructionIdOpaqueType: |
| 24547 | 24600 | return ir_analyze_instruction_opaque_type(ira, (IrInstructionOpaqueType *)instruction); |
| 24548 | 24601 | case IrInstructionIdSetAlignStack: |
| ... | ... | @@ -24672,6 +24725,9 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ |
| 24672 | 24725 | continue; |
| 24673 | 24726 | } |
| 24674 | 24727 | |
| 24728 | if (ira->codegen->verbose_ir) { | |
| 24729 | fprintf(stderr, "analyze #%zu\n", old_instruction->debug_id); | |
| 24730 | } | |
| 24675 | 24731 | IrInstruction *new_instruction = ir_analyze_instruction_base(ira, old_instruction); |
| 24676 | 24732 | if (new_instruction != nullptr) { |
| 24677 | 24733 | ir_assert(new_instruction->value.type != nullptr || new_instruction->value.type != nullptr, old_instruction); |
| ... | ... | @@ -24808,7 +24864,8 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 24808 | 24864 | case IrInstructionIdReturnAddress: |
| 24809 | 24865 | case IrInstructionIdFrameAddress: |
| 24810 | 24866 | case IrInstructionIdHandle: |
| 24811 | case IrInstructionIdTestErr: | |
| 24867 | case IrInstructionIdTestErrSrc: | |
| 24868 | case IrInstructionIdTestErrGen: | |
| 24812 | 24869 | case IrInstructionIdFnProto: |
| 24813 | 24870 | case IrInstructionIdTestComptime: |
| 24814 | 24871 | case IrInstructionIdPtrCastSrc: |
| ... | ... | @@ -24860,6 +24917,7 @@ bool ir_has_side_effects(IrInstruction *instruction) { |
| 24860 | 24917 | case IrInstructionIdHasDecl: |
| 24861 | 24918 | case IrInstructionIdAllocaSrc: |
| 24862 | 24919 | case IrInstructionIdAllocaGen: |
| 24920 | case IrInstructionIdResultPtr: | |
| 24863 | 24921 | return false; |
| 24864 | 24922 | |
| 24865 | 24923 | case IrInstructionIdAsm: |
src/ir_print.cpp+25-8| ... | ... | @@ -961,9 +961,15 @@ static void ir_print_overflow_op(IrPrint *irp, IrInstructionOverflowOp *instruct |
| 961 | 961 | fprintf(irp->f, ")"); |
| 962 | 962 | } |
| 963 | 963 | |
| 964 | static void ir_print_test_err(IrPrint *irp, IrInstructionTestErr *instruction) { | |
| 964 | static void ir_print_test_err_src(IrPrint *irp, IrInstructionTestErrSrc *instruction) { | |
| 965 | 965 | fprintf(irp->f, "@testError("); |
| 966 | ir_print_other_instruction(irp, instruction->value); | |
| 966 | ir_print_other_instruction(irp, instruction->base_ptr); | |
| 967 | fprintf(irp->f, ")"); | |
| 968 | } | |
| 969 | ||
| 970 | static void ir_print_test_err_gen(IrPrint *irp, IrInstructionTestErrGen *instruction) { | |
| 971 | fprintf(irp->f, "@testError("); | |
| 972 | ir_print_other_instruction(irp, instruction->err_union); | |
| 967 | 973 | fprintf(irp->f, ")"); |
| 968 | 974 | } |
| 969 | 975 | |
| ... | ... | @@ -976,10 +982,7 @@ static void ir_print_unwrap_err_code(IrPrint *irp, IrInstructionUnwrapErrCode *i |
| 976 | 982 | static void ir_print_unwrap_err_payload(IrPrint *irp, IrInstructionUnwrapErrPayload *instruction) { |
| 977 | 983 | fprintf(irp->f, "ErrorUnionFieldPayload("); |
| 978 | 984 | ir_print_other_instruction(irp, instruction->value); |
| 979 | fprintf(irp->f, ")"); | |
| 980 | if (!instruction->safety_check_on) { | |
| 981 | fprintf(irp->f, " // no safety"); | |
| 982 | } | |
| 985 | fprintf(irp->f, ")safety=%d,init=%d",instruction->safety_check_on, instruction->initializing); | |
| 983 | 986 | } |
| 984 | 987 | |
| 985 | 988 | static void ir_print_optional_wrap(IrPrint *irp, IrInstructionOptionalWrap *instruction) { |
| ... | ... | @@ -1301,6 +1304,14 @@ static void ir_print_resolve_result(IrPrint *irp, IrInstructionResolveResult *in |
| 1301 | 1304 | fprintf(irp->f, ")"); |
| 1302 | 1305 | } |
| 1303 | 1306 | |
| 1307 | static void ir_print_result_ptr(IrPrint *irp, IrInstructionResultPtr *instruction) { | |
| 1308 | fprintf(irp->f, "ResultPtr("); | |
| 1309 | ir_print_result_loc(irp, instruction->result_loc); | |
| 1310 | fprintf(irp->f, ","); | |
| 1311 | ir_print_other_instruction(irp, instruction->result); | |
| 1312 | fprintf(irp->f, ")"); | |
| 1313 | } | |
| 1314 | ||
| 1304 | 1315 | static void ir_print_opaque_type(IrPrint *irp, IrInstructionOpaqueType *instruction) { |
| 1305 | 1316 | fprintf(irp->f, "@OpaqueType()"); |
| 1306 | 1317 | } |
| ... | ... | @@ -1837,8 +1848,11 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) { |
| 1837 | 1848 | case IrInstructionIdOverflowOp: |
| 1838 | 1849 | ir_print_overflow_op(irp, (IrInstructionOverflowOp *)instruction); |
| 1839 | 1850 | break; |
| 1840 | case IrInstructionIdTestErr: | |
| 1841 | ir_print_test_err(irp, (IrInstructionTestErr *)instruction); | |
| 1851 | case IrInstructionIdTestErrSrc: | |
| 1852 | ir_print_test_err_src(irp, (IrInstructionTestErrSrc *)instruction); | |
| 1853 | break; | |
| 1854 | case IrInstructionIdTestErrGen: | |
| 1855 | ir_print_test_err_gen(irp, (IrInstructionTestErrGen *)instruction); | |
| 1842 | 1856 | break; |
| 1843 | 1857 | case IrInstructionIdUnwrapErrCode: |
| 1844 | 1858 | ir_print_unwrap_err_code(irp, (IrInstructionUnwrapErrCode *)instruction); |
| ... | ... | @@ -1939,6 +1953,9 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) { |
| 1939 | 1953 | case IrInstructionIdResolveResult: |
| 1940 | 1954 | ir_print_resolve_result(irp, (IrInstructionResolveResult *)instruction); |
| 1941 | 1955 | break; |
| 1956 | case IrInstructionIdResultPtr: | |
| 1957 | ir_print_result_ptr(irp, (IrInstructionResultPtr *)instruction); | |
| 1958 | break; | |
| 1942 | 1959 | case IrInstructionIdOpaqueType: |
| 1943 | 1960 | ir_print_opaque_type(irp, (IrInstructionOpaqueType *)instruction); |
| 1944 | 1961 | break; |
std/os.zig+1-1| ... | ... | @@ -2487,7 +2487,7 @@ pub fn toPosixPath(file_path: []const u8) ![PATH_MAX]u8 { |
| 2487 | 2487 | /// if this happens the fix is to add the error code to the corresponding |
| 2488 | 2488 | /// switch expression, possibly introduce a new error in the error set, and |
| 2489 | 2489 | /// send a patch to Zig. |
| 2490 | pub const unexpected_error_tracing = false; | |
| 2490 | pub const unexpected_error_tracing = builtin.mode == .Debug; | |
| 2491 | 2491 | |
| 2492 | 2492 | pub const UnexpectedError = error{ |
| 2493 | 2493 | /// The Operating System returned an undocumented error code. |
std/special/panic.zig+19-4| ... | ... | @@ -7,8 +7,23 @@ const builtin = @import("builtin"); |
| 7 | 7 | const std = @import("std"); |
| 8 | 8 | |
| 9 | 9 | pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn { |
| 10 | const stderr = std.io.getStdErr() catch std.process.abort(); | |
| 11 | stderr.write("panic: ") catch std.process.abort(); | |
| 12 | stderr.write(msg) catch std.process.abort(); | |
| 13 | std.process.abort(); | |
| 10 | @setCold(true); | |
| 11 | switch (builtin.os) { | |
| 12 | .freestanding => { | |
| 13 | while (true) {} | |
| 14 | }, | |
| 15 | .wasi => { | |
| 16 | std.debug.warn("{}", msg); | |
| 17 | _ = std.os.wasi.proc_raise(std.os.wasi.SIGABRT); | |
| 18 | unreachable; | |
| 19 | }, | |
| 20 | .uefi => { | |
| 21 | // TODO look into using the debug info and logging helpful messages | |
| 22 | std.os.abort(); | |
| 23 | }, | |
| 24 | else => { | |
| 25 | const first_trace_addr = @returnAddress(); | |
| 26 | std.debug.panicExtra(error_return_trace, first_trace_addr, "{}", msg); | |
| 27 | }, | |
| 28 | } | |
| 14 | 29 | } |
std/special/test_runner.zig+8-14| ... | ... | @@ -2,34 +2,28 @@ const std = @import("std"); |
| 2 | 2 | const io = std.io; |
| 3 | 3 | const builtin = @import("builtin"); |
| 4 | 4 | const test_fn_list = builtin.test_functions; |
| 5 | const warn = std.debug.warn; | |
| 5 | 6 | |
| 6 | pub fn main() void { | |
| 7 | const stderr = io.getStdErr() catch std.process.abort(); | |
| 8 | ||
| 7 | pub fn main() !void { | |
| 9 | 8 | var ok_count: usize = 0; |
| 10 | 9 | var skip_count: usize = 0; |
| 11 | 10 | for (test_fn_list) |test_fn, i| { |
| 12 | stderr.write("test ") catch std.process.abort(); | |
| 13 | stderr.write(test_fn.name) catch std.process.abort(); | |
| 11 | warn("{}/{} {}...", i + 1, test_fn_list.len, test_fn.name); | |
| 14 | 12 | |
| 15 | 13 | if (test_fn.func()) |_| { |
| 16 | 14 | ok_count += 1; |
| 17 | stderr.write("...OK\n") catch std.process.abort(); | |
| 15 | warn("OK\n"); | |
| 18 | 16 | } else |err| switch (err) { |
| 19 | 17 | error.SkipZigTest => { |
| 20 | 18 | skip_count += 1; |
| 21 | stderr.write("...SKIP\n") catch std.process.abort(); | |
| 22 | }, | |
| 23 | else => { | |
| 24 | stderr.write("error: ") catch std.process.abort(); | |
| 25 | stderr.write(@errorName(err)) catch std.process.abort(); | |
| 26 | std.process.abort(); | |
| 19 | warn("SKIP\n"); | |
| 27 | 20 | }, |
| 21 | else => return err, | |
| 28 | 22 | } |
| 29 | 23 | } |
| 30 | 24 | if (ok_count == test_fn_list.len) { |
| 31 | stderr.write("All tests passed.\n") catch std.process.abort(); | |
| 25 | warn("All tests passed.\n"); | |
| 32 | 26 | } else { |
| 33 | stderr.write("Some tests skipped.\n") catch std.process.abort(); | |
| 27 | warn("{} passed; {} skipped.\n", ok_count, skip_count); | |
| 34 | 28 | } |
| 35 | 29 | } |
test/stage1/behavior.zig+9-9| ... | ... | @@ -40,46 +40,46 @@ comptime { |
| 40 | 40 | //_ = @import("behavior/bugs/920.zig"); |
| 41 | 41 | _ = @import("behavior/byval_arg_var.zig"); |
| 42 | 42 | //_ = @import("behavior/cancel.zig"); |
| 43 | _ = @import("behavior/cast.zig"); // TODO | |
| 43 | _ = @import("behavior/cast.zig"); | |
| 44 | 44 | _ = @import("behavior/const_slice_child.zig"); |
| 45 | 45 | //_ = @import("behavior/coroutine_await_struct.zig"); |
| 46 | 46 | //_ = @import("behavior/coroutines.zig"); |
| 47 | 47 | _ = @import("behavior/defer.zig"); |
| 48 | 48 | _ = @import("behavior/enum.zig"); |
| 49 | 49 | _ = @import("behavior/enum_with_members.zig"); |
| 50 | //_ = @import("behavior/error.zig"); | |
| 50 | _ = @import("behavior/error.zig"); // TODO | |
| 51 | 51 | _ = @import("behavior/eval.zig"); // TODO |
| 52 | 52 | _ = @import("behavior/field_parent_ptr.zig"); |
| 53 | 53 | _ = @import("behavior/fn.zig"); |
| 54 | 54 | _ = @import("behavior/fn_in_struct_in_comptime.zig"); |
| 55 | 55 | _ = @import("behavior/for.zig"); |
| 56 | _ = @import("behavior/generics.zig"); // TODO | |
| 56 | _ = @import("behavior/generics.zig"); | |
| 57 | 57 | _ = @import("behavior/hasdecl.zig"); |
| 58 | 58 | _ = @import("behavior/if.zig"); |
| 59 | //_ = @import("behavior/import.zig"); | |
| 59 | _ = @import("behavior/import.zig"); | |
| 60 | 60 | _ = @import("behavior/incomplete_struct_param_tld.zig"); |
| 61 | 61 | _ = @import("behavior/inttoptr.zig"); |
| 62 | 62 | _ = @import("behavior/ir_block_deps.zig"); |
| 63 | //_ = @import("behavior/math.zig"); | |
| 63 | _ = @import("behavior/math.zig"); | |
| 64 | 64 | _ = @import("behavior/merge_error_sets.zig"); |
| 65 | 65 | _ = @import("behavior/misc.zig"); // TODO |
| 66 | 66 | _ = @import("behavior/namespace_depends_on_compile_var.zig"); |
| 67 | 67 | _ = @import("behavior/new_stack_call.zig"); |
| 68 | 68 | _ = @import("behavior/null.zig"); |
| 69 | 69 | _ = @import("behavior/optional.zig"); // TODO |
| 70 | //_ = @import("behavior/pointers.zig"); | |
| 70 | _ = @import("behavior/pointers.zig"); | |
| 71 | 71 | _ = @import("behavior/popcount.zig"); |
| 72 | 72 | _ = @import("behavior/ptrcast.zig"); // TODO |
| 73 | 73 | _ = @import("behavior/pub_enum.zig"); |
| 74 | 74 | _ = @import("behavior/ref_var_in_if_after_if_2nd_switch_prong.zig"); |
| 75 | 75 | _ = @import("behavior/reflection.zig"); |
| 76 | 76 | _ = @import("behavior/sizeof_and_typeof.zig"); |
| 77 | //_ = @import("behavior/slice.zig"); | |
| 77 | _ = @import("behavior/slice.zig"); | |
| 78 | 78 | _ = @import("behavior/slicetobytes.zig"); |
| 79 | 79 | //_ = @import("behavior/struct.zig"); |
| 80 | 80 | _ = @import("behavior/struct_contains_null_ptr_itself.zig"); |
| 81 | 81 | _ = @import("behavior/struct_contains_slice_of_itself.zig"); |
| 82 | //_ = @import("behavior/switch.zig"); | |
| 82 | _ = @import("behavior/switch.zig"); | |
| 83 | 83 | //_ = @import("behavior/switch_prong_err_enum.zig"); |
| 84 | 84 | _ = @import("behavior/switch_prong_implicit_cast.zig"); |
| 85 | 85 | _ = @import("behavior/syntax.zig"); |
| ... | ... | @@ -87,7 +87,7 @@ comptime { |
| 87 | 87 | _ = @import("behavior/truncate.zig"); |
| 88 | 88 | _ = @import("behavior/try.zig"); |
| 89 | 89 | _ = @import("behavior/type_info.zig"); |
| 90 | //_ = @import("behavior/typename.zig"); | |
| 90 | _ = @import("behavior/typename.zig"); | |
| 91 | 91 | _ = @import("behavior/undefined.zig"); |
| 92 | 92 | _ = @import("behavior/underscore.zig"); |
| 93 | 93 | _ = @import("behavior/union.zig"); |
test/stage1/behavior/cast.zig+8-8| ... | ... | @@ -124,14 +124,14 @@ fn returnNullLitFromOptionalTypeErrorRef() anyerror!?*A { |
| 124 | 124 | return null; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | //test "peer type resolution: ?T and T" { | |
| 128 | // expect(peerTypeTAndOptionalT(true, false).? == 0); | |
| 129 | // expect(peerTypeTAndOptionalT(false, false).? == 3); | |
| 130 | // comptime { | |
| 131 | // expect(peerTypeTAndOptionalT(true, false).? == 0); | |
| 132 | // expect(peerTypeTAndOptionalT(false, false).? == 3); | |
| 133 | // } | |
| 134 | //} | |
| 127 | test "peer type resolution: ?T and T" { | |
| 128 | expect(peerTypeTAndOptionalT(true, false).? == 0); | |
| 129 | expect(peerTypeTAndOptionalT(false, false).? == 3); | |
| 130 | comptime { | |
| 131 | expect(peerTypeTAndOptionalT(true, false).? == 0); | |
| 132 | expect(peerTypeTAndOptionalT(false, false).? == 3); | |
| 133 | } | |
| 134 | } | |
| 135 | 135 | fn peerTypeTAndOptionalT(c: bool, b: bool) ?usize { |
| 136 | 136 | if (c) { |
| 137 | 137 | return if (b) null else usize(0); |
test/stage1/behavior/error.zig+42-42| ... | ... | @@ -249,48 +249,48 @@ fn intLiteral(str: []const u8) !?i64 { |
| 249 | 249 | return error.T; |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | test "nested error union function call in optional unwrap" { | |
| 253 | const S = struct { | |
| 254 | const Foo = struct { | |
| 255 | a: i32, | |
| 256 | }; | |
| 257 | ||
| 258 | fn errorable() !i32 { | |
| 259 | var x: Foo = (try getFoo()) orelse return error.Other; | |
| 260 | return x.a; | |
| 261 | } | |
| 262 | ||
| 263 | fn errorable2() !i32 { | |
| 264 | var x: Foo = (try getFoo2()) orelse return error.Other; | |
| 265 | return x.a; | |
| 266 | } | |
| 267 | ||
| 268 | fn errorable3() !i32 { | |
| 269 | var x: Foo = (try getFoo3()) orelse return error.Other; | |
| 270 | return x.a; | |
| 271 | } | |
| 272 | ||
| 273 | fn getFoo() anyerror!?Foo { | |
| 274 | return Foo{ .a = 1234 }; | |
| 275 | } | |
| 276 | ||
| 277 | fn getFoo2() anyerror!?Foo { | |
| 278 | return error.Failure; | |
| 279 | } | |
| 280 | ||
| 281 | fn getFoo3() anyerror!?Foo { | |
| 282 | return null; | |
| 283 | } | |
| 284 | }; | |
| 285 | expect((try S.errorable()) == 1234); | |
| 286 | expectError(error.Failure, S.errorable2()); | |
| 287 | expectError(error.Other, S.errorable3()); | |
| 288 | comptime { | |
| 289 | expect((try S.errorable()) == 1234); | |
| 290 | expectError(error.Failure, S.errorable2()); | |
| 291 | expectError(error.Other, S.errorable3()); | |
| 292 | } | |
| 293 | } | |
| 252 | //test "nested error union function call in optional unwrap" { | |
| 253 | // const S = struct { | |
| 254 | // const Foo = struct { | |
| 255 | // a: i32, | |
| 256 | // }; | |
| 257 | // | |
| 258 | // fn errorable() !i32 { | |
| 259 | // var x: Foo = (try getFoo()) orelse return error.Other; | |
| 260 | // return x.a; | |
| 261 | // } | |
| 262 | // | |
| 263 | // fn errorable2() !i32 { | |
| 264 | // var x: Foo = (try getFoo2()) orelse return error.Other; | |
| 265 | // return x.a; | |
| 266 | // } | |
| 267 | // | |
| 268 | // fn errorable3() !i32 { | |
| 269 | // var x: Foo = (try getFoo3()) orelse return error.Other; | |
| 270 | // return x.a; | |
| 271 | // } | |
| 272 | // | |
| 273 | // fn getFoo() anyerror!?Foo { | |
| 274 | // return Foo{ .a = 1234 }; | |
| 275 | // } | |
| 276 | // | |
| 277 | // fn getFoo2() anyerror!?Foo { | |
| 278 | // return error.Failure; | |
| 279 | // } | |
| 280 | // | |
| 281 | // fn getFoo3() anyerror!?Foo { | |
| 282 | // return null; | |
| 283 | // } | |
| 284 | // }; | |
| 285 | // expect((try S.errorable()) == 1234); | |
| 286 | // expectError(error.Failure, S.errorable2()); | |
| 287 | // expectError(error.Other, S.errorable3()); | |
| 288 | // comptime { | |
| 289 | // expect((try S.errorable()) == 1234); | |
| 290 | // expectError(error.Failure, S.errorable2()); | |
| 291 | // expectError(error.Other, S.errorable3()); | |
| 292 | // } | |
| 293 | //} | |
| 294 | 294 | |
| 295 | 295 | test "widen cast integer payload of error union function call" { |
| 296 | 296 | const S = struct { |
test/stage1/behavior/generics.zig+13-13| ... | ... | @@ -80,19 +80,19 @@ test "function with return type type" { |
| 80 | 80 | expect(list2.prealloc_items.len == 8); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | //test "generic struct" { | |
| 84 | // var a1 = GenNode(i32){ | |
| 85 | // .value = 13, | |
| 86 | // .next = null, | |
| 87 | // }; | |
| 88 | // var b1 = GenNode(bool){ | |
| 89 | // .value = true, | |
| 90 | // .next = null, | |
| 91 | // }; | |
| 92 | // expect(a1.value == 13); | |
| 93 | // expect(a1.value == a1.getVal()); | |
| 94 | // expect(b1.getVal()); | |
| 95 | //} | |
| 83 | test "generic struct" { | |
| 84 | var a1 = GenNode(i32){ | |
| 85 | .value = 13, | |
| 86 | .next = null, | |
| 87 | }; | |
| 88 | var b1 = GenNode(bool){ | |
| 89 | .value = true, | |
| 90 | .next = null, | |
| 91 | }; | |
| 92 | expect(a1.value == 13); | |
| 93 | expect(a1.value == a1.getVal()); | |
| 94 | expect(b1.getVal()); | |
| 95 | } | |
| 96 | 96 | fn GenNode(comptime T: type) type { |
| 97 | 97 | return struct { |
| 98 | 98 | value: T, |
test/stage1/behavior/optional.zig+1-2| ... | ... | @@ -76,6 +76,5 @@ test "unwrap function call with optional pointer return value" { |
| 76 | 76 | } |
| 77 | 77 | }; |
| 78 | 78 | S.entry(); |
| 79 | // TODO https://github.com/ziglang/zig/issues/1901 | |
| 80 | //comptime S.entry(); | |
| 79 | comptime S.entry(); | |
| 81 | 80 | } |
test/stage1/behavior/while.zig+22-22| ... | ... | @@ -82,28 +82,28 @@ test "while with else" { |
| 82 | 82 | expect(got_else == 1); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | //test "while with optional as condition" { | |
| 86 | // numbers_left = 10; | |
| 87 | // var sum: i32 = 0; | |
| 88 | // while (getNumberOrNull()) |value| { | |
| 89 | // sum += value; | |
| 90 | // } | |
| 91 | // expect(sum == 45); | |
| 92 | //} | |
| 93 | // | |
| 94 | //test "while with optional as condition with else" { | |
| 95 | // numbers_left = 10; | |
| 96 | // var sum: i32 = 0; | |
| 97 | // var got_else: i32 = 0; | |
| 98 | // while (getNumberOrNull()) |value| { | |
| 99 | // sum += value; | |
| 100 | // expect(got_else == 0); | |
| 101 | // } else { | |
| 102 | // got_else += 1; | |
| 103 | // } | |
| 104 | // expect(sum == 45); | |
| 105 | // expect(got_else == 1); | |
| 106 | //} | |
| 85 | test "while with optional as condition" { | |
| 86 | numbers_left = 10; | |
| 87 | var sum: i32 = 0; | |
| 88 | while (getNumberOrNull()) |value| { | |
| 89 | sum += value; | |
| 90 | } | |
| 91 | expect(sum == 45); | |
| 92 | } | |
| 93 | ||
| 94 | test "while with optional as condition with else" { | |
| 95 | numbers_left = 10; | |
| 96 | var sum: i32 = 0; | |
| 97 | var got_else: i32 = 0; | |
| 98 | while (getNumberOrNull()) |value| { | |
| 99 | sum += value; | |
| 100 | expect(got_else == 0); | |
| 101 | } else { | |
| 102 | got_else += 1; | |
| 103 | } | |
| 104 | expect(sum == 45); | |
| 105 | expect(got_else == 1); | |
| 106 | } | |
| 107 | 107 | |
| 108 | 108 | test "while with error union condition" { |
| 109 | 109 | numbers_left = 10; |