| author | |
| committer | |
| log | 39d5f44863aafa77163b2a7e32f2553a589dbb2c |
| tree | 43a0d9684bde2bb94bca491ab3718408dc05c7ed |
| parent | cfb2c676925d77887e46631dcafa783e6c65e61d |
18 files changed, 134 insertions(+), 92 deletions(-)
TODO+11-2| ... | ... | @@ -1,6 +1,15 @@ |
| 1 | sed -i 's/\(\bfn .*) \)%\(.*{\)$/\1!\2/g' $(find .. -name "*.zig") | |
| 1 | sed -i 's/\(\bfn .*) \)%\(.*{\)$/\1!\2/g' $(find . -name "*.zig") | |
| 2 | 2 | |
| 3 | comptime assert(error{} ! i32 == i32); | |
| 3 | the literal translation of `%T` to this new code is `error!T`. | |
| 4 | however this would not take advantage of error sets. It's | |
| 5 | recommended to generally have all your functions which return possible | |
| 6 | errors to use error set inference, like this: | |
| 7 | ||
| 8 | fn foo() !void { | |
| 9 | ||
| 10 | } | |
| 11 | ||
| 12 | then you can return void, or any error, and the error set is inferred. | |
| 4 | 13 | |
| 5 | 14 | // TODO this is an explicit cast and should actually coerce the type |
| 6 | 15 | erorr set casting |
src/analyze.cpp+2-2| ... | ... | @@ -3367,7 +3367,7 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *so |
| 3367 | 3367 | } |
| 3368 | 3368 | |
| 3369 | 3369 | ConstCastOnly types_match_const_cast_only(CodeGen *g, TypeTableEntry *expected_type, TypeTableEntry *actual_type) { |
| 3370 | ConstCastOnly result = {0}; | |
| 3370 | ConstCastOnly result = {}; | |
| 3371 | 3371 | result.id = ConstCastResultIdOk; |
| 3372 | 3372 | |
| 3373 | 3373 | if (expected_type == actual_type) |
| ... | ... | @@ -3465,7 +3465,7 @@ ConstCastOnly types_match_const_cast_only(CodeGen *g, TypeTableEntry *expected_t |
| 3465 | 3465 | if (result.id == ConstCastResultIdOk) { |
| 3466 | 3466 | result.id = ConstCastResultIdErrSet; |
| 3467 | 3467 | } |
| 3468 | result.data.error_set.errors.append(contained_error_entry); | |
| 3468 | result.data.error_set.missing_errors.append(contained_error_entry); | |
| 3469 | 3469 | } |
| 3470 | 3470 | } |
| 3471 | 3471 | free(errors); |
src/analyze.hpp+3-1| ... | ... | @@ -214,6 +214,8 @@ struct ConstCastErrSetMismatch { |
| 214 | 214 | ZigList<ErrorTableEntry *> missing_errors; |
| 215 | 215 | }; |
| 216 | 216 | |
| 217 | struct ConstCastOnly; | |
| 218 | ||
| 217 | 219 | struct ConstCastArg { |
| 218 | 220 | size_t arg_index; |
| 219 | 221 | ConstCastOnly *child; |
| ... | ... | @@ -238,6 +240,6 @@ struct ConstCastOnly { |
| 238 | 240 | } data; |
| 239 | 241 | }; |
| 240 | 242 | |
| 241 | bool types_match_const_cast_only(CodeGen *g, TypeTableEntry *expected_type, TypeTableEntry *actual_type); | |
| 243 | ConstCastOnly types_match_const_cast_only(CodeGen *g, TypeTableEntry *expected_type, TypeTableEntry *actual_type); | |
| 242 | 244 | |
| 243 | 245 | #endif |
src/ir.cpp+54-29| ... | ... | @@ -6424,12 +6424,23 @@ enum ImplicitCastMatchResult { |
| 6424 | 6424 | static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, TypeTableEntry *expected_type, |
| 6425 | 6425 | TypeTableEntry *actual_type, IrInstruction *value) |
| 6426 | 6426 | { |
| 6427 | if (types_match_const_cast_only(ira->codegen, expected_type, actual_type)) { | |
| 6427 | ConstCastOnly const_cast_result = types_match_const_cast_only(ira->codegen, expected_type, actual_type); | |
| 6428 | if (const_cast_result.id == ConstCastResultIdOk) { | |
| 6428 | 6429 | return ImplicitCastMatchResultYes; |
| 6429 | 6430 | } |
| 6430 | 6431 | |
| 6431 | 6432 | // if we got here with error sets, make an error showing the incompatibilities |
| 6432 | if (expected_typek | |
| 6433 | if (const_cast_result.id == ConstCastResultIdErrSet) { | |
| 6434 | ErrorMsg *msg = ir_add_error(ira, value, | |
| 6435 | buf_sprintf("expected '%s', found '%s'", buf_ptr(&expected_type->name), buf_ptr(&actual_type->name))); | |
| 6436 | for (size_t i = 0; i < const_cast_result.data.error_set.missing_errors.length; i += 1) { | |
| 6437 | ErrorTableEntry *error_entry = const_cast_result.data.error_set.missing_errors.at(i); | |
| 6438 | add_error_note(ira->codegen, msg, error_entry->decl_node, | |
| 6439 | buf_sprintf("'error.%s' not a member of destination error set", buf_ptr(&error_entry->name))); | |
| 6440 | } | |
| 6441 | ||
| 6442 | return ImplicitCastMatchResultReportedError; | |
| 6443 | } | |
| 6433 | 6444 | |
| 6434 | 6445 | // implicit conversion from anything to var |
| 6435 | 6446 | if (expected_type->id == TypeTableEntryIdVar) { |
| ... | ... | @@ -6508,7 +6519,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6508 | 6519 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 6509 | 6520 | |
| 6510 | 6521 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 6511 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) | |
| 6522 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk) | |
| 6512 | 6523 | { |
| 6513 | 6524 | return ImplicitCastMatchResultYes; |
| 6514 | 6525 | } |
| ... | ... | @@ -6527,7 +6538,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6527 | 6538 | TypeTableEntry *array_type = actual_type->data.pointer.child_type; |
| 6528 | 6539 | |
| 6529 | 6540 | if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) && |
| 6530 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, array_type->data.array.child_type)) | |
| 6541 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, array_type->data.array.child_type).id == ConstCastResultIdOk) | |
| 6531 | 6542 | { |
| 6532 | 6543 | return ImplicitCastMatchResultYes; |
| 6533 | 6544 | } |
| ... | ... | @@ -6543,7 +6554,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6543 | 6554 | expected_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry; |
| 6544 | 6555 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 6545 | 6556 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 6546 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) | |
| 6557 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk) | |
| 6547 | 6558 | { |
| 6548 | 6559 | return ImplicitCastMatchResultYes; |
| 6549 | 6560 | } |
| ... | ... | @@ -6558,7 +6569,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6558 | 6569 | expected_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry; |
| 6559 | 6570 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 6560 | 6571 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 6561 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) | |
| 6572 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk) | |
| 6562 | 6573 | { |
| 6563 | 6574 | return ImplicitCastMatchResultYes; |
| 6564 | 6575 | } |
| ... | ... | @@ -6638,7 +6649,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, |
| 6638 | 6649 | // implicitly take a const pointer to something |
| 6639 | 6650 | if (!type_requires_comptime(actual_type)) { |
| 6640 | 6651 | TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true); |
| 6641 | if (types_match_const_cast_only(ira->codegen, expected_type, const_ptr_actual)) { | |
| 6652 | if (types_match_const_cast_only(ira->codegen, expected_type, const_ptr_actual).id == ConstCastResultIdOk) { | |
| 6642 | 6653 | return ImplicitCastMatchResultYes; |
| 6643 | 6654 | } |
| 6644 | 6655 | } |
| ... | ... | @@ -6742,20 +6753,31 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6742 | 6753 | if (cur_is_superset) { |
| 6743 | 6754 | err_set_type = cur_type; |
| 6744 | 6755 | prev_inst = cur_inst; |
| 6756 | assert(errors != nullptr); | |
| 6745 | 6757 | continue; |
| 6746 | 6758 | } |
| 6747 | 6759 | |
| 6748 | 6760 | // neither of them are supersets. so we invent a new error set type that is a union of both of them |
| 6749 | 6761 | err_set_type = get_error_set_union(ira->codegen, errors, cur_type, err_set_type); |
| 6762 | assert(errors != nullptr); | |
| 6750 | 6763 | continue; |
| 6751 | 6764 | } else if (cur_type->id == TypeTableEntryIdErrorUnion) { |
| 6765 | if (err_set_type == ira->codegen->builtin_types.entry_global_error_set) { | |
| 6766 | prev_inst = cur_inst; | |
| 6767 | continue; | |
| 6768 | } | |
| 6769 | TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type; | |
| 6770 | if (cur_err_set_type == ira->codegen->builtin_types.entry_global_error_set) { | |
| 6771 | err_set_type = ira->codegen->builtin_types.entry_global_error_set; | |
| 6772 | prev_inst = cur_inst; | |
| 6773 | continue; | |
| 6774 | } | |
| 6752 | 6775 | // test if err_set_type is a subset of cur_type's error set |
| 6753 | 6776 | // unset everything in errors |
| 6754 | 6777 | for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) { |
| 6755 | 6778 | ErrorTableEntry *error_entry = err_set_type->data.error_set.errors[i]; |
| 6756 | 6779 | errors[error_entry->value] = nullptr; |
| 6757 | 6780 | } |
| 6758 | TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type; | |
| 6759 | 6781 | for (uint32_t i = 0; i < cur_err_set_type->data.error_set.err_count; i += 1) { |
| 6760 | 6782 | ErrorTableEntry *error_entry = cur_err_set_type->data.error_set.errors[i]; |
| 6761 | 6783 | errors[error_entry->value] = error_entry; |
| ... | ... | @@ -6772,12 +6794,14 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6772 | 6794 | if (cur_is_superset) { |
| 6773 | 6795 | err_set_type = cur_err_set_type; |
| 6774 | 6796 | prev_inst = cur_inst; |
| 6797 | assert(errors != nullptr); | |
| 6775 | 6798 | continue; |
| 6776 | 6799 | } |
| 6777 | 6800 | |
| 6778 | 6801 | // not a subset. invent new error set type, union of both of them |
| 6779 | 6802 | err_set_type = get_error_set_union(ira->codegen, errors, cur_err_set_type, err_set_type); |
| 6780 | 6803 | prev_inst = cur_inst; |
| 6804 | assert(errors != nullptr); | |
| 6781 | 6805 | continue; |
| 6782 | 6806 | } else { |
| 6783 | 6807 | prev_inst = cur_inst; |
| ... | ... | @@ -6820,15 +6844,16 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6820 | 6844 | } |
| 6821 | 6845 | // not a subset. invent new error set type, union of both of them |
| 6822 | 6846 | err_set_type = get_error_set_union(ira->codegen, errors, err_set_type, cur_type); |
| 6847 | assert(errors != nullptr); | |
| 6823 | 6848 | continue; |
| 6824 | 6849 | } |
| 6825 | 6850 | } |
| 6826 | 6851 | |
| 6827 | if (types_match_const_cast_only(ira->codegen, prev_type, cur_type)) { | |
| 6852 | if (types_match_const_cast_only(ira->codegen, prev_type, cur_type).id == ConstCastResultIdOk) { | |
| 6828 | 6853 | continue; |
| 6829 | 6854 | } |
| 6830 | 6855 | |
| 6831 | if (types_match_const_cast_only(ira->codegen, cur_type, prev_type)) { | |
| 6856 | if (types_match_const_cast_only(ira->codegen, cur_type, prev_type).id == ConstCastResultIdOk) { | |
| 6832 | 6857 | prev_inst = cur_inst; |
| 6833 | 6858 | continue; |
| 6834 | 6859 | } |
| ... | ... | @@ -6851,26 +6876,26 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6851 | 6876 | } |
| 6852 | 6877 | |
| 6853 | 6878 | if (prev_type->id == TypeTableEntryIdErrorUnion && |
| 6854 | types_match_const_cast_only(ira->codegen, prev_type->data.error_union.payload_type, cur_type)) | |
| 6879 | types_match_const_cast_only(ira->codegen, prev_type->data.error_union.payload_type, cur_type).id == ConstCastResultIdOk) | |
| 6855 | 6880 | { |
| 6856 | 6881 | continue; |
| 6857 | 6882 | } |
| 6858 | 6883 | |
| 6859 | 6884 | if (cur_type->id == TypeTableEntryIdErrorUnion && |
| 6860 | types_match_const_cast_only(ira->codegen, cur_type->data.error_union.payload_type, prev_type)) | |
| 6885 | types_match_const_cast_only(ira->codegen, cur_type->data.error_union.payload_type, prev_type).id == ConstCastResultIdOk) | |
| 6861 | 6886 | { |
| 6862 | 6887 | prev_inst = cur_inst; |
| 6863 | 6888 | continue; |
| 6864 | 6889 | } |
| 6865 | 6890 | |
| 6866 | 6891 | if (prev_type->id == TypeTableEntryIdMaybe && |
| 6867 | types_match_const_cast_only(ira->codegen, prev_type->data.maybe.child_type, cur_type)) | |
| 6892 | types_match_const_cast_only(ira->codegen, prev_type->data.maybe.child_type, cur_type).id == ConstCastResultIdOk) | |
| 6868 | 6893 | { |
| 6869 | 6894 | continue; |
| 6870 | 6895 | } |
| 6871 | 6896 | |
| 6872 | 6897 | if (cur_type->id == TypeTableEntryIdMaybe && |
| 6873 | types_match_const_cast_only(ira->codegen, cur_type->data.maybe.child_type, prev_type)) | |
| 6898 | types_match_const_cast_only(ira->codegen, cur_type->data.maybe.child_type, prev_type).id == ConstCastResultIdOk) | |
| 6874 | 6899 | { |
| 6875 | 6900 | prev_inst = cur_inst; |
| 6876 | 6901 | continue; |
| ... | ... | @@ -6908,7 +6933,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6908 | 6933 | |
| 6909 | 6934 | if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray && |
| 6910 | 6935 | cur_type->data.array.len != prev_type->data.array.len && |
| 6911 | types_match_const_cast_only(ira->codegen, cur_type->data.array.child_type, prev_type->data.array.child_type)) | |
| 6936 | types_match_const_cast_only(ira->codegen, cur_type->data.array.child_type, prev_type->data.array.child_type).id == ConstCastResultIdOk) | |
| 6912 | 6937 | { |
| 6913 | 6938 | convert_to_const_slice = true; |
| 6914 | 6939 | prev_inst = cur_inst; |
| ... | ... | @@ -6917,7 +6942,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6917 | 6942 | |
| 6918 | 6943 | if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray && |
| 6919 | 6944 | cur_type->data.array.len != prev_type->data.array.len && |
| 6920 | types_match_const_cast_only(ira->codegen, prev_type->data.array.child_type, cur_type->data.array.child_type)) | |
| 6945 | types_match_const_cast_only(ira->codegen, prev_type->data.array.child_type, cur_type->data.array.child_type).id == ConstCastResultIdOk) | |
| 6921 | 6946 | { |
| 6922 | 6947 | convert_to_const_slice = true; |
| 6923 | 6948 | continue; |
| ... | ... | @@ -6927,7 +6952,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6927 | 6952 | (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || |
| 6928 | 6953 | cur_type->data.array.len == 0) && |
| 6929 | 6954 | types_match_const_cast_only(ira->codegen, prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type, |
| 6930 | cur_type->data.array.child_type)) | |
| 6955 | cur_type->data.array.child_type).id == ConstCastResultIdOk) | |
| 6931 | 6956 | { |
| 6932 | 6957 | convert_to_const_slice = false; |
| 6933 | 6958 | continue; |
| ... | ... | @@ -6937,7 +6962,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod |
| 6937 | 6962 | (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || |
| 6938 | 6963 | prev_type->data.array.len == 0) && |
| 6939 | 6964 | types_match_const_cast_only(ira->codegen, cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type, |
| 6940 | prev_type->data.array.child_type)) | |
| 6965 | prev_type->data.array.child_type).id == ConstCastResultIdOk) | |
| 6941 | 6966 | { |
| 6942 | 6967 | prev_inst = cur_inst; |
| 6943 | 6968 | convert_to_const_slice = false; |
| ... | ... | @@ -8059,7 +8084,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8059 | 8084 | return value; |
| 8060 | 8085 | |
| 8061 | 8086 | // explicit match or non-const to const |
| 8062 | if (types_match_const_cast_only(ira->codegen, wanted_type, actual_type)) { | |
| 8087 | if (types_match_const_cast_only(ira->codegen, wanted_type, actual_type).id == ConstCastResultIdOk) { | |
| 8063 | 8088 | return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop, false); |
| 8064 | 8089 | } |
| 8065 | 8090 | |
| ... | ... | @@ -8105,7 +8130,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8105 | 8130 | TypeTableEntry *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8106 | 8131 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 8107 | 8132 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 8108 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) | |
| 8133 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk) | |
| 8109 | 8134 | { |
| 8110 | 8135 | return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type); |
| 8111 | 8136 | } |
| ... | ... | @@ -8123,7 +8148,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8123 | 8148 | TypeTableEntry *array_type = actual_type->data.pointer.child_type; |
| 8124 | 8149 | |
| 8125 | 8150 | if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) && |
| 8126 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, array_type->data.array.child_type)) | |
| 8151 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, array_type->data.array.child_type).id == ConstCastResultIdOk) | |
| 8127 | 8152 | { |
| 8128 | 8153 | return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type); |
| 8129 | 8154 | } |
| ... | ... | @@ -8139,7 +8164,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8139 | 8164 | wanted_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8140 | 8165 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 8141 | 8166 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 8142 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) | |
| 8167 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk) | |
| 8143 | 8168 | { |
| 8144 | 8169 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value); |
| 8145 | 8170 | if (type_is_invalid(cast1->value.type)) |
| ... | ... | @@ -8162,7 +8187,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8162 | 8187 | wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8163 | 8188 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 8164 | 8189 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 8165 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) | |
| 8190 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk) | |
| 8166 | 8191 | { |
| 8167 | 8192 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value); |
| 8168 | 8193 | if (type_is_invalid(cast1->value.type)) |
| ... | ... | @@ -8224,7 +8249,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8224 | 8249 | |
| 8225 | 8250 | // explicit cast from child type of maybe type to maybe type |
| 8226 | 8251 | if (wanted_type->id == TypeTableEntryIdMaybe) { |
| 8227 | if (types_match_const_cast_only(ira->codegen, wanted_type->data.maybe.child_type, actual_type)) { | |
| 8252 | if (types_match_const_cast_only(ira->codegen, wanted_type->data.maybe.child_type, actual_type).id == ConstCastResultIdOk) { | |
| 8228 | 8253 | return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type); |
| 8229 | 8254 | } else if (actual_type->id == TypeTableEntryIdNumLitInt || |
| 8230 | 8255 | actual_type->id == TypeTableEntryIdNumLitFloat) |
| ... | ... | @@ -8246,7 +8271,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8246 | 8271 | |
| 8247 | 8272 | // explicit cast from child type of error type to error type |
| 8248 | 8273 | if (wanted_type->id == TypeTableEntryIdErrorUnion) { |
| 8249 | if (types_match_const_cast_only(ira->codegen, wanted_type->data.error_union.payload_type, actual_type)) { | |
| 8274 | if (types_match_const_cast_only(ira->codegen, wanted_type->data.error_union.payload_type, actual_type).id == ConstCastResultIdOk) { | |
| 8250 | 8275 | return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type); |
| 8251 | 8276 | } else if (actual_type->id == TypeTableEntryIdNumLitInt || |
| 8252 | 8277 | actual_type->id == TypeTableEntryIdNumLitFloat) |
| ... | ... | @@ -8268,7 +8293,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8268 | 8293 | wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index].type_entry; |
| 8269 | 8294 | assert(ptr_type->id == TypeTableEntryIdPointer); |
| 8270 | 8295 | if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && |
| 8271 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type)) | |
| 8296 | types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type).id == ConstCastResultIdOk) | |
| 8272 | 8297 | { |
| 8273 | 8298 | IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); |
| 8274 | 8299 | if (type_is_invalid(cast1->value.type)) |
| ... | ... | @@ -8295,7 +8320,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8295 | 8320 | actual_type->id != TypeTableEntryIdMaybe) |
| 8296 | 8321 | { |
| 8297 | 8322 | TypeTableEntry *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type; |
| 8298 | if (types_match_const_cast_only(ira->codegen, wanted_child_type, actual_type) || | |
| 8323 | if (types_match_const_cast_only(ira->codegen, wanted_child_type, actual_type).id == ConstCastResultIdOk || | |
| 8299 | 8324 | actual_type->id == TypeTableEntryIdNullLit || |
| 8300 | 8325 | actual_type->id == TypeTableEntryIdNumLitInt || |
| 8301 | 8326 | actual_type->id == TypeTableEntryIdNumLitFloat) |
| ... | ... | @@ -8445,7 +8470,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst |
| 8445 | 8470 | // explicit cast from something to const pointer of it |
| 8446 | 8471 | if (!type_requires_comptime(actual_type)) { |
| 8447 | 8472 | TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true); |
| 8448 | if (types_match_const_cast_only(ira->codegen, wanted_type, const_ptr_actual)) { | |
| 8473 | if (types_match_const_cast_only(ira->codegen, wanted_type, const_ptr_actual).id == ConstCastResultIdOk) { | |
| 8449 | 8474 | return ir_analyze_cast_ref(ira, source_instr, value, wanted_type); |
| 8450 | 8475 | } |
| 8451 | 8476 | } |
| ... | ... | @@ -8473,7 +8498,7 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ |
| 8473 | 8498 | ImplicitCastMatchResult result = ir_types_match_with_implicit_cast(ira, expected_type, value->value.type, value); |
| 8474 | 8499 | switch (result) { |
| 8475 | 8500 | case ImplicitCastMatchResultNo: |
| 8476 | ErrorMsg *msg = ir_add_error(ira, value, | |
| 8501 | ir_add_error(ira, value, | |
| 8477 | 8502 | buf_sprintf("expected type '%s', found '%s'", |
| 8478 | 8503 | buf_ptr(&expected_type->name), |
| 8479 | 8504 | buf_ptr(&value->value.type->name))); |
std/debug/index.zig+1-2| ... | ... | @@ -209,8 +209,7 @@ fn printSourceAtAddress(debug_info: &ElfStackTrace, out_stream: &io.OutStream, a |
| 209 | 209 | try out_stream.write(GREEN ++ "^" ++ RESET ++ "\n"); |
| 210 | 210 | } |
| 211 | 211 | } else |err| switch (err) { |
| 212 | error.EndOfFile, error.PathNotFound => {}, | |
| 213 | else => return err, | |
| 212 | error.EndOfFile => {}, | |
| 214 | 213 | } |
| 215 | 214 | } else |err| switch (err) { |
| 216 | 215 | error.MissingDebugInfo, error.InvalidDebugInfo => { |
std/fmt/index.zig+20-13| ... | ... | @@ -195,7 +195,7 @@ pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@ |
| 195 | 195 | const T = @typeOf(value); |
| 196 | 196 | switch (@typeId(T)) { |
| 197 | 197 | builtin.TypeId.Int => { |
| 198 | return formatInt(value, 10, false, 0, context, output); | |
| 198 | return formatInt(value, 10, false, 0, context, Errors, output); | |
| 199 | 199 | }, |
| 200 | 200 | builtin.TypeId.Float => { |
| 201 | 201 | return formatFloat(value, context, output); |
| ... | ... | @@ -290,7 +290,7 @@ pub fn formatFloat(value: var, context: var, comptime Errors: type, output: fn(@ |
| 290 | 290 | |
| 291 | 291 | if (float_decimal.exp != 1) { |
| 292 | 292 | try output(context, "e"); |
| 293 | try formatInt(float_decimal.exp - 1, 10, false, 0, context, output); | |
| 293 | try formatInt(float_decimal.exp - 1, 10, false, 0, context, Errors, output); | |
| 294 | 294 | } |
| 295 | 295 | } |
| 296 | 296 | |
| ... | ... | @@ -336,12 +336,12 @@ pub fn formatFloatDecimal(value: var, precision: usize, context: var, comptime E |
| 336 | 336 | |
| 337 | 337 | |
| 338 | 338 | pub fn formatInt(value: var, base: u8, uppercase: bool, width: usize, |
| 339 | context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)errors!void) errors!void | |
| 339 | context: var, comptime Errors: type, output: fn(@typeOf(context), []const u8)Errors!void) Errors!void | |
| 340 | 340 | { |
| 341 | 341 | if (@typeOf(value).is_signed) { |
| 342 | return formatIntSigned(value, base, uppercase, width, context, output); | |
| 342 | return formatIntSigned(value, base, uppercase, width, context, Errors, output); | |
| 343 | 343 | } else { |
| 344 | return formatIntUnsigned(value, base, uppercase, width, context, output); | |
| 344 | return formatIntUnsigned(value, base, uppercase, width, context, Errors, output); | |
| 345 | 345 | } |
| 346 | 346 | } |
| 347 | 347 | |
| ... | ... | @@ -354,15 +354,15 @@ fn formatIntSigned(value: var, base: u8, uppercase: bool, width: usize, |
| 354 | 354 | try output(context, (&minus_sign)[0..1]); |
| 355 | 355 | const new_value = uint(-(value + 1)) + 1; |
| 356 | 356 | const new_width = if (width == 0) 0 else (width - 1); |
| 357 | return formatIntUnsigned(new_value, base, uppercase, new_width, context, output); | |
| 357 | return formatIntUnsigned(new_value, base, uppercase, new_width, context, Errors, output); | |
| 358 | 358 | } else if (width == 0) { |
| 359 | return formatIntUnsigned(uint(value), base, uppercase, width, context, output); | |
| 359 | return formatIntUnsigned(uint(value), base, uppercase, width, context, Errors, output); | |
| 360 | 360 | } else { |
| 361 | 361 | const plus_sign: u8 = '+'; |
| 362 | 362 | try output(context, (&plus_sign)[0..1]); |
| 363 | 363 | const new_value = uint(value); |
| 364 | 364 | const new_width = if (width == 0) 0 else (width - 1); |
| 365 | return formatIntUnsigned(new_value, base, uppercase, new_width, context, output); | |
| 365 | return formatIntUnsigned(new_value, base, uppercase, new_width, context, Errors, output); | |
| 366 | 366 | } |
| 367 | 367 | } |
| 368 | 368 | |
| ... | ... | @@ -410,7 +410,7 @@ pub fn formatIntBuf(out_buf: []u8, value: var, base: u8, uppercase: bool, width: |
| 410 | 410 | .out_buf = out_buf, |
| 411 | 411 | .index = 0, |
| 412 | 412 | }; |
| 413 | formatInt(value, base, uppercase, width, &context, formatIntCallback) catch unreachable; | |
| 413 | formatInt(value, base, uppercase, width, &context, error{}, formatIntCallback) catch unreachable; | |
| 414 | 414 | return context.index; |
| 415 | 415 | } |
| 416 | 416 | const FormatIntBuf = struct { |
| ... | ... | @@ -446,7 +446,14 @@ test "fmt.parseInt" { |
| 446 | 446 | assert(if (parseInt(u8, "256", 10)) |_| false else |err| err == error.Overflow); |
| 447 | 447 | } |
| 448 | 448 | |
| 449 | pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) !T { | |
| 449 | const ParseUnsignedError = error { | |
| 450 | /// The result cannot fit in the type specified | |
| 451 | Overflow, | |
| 452 | /// The input had a byte that was not a digit | |
| 453 | InvalidCharacter, | |
| 454 | }; | |
| 455 | ||
| 456 | pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) ParseUnsignedError!T { | |
| 450 | 457 | var x: T = 0; |
| 451 | 458 | |
| 452 | 459 | for (buf) |c| { |
| ... | ... | @@ -458,16 +465,16 @@ pub fn parseUnsigned(comptime T: type, buf: []const u8, radix: u8) !T { |
| 458 | 465 | return x; |
| 459 | 466 | } |
| 460 | 467 | |
| 461 | fn charToDigit(c: u8, radix: u8) !u8 { | |
| 468 | fn charToDigit(c: u8, radix: u8) (error{InvalidCharacter}!u8) { | |
| 462 | 469 | const value = switch (c) { |
| 463 | 470 | '0' ... '9' => c - '0', |
| 464 | 471 | 'A' ... 'Z' => c - 'A' + 10, |
| 465 | 472 | 'a' ... 'z' => c - 'a' + 10, |
| 466 | else => return error.InvalidChar, | |
| 473 | else => return error.InvalidCharacter, | |
| 467 | 474 | }; |
| 468 | 475 | |
| 469 | 476 | if (value >= radix) |
| 470 | return error.InvalidChar; | |
| 477 | return error.InvalidCharacter; | |
| 471 | 478 | |
| 472 | 479 | return value; |
| 473 | 480 | } |
std/math/index.zig+3-3| ... | ... | @@ -191,17 +191,17 @@ test "math.max" { |
| 191 | 191 | assert(max(i32(-1), i32(2)) == 2); |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | pub fn mul(comptime T: type, a: T, b: T) !T { | |
| 194 | pub fn mul(comptime T: type, a: T, b: T) (error{Overflow}!T) { | |
| 195 | 195 | var answer: T = undefined; |
| 196 | 196 | return if (@mulWithOverflow(T, a, b, &answer)) error.Overflow else answer; |
| 197 | 197 | } |
| 198 | 198 | |
| 199 | pub fn add(comptime T: type, a: T, b: T) !T { | |
| 199 | pub fn add(comptime T: type, a: T, b: T) (error{Overflow}!T) { | |
| 200 | 200 | var answer: T = undefined; |
| 201 | 201 | return if (@addWithOverflow(T, a, b, &answer)) error.Overflow else answer; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | pub fn sub(comptime T: type, a: T, b: T) !T { | |
| 204 | pub fn sub(comptime T: type, a: T, b: T) (error{Overflow}!T) { | |
| 205 | 205 | var answer: T = undefined; |
| 206 | 206 | return if (@subWithOverflow(T, a, b, &answer)) error.Overflow else answer; |
| 207 | 207 | } |
test/cases/cast.zig+16-16| ... | ... | @@ -74,7 +74,7 @@ test "string literal to &const []const u8" { |
| 74 | 74 | assert(mem.eql(u8, *x, "hello")); |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | test "implicitly cast from T to %?T" { | |
| 77 | test "implicitly cast from T to error!?T" { | |
| 78 | 78 | castToMaybeTypeError(1); |
| 79 | 79 | comptime castToMaybeTypeError(1); |
| 80 | 80 | } |
| ... | ... | @@ -83,37 +83,37 @@ const A = struct { |
| 83 | 83 | }; |
| 84 | 84 | fn castToMaybeTypeError(z: i32) void { |
| 85 | 85 | const x = i32(1); |
| 86 | const y: %?i32 = x; | |
| 86 | const y: error!?i32 = x; | |
| 87 | 87 | assert(??(try y) == 1); |
| 88 | 88 | |
| 89 | 89 | const f = z; |
| 90 | const g: %?i32 = f; | |
| 90 | const g: error!?i32 = f; | |
| 91 | 91 | |
| 92 | 92 | const a = A{ .a = z }; |
| 93 | const b: %?A = a; | |
| 93 | const b: error!?A = a; | |
| 94 | 94 | assert((??(b catch unreachable)).a == 1); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | test "implicitly cast from int to %?T" { | |
| 97 | test "implicitly cast from int to error!?T" { | |
| 98 | 98 | implicitIntLitToMaybe(); |
| 99 | 99 | comptime implicitIntLitToMaybe(); |
| 100 | 100 | } |
| 101 | 101 | fn implicitIntLitToMaybe() void { |
| 102 | 102 | const f: ?i32 = 1; |
| 103 | const g: %?i32 = 1; | |
| 103 | const g: error!?i32 = 1; | |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | |
| 107 | test "return null from fn() %?&T" { | |
| 107 | test "return null from fn() error!?&T" { | |
| 108 | 108 | const a = returnNullFromMaybeTypeErrorRef(); |
| 109 | 109 | const b = returnNullLitFromMaybeTypeErrorRef(); |
| 110 | 110 | assert((try a) == null and (try b) == null); |
| 111 | 111 | } |
| 112 | fn returnNullFromMaybeTypeErrorRef() !?&A { | |
| 112 | fn returnNullFromMaybeTypeErrorRef() error!?&A { | |
| 113 | 113 | const a: ?&A = null; |
| 114 | 114 | return a; |
| 115 | 115 | } |
| 116 | fn returnNullLitFromMaybeTypeErrorRef() !?&A { | |
| 116 | fn returnNullLitFromMaybeTypeErrorRef() error!?&A { | |
| 117 | 117 | return null; |
| 118 | 118 | } |
| 119 | 119 | |
| ... | ... | @@ -160,7 +160,7 @@ fn castToMaybeSlice() ?[]const u8 { |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | |
| 163 | test "implicitly cast from [0]T to %[]T" { | |
| 163 | test "implicitly cast from [0]T to error![]T" { | |
| 164 | 164 | testCastZeroArrayToErrSliceMut(); |
| 165 | 165 | comptime testCastZeroArrayToErrSliceMut(); |
| 166 | 166 | } |
| ... | ... | @@ -169,11 +169,11 @@ fn testCastZeroArrayToErrSliceMut() void { |
| 169 | 169 | assert((gimmeErrOrSlice() catch unreachable).len == 0); |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | fn gimmeErrOrSlice() ![]u8 { | |
| 172 | fn gimmeErrOrSlice() error![]u8 { | |
| 173 | 173 | return []u8{}; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | test "peer type resolution: [0]u8, []const u8, and %[]u8" { | |
| 176 | test "peer type resolution: [0]u8, []const u8, and error![]u8" { | |
| 177 | 177 | { |
| 178 | 178 | var data = "hi"; |
| 179 | 179 | const slice = data[0..]; |
| ... | ... | @@ -187,7 +187,7 @@ test "peer type resolution: [0]u8, []const u8, and %[]u8" { |
| 187 | 187 | assert((try peerTypeEmptyArrayAndSliceAndError(false, slice)).len == 1); |
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) ![]u8 { | |
| 190 | fn peerTypeEmptyArrayAndSliceAndError(a: bool, slice: []u8) error![]u8 { | |
| 191 | 191 | if (a) { |
| 192 | 192 | return []u8{}; |
| 193 | 193 | } |
| ... | ... | @@ -229,7 +229,7 @@ fn foo(args: ...) void { |
| 229 | 229 | |
| 230 | 230 | |
| 231 | 231 | test "peer type resolution: error and [N]T" { |
| 232 | // TODO: implicit %T to %U where T can implicitly cast to U | |
| 232 | // TODO: implicit error!T to error!U where T can implicitly cast to U | |
| 233 | 233 | //assert(mem.eql(u8, try testPeerErrorAndArray(0), "OK")); |
| 234 | 234 | //comptime assert(mem.eql(u8, try testPeerErrorAndArray(0), "OK")); |
| 235 | 235 | |
| ... | ... | @@ -237,13 +237,13 @@ test "peer type resolution: error and [N]T" { |
| 237 | 237 | comptime assert(mem.eql(u8, try testPeerErrorAndArray2(1), "OKK")); |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | //fn testPeerErrorAndArray(x: u8) ![]const u8 { | |
| 240 | //fn testPeerErrorAndArray(x: u8) error![]const u8 { | |
| 241 | 241 | // return switch (x) { |
| 242 | 242 | // 0x00 => "OK", |
| 243 | 243 | // else => error.BadValue, |
| 244 | 244 | // }; |
| 245 | 245 | //} |
| 246 | fn testPeerErrorAndArray2(x: u8) ![]const u8 { | |
| 246 | fn testPeerErrorAndArray2(x: u8) error![]const u8 { | |
| 247 | 247 | return switch (x) { |
| 248 | 248 | 0x00 => "OK", |
| 249 | 249 | 0x01 => "OKK", |
test/cases/enum_with_members.zig+1-1| ... | ... | @@ -6,7 +6,7 @@ const ET = union(enum) { |
| 6 | 6 | SINT: i32, |
| 7 | 7 | UINT: u32, |
| 8 | 8 | |
| 9 | pub fn print(a: &const ET, buf: []u8) !usize { | |
| 9 | pub fn print(a: &const ET, buf: []u8) error!usize { | |
| 10 | 10 | return switch (*a) { |
| 11 | 11 | ET.SINT => |x| fmt.formatIntBuf(buf, x, 10, false, 0), |
| 12 | 12 | ET.UINT => |x| fmt.formatIntBuf(buf, x, 10, false, 0), |
test/cases/error.zig+7-7| ... | ... | @@ -1,16 +1,16 @@ |
| 1 | 1 | const assert = @import("std").debug.assert; |
| 2 | 2 | const mem = @import("std").mem; |
| 3 | 3 | |
| 4 | pub fn foo() !i32 { | |
| 4 | pub fn foo() error!i32 { | |
| 5 | 5 | const x = try bar(); |
| 6 | 6 | return x + 1; |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | pub fn bar() !i32 { | |
| 9 | pub fn bar() error!i32 { | |
| 10 | 10 | return 13; |
| 11 | 11 | } |
| 12 | 12 | |
| 13 | pub fn baz() !i32 { | |
| 13 | pub fn baz() error!i32 { | |
| 14 | 14 | const y = foo() catch 1234; |
| 15 | 15 | return y + 1; |
| 16 | 16 | } |
| ... | ... | @@ -50,7 +50,7 @@ test "error binary operator" { |
| 50 | 50 | assert(a == 3); |
| 51 | 51 | assert(b == 10); |
| 52 | 52 | } |
| 53 | fn errBinaryOperatorG(x: bool) !isize { | |
| 53 | fn errBinaryOperatorG(x: bool) error!isize { | |
| 54 | 54 | return if (x) error.ItBroke else isize(10); |
| 55 | 55 | } |
| 56 | 56 | |
| ... | ... | @@ -59,18 +59,18 @@ test "unwrap simple value from error" { |
| 59 | 59 | const i = unwrapSimpleValueFromErrorDo() catch unreachable; |
| 60 | 60 | assert(i == 13); |
| 61 | 61 | } |
| 62 | fn unwrapSimpleValueFromErrorDo() %isize { return 13; } | |
| 62 | fn unwrapSimpleValueFromErrorDo() error!isize { return 13; } | |
| 63 | 63 | |
| 64 | 64 | |
| 65 | 65 | test "error return in assignment" { |
| 66 | 66 | doErrReturnInAssignment() catch unreachable; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | fn doErrReturnInAssignment() !void { | |
| 69 | fn doErrReturnInAssignment() error!void { | |
| 70 | 70 | var x : i32 = undefined; |
| 71 | 71 | x = try makeANonErr(); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | fn makeANonErr() !i32 { | |
| 74 | fn makeANonErr() error!i32 { | |
| 75 | 75 | return 1; |
| 76 | 76 | } |
test/cases/ir_block_deps.zig+1-1| ... | ... | @@ -11,7 +11,7 @@ fn foo(id: u64) !i32 { |
| 11 | 11 | }; |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | fn getErrInt() %i32 { return 0; } | |
| 14 | fn getErrInt() error!i32 { return 0; } | |
| 15 | 15 | |
| 16 | 16 | test "ir block deps" { |
| 17 | 17 | assert((foo(1) catch unreachable) == 0); |
test/cases/misc.zig+4-4| ... | ... | @@ -262,7 +262,7 @@ test "generic malloc free" { |
| 262 | 262 | memFree(u8, a); |
| 263 | 263 | } |
| 264 | 264 | const some_mem : [100]u8 = undefined; |
| 265 | fn memAlloc(comptime T: type, n: usize) ![]T { | |
| 265 | fn memAlloc(comptime T: type, n: usize) error![]T { | |
| 266 | 266 | return @ptrCast(&T, &some_mem[0])[0..n]; |
| 267 | 267 | } |
| 268 | 268 | fn memFree(comptime T: type, memory: []T) void { } |
| ... | ... | @@ -419,7 +419,7 @@ test "cast slice to u8 slice" { |
| 419 | 419 | test "pointer to void return type" { |
| 420 | 420 | testPointerToVoidReturnType() catch unreachable; |
| 421 | 421 | } |
| 422 | fn testPointerToVoidReturnType() !void { | |
| 422 | fn testPointerToVoidReturnType() error!void { | |
| 423 | 423 | const a = testPointerToVoidReturnType2(); |
| 424 | 424 | return *a; |
| 425 | 425 | } |
| ... | ... | @@ -475,8 +475,8 @@ test "@typeId" { |
| 475 | 475 | assert(@typeId(@typeOf(undefined)) == Tid.UndefinedLiteral); |
| 476 | 476 | assert(@typeId(@typeOf(null)) == Tid.NullLiteral); |
| 477 | 477 | assert(@typeId(?i32) == Tid.Nullable); |
| 478 | assert(@typeId(%i32) == Tid.ErrorUnion); | |
| 479 | assert(@typeId(error) == Tid.Error); | |
| 478 | assert(@typeId(error!i32) == Tid.ErrorUnion); | |
| 479 | assert(@typeId(error) == Tid.ErrorSet); | |
| 480 | 480 | assert(@typeId(AnEnum) == Tid.Enum); |
| 481 | 481 | assert(@typeId(@typeOf(AUnionEnum.One)) == Tid.Enum); |
| 482 | 482 | assert(@typeId(AUnionEnum) == Tid.Union); |
test/cases/reflection.zig+1-1| ... | ... | @@ -5,7 +5,7 @@ test "reflection: array, pointer, nullable, error union type child" { |
| 5 | 5 | comptime { |
| 6 | 6 | assert(([10]u8).Child == u8); |
| 7 | 7 | assert((&u8).Child == u8); |
| 8 | assert((%u8).Child == u8); | |
| 8 | assert((error!u8).Payload == u8); | |
| 9 | 9 | assert((?u8).Child == u8); |
| 10 | 10 | } |
| 11 | 11 | } |
test/cases/switch.zig+1-1| ... | ... | @@ -225,7 +225,7 @@ fn switchWithUnreachable(x: i32) i32 { |
| 225 | 225 | return 10; |
| 226 | 226 | } |
| 227 | 227 | |
| 228 | fn return_a_number() !i32 { | |
| 228 | fn return_a_number() error!i32 { | |
| 229 | 229 | return 1; |
| 230 | 230 | } |
| 231 | 231 |
test/cases/switch_prong_err_enum.zig+2-2| ... | ... | @@ -2,7 +2,7 @@ const assert = @import("std").debug.assert; |
| 2 | 2 | |
| 3 | 3 | var read_count: u64 = 0; |
| 4 | 4 | |
| 5 | fn readOnce() !u64 { | |
| 5 | fn readOnce() error!u64 { | |
| 6 | 6 | read_count += 1; |
| 7 | 7 | return read_count; |
| 8 | 8 | } |
| ... | ... | @@ -12,7 +12,7 @@ const FormValue = union(enum) { |
| 12 | 12 | Other: bool, |
| 13 | 13 | }; |
| 14 | 14 | |
| 15 | fn doThing(form_id: u64) !FormValue { | |
| 15 | fn doThing(form_id: u64) error!FormValue { | |
| 16 | 16 | return switch (form_id) { |
| 17 | 17 | 17 => FormValue { .Address = try readOnce() }, |
| 18 | 18 | else => error.InvalidDebugInfo, |
test/cases/try.zig+2-2| ... | ... | @@ -17,7 +17,7 @@ fn tryOnErrorUnionImpl() void { |
| 17 | 17 | assert(x == 11); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | fn returnsTen() !i32 { | |
| 20 | fn returnsTen() error!i32 { | |
| 21 | 21 | return 10; |
| 22 | 22 | } |
| 23 | 23 | |
| ... | ... | @@ -29,7 +29,7 @@ test "try without vars" { |
| 29 | 29 | assert(result2 == 1); |
| 30 | 30 | } |
| 31 | 31 | |
| 32 | fn failIfTrue(ok: bool) !void { | |
| 32 | fn failIfTrue(ok: bool) error!void { | |
| 33 | 33 | if (ok) { |
| 34 | 34 | return error.ItBroke; |
| 35 | 35 | } else { |
test/cases/union.zig+1-1| ... | ... | @@ -13,7 +13,7 @@ const Agg = struct { |
| 13 | 13 | const v1 = Value { .Int = 1234 }; |
| 14 | 14 | const v2 = Value { .Array = []u8{3} ** 9 }; |
| 15 | 15 | |
| 16 | const err = (%Agg)(Agg { | |
| 16 | const err = (error!Agg)(Agg { | |
| 17 | 17 | .val1 = v1, |
| 18 | 18 | .val2 = v2, |
| 19 | 19 | }); |
test/cases/while.zig+4-4| ... | ... | @@ -50,7 +50,7 @@ fn runContinueAndBreakTest() void { |
| 50 | 50 | test "return with implicit cast from while loop" { |
| 51 | 51 | returnWithImplicitCastFromWhileLoopTest() catch unreachable; |
| 52 | 52 | } |
| 53 | fn returnWithImplicitCastFromWhileLoopTest() !void { | |
| 53 | fn returnWithImplicitCastFromWhileLoopTest() error!void { | |
| 54 | 54 | while (true) { |
| 55 | 55 | return; |
| 56 | 56 | } |
| ... | ... | @@ -116,7 +116,7 @@ test "while with error union condition" { |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | var numbers_left: i32 = undefined; |
| 119 | fn getNumberOrErr() !i32 { | |
| 119 | fn getNumberOrErr() error!i32 { | |
| 120 | 120 | return if (numbers_left == 0) |
| 121 | 121 | error.OutOfNumbers |
| 122 | 122 | else x: { |
| ... | ... | @@ -204,7 +204,7 @@ fn testContinueOuter() void { |
| 204 | 204 | |
| 205 | 205 | fn returnNull() ?i32 { return null; } |
| 206 | 206 | fn returnMaybe(x: i32) ?i32 { return x; } |
| 207 | fn returnError() %i32 { return error.YouWantedAnError; } | |
| 208 | fn returnSuccess(x: i32) %i32 { return x; } | |
| 207 | fn returnError() error!i32 { return error.YouWantedAnError; } | |
| 208 | fn returnSuccess(x: i32) error!i32 { return x; } | |
| 209 | 209 | fn returnFalse() bool { return false; } |
| 210 | 210 | fn returnTrue() bool { return true; } |