authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-01 10:23:25-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-01 10:23:25-05:00
log13b36d458f6ba45fdda1c1510e056a7012fb3fff
tree26afe03e50c7206f390ff44b4347bd493cfa067e
parent5f518dbeb952186b7c11777b2454256c8c4fb9ac

*WIP* error sets - fix implicit cast


8 files changed, 92 insertions(+), 55 deletions(-)

TODO+2-1
......@@ -2,4 +2,5 @@ sed -i 's/\(\bfn .*) \)%\(.*{\)$/\1!\2/g' $(find .. -name "*.zig")
22
33comptime assert(error{} ! i32 == i32);
44
5
5// TODO this is an explicit cast and should actually coerce the type
6 erorr set casting
src/analyze.cpp+38-9
......@@ -1274,7 +1274,7 @@ static bool type_allowed_in_extern(CodeGen *g, TypeTableEntry *type_entry) {
12741274 zig_unreachable();
12751275}
12761276
1277static TypeTableEntry *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry) {
1277TypeTableEntry *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry) {
12781278 TypeTableEntry *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet);
12791279 buf_resize(&err_set_type->name, 0);
12801280 buf_appendf(&err_set_type->name, "%s.errors", buf_ptr(&fn_entry->symbol_name));
......@@ -3366,7 +3366,7 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *so
33663366 g->tld_ref_source_node_stack.pop();
33673367}
33683368
3369bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *actual_type) {
3369bool types_match_const_cast_only(CodeGen *g, TypeTableEntry *expected_type, TypeTableEntry *actual_type) {
33703370 if (expected_type == actual_type)
33713371 return true;
33723372
......@@ -3379,7 +3379,7 @@ bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *
33793379 actual_type->data.pointer.unaligned_bit_count == expected_type->data.pointer.unaligned_bit_count &&
33803380 actual_type->data.pointer.alignment >= expected_type->data.pointer.alignment)
33813381 {
3382 return types_match_const_cast_only(expected_type->data.pointer.child_type,
3382 return types_match_const_cast_only(g, expected_type->data.pointer.child_type,
33833383 actual_type->data.pointer.child_type);
33843384 }
33853385
......@@ -3397,7 +3397,7 @@ bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *
33973397 actual_ptr_type->data.pointer.unaligned_bit_count == expected_ptr_type->data.pointer.unaligned_bit_count &&
33983398 actual_ptr_type->data.pointer.alignment >= expected_ptr_type->data.pointer.alignment)
33993399 {
3400 return types_match_const_cast_only(expected_ptr_type->data.pointer.child_type,
3400 return types_match_const_cast_only(g, expected_ptr_type->data.pointer.child_type,
34013401 actual_ptr_type->data.pointer.child_type);
34023402 }
34033403 }
......@@ -3406,7 +3406,7 @@ bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *
34063406 if (expected_type->id == TypeTableEntryIdMaybe &&
34073407 actual_type->id == TypeTableEntryIdMaybe)
34083408 {
3409 return types_match_const_cast_only(
3409 return types_match_const_cast_only(g,
34103410 expected_type->data.maybe.child_type,
34113411 actual_type->data.maybe.child_type);
34123412 }
......@@ -3415,14 +3415,43 @@ bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *
34153415 if (expected_type->id == TypeTableEntryIdErrorUnion &&
34163416 actual_type->id == TypeTableEntryIdErrorUnion)
34173417 {
3418 return types_match_const_cast_only(
3418 return types_match_const_cast_only(g,
34193419 expected_type->data.error_union.payload_type,
34203420 actual_type->data.error_union.payload_type) &&
3421 types_match_const_cast_only(
3421 types_match_const_cast_only(g,
34223422 expected_type->data.error_union.err_set_type,
34233423 actual_type->data.error_union.err_set_type);
34243424 }
34253425
3426 // error set
3427 if (expected_type->id == TypeTableEntryIdErrorSet &&
3428 actual_type->id == TypeTableEntryIdErrorSet)
3429 {
3430 TypeTableEntry *contained_set = actual_type;
3431 TypeTableEntry *container_set = expected_type;
3432
3433 if (container_set == g->builtin_types.entry_global_error_set ||
3434 container_set->data.error_set.infer_fn != nullptr)
3435 {
3436 return true;
3437 }
3438
3439 ErrorTableEntry **errors = allocate<ErrorTableEntry *>(g->errors_by_index.length);
3440 for (uint32_t i = 0; i < container_set->data.error_set.err_count; i += 1) {
3441 ErrorTableEntry *error_entry = container_set->data.error_set.errors[i];
3442 errors[error_entry->value] = error_entry;
3443 }
3444 for (uint32_t i = 0; i < contained_set->data.error_set.err_count; i += 1) {
3445 ErrorTableEntry *contained_error_entry = contained_set->data.error_set.errors[i];
3446 ErrorTableEntry *error_entry = errors[contained_error_entry->value];
3447 if (error_entry == nullptr) {
3448 return false;
3449 }
3450 }
3451 free(errors);
3452 return true;
3453 }
3454
34263455 // fn
34273456 if (expected_type->id == TypeTableEntryIdFn &&
34283457 actual_type->id == TypeTableEntryIdFn)
......@@ -3441,7 +3470,7 @@ bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *
34413470 }
34423471 if (!expected_type->data.fn.is_generic &&
34433472 actual_type->data.fn.fn_type_id.return_type->id != TypeTableEntryIdUnreachable &&
3444 !types_match_const_cast_only(
3473 !types_match_const_cast_only(g,
34453474 expected_type->data.fn.fn_type_id.return_type,
34463475 actual_type->data.fn.fn_type_id.return_type))
34473476 {
......@@ -3460,7 +3489,7 @@ bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *
34603489 FnTypeParamInfo *actual_param_info = &actual_type->data.fn.fn_type_id.param_info[i];
34613490 FnTypeParamInfo *expected_param_info = &expected_type->data.fn.fn_type_id.param_info[i];
34623491
3463 if (!types_match_const_cast_only(actual_param_info->type, expected_param_info->type)) {
3492 if (!types_match_const_cast_only(g, actual_param_info->type, expected_param_info->type)) {
34643493 return false;
34653494 }
34663495
src/analyze.hpp+2-1
......@@ -46,7 +46,7 @@ bool type_has_bits(TypeTableEntry *type_entry);
4646ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *abs_full_path, Buf *source_code);
4747
4848
49bool types_match_const_cast_only(TypeTableEntry *expected_type, TypeTableEntry *actual_type);
49bool types_match_const_cast_only(CodeGen *g, TypeTableEntry *expected_type, TypeTableEntry *actual_type);
5050VariableTableEntry *find_variable(CodeGen *g, Scope *orig_context, Buf *name);
5151Tld *find_decl(CodeGen *g, Scope *scope, Buf *name);
5252void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *source_node);
......@@ -189,5 +189,6 @@ ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name);
189189TypeTableEntry *get_ptr_to_stack_trace_type(CodeGen *g);
190190void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry);
191191
192TypeTableEntry *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry);
192193
193194#endif
src/ir.cpp+36-37
......@@ -6375,7 +6375,7 @@ enum ImplicitCastMatchResult {
63756375static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira, TypeTableEntry *expected_type,
63766376 TypeTableEntry *actual_type, IrInstruction *value)
63776377{
6378 if (types_match_const_cast_only(expected_type, actual_type)) {
6378 if (types_match_const_cast_only(ira->codegen, expected_type, actual_type)) {
63796379 return ImplicitCastMatchResultYes;
63806380 }
63816381
......@@ -6412,13 +6412,6 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
64126412 return ImplicitCastMatchResultYes;
64136413 }
64146414
6415 // implicit conversion from error set to another error set
6416 if (expected_type->id == TypeTableEntryIdErrorSet &&
6417 actual_type->id == TypeTableEntryIdErrorSet)
6418 {
6419 return ImplicitCastMatchResultYes;
6420 }
6421
64226415 // implicit conversion from T to U!?T
64236416 if (expected_type->id == TypeTableEntryIdErrorUnion &&
64246417 expected_type->data.error_union.payload_type->id == TypeTableEntryIdMaybe &&
......@@ -6463,7 +6456,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
64636456 assert(ptr_type->id == TypeTableEntryIdPointer);
64646457
64656458 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
6466 types_match_const_cast_only(ptr_type->data.pointer.child_type, actual_type->data.array.child_type))
6459 types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type))
64676460 {
64686461 return ImplicitCastMatchResultYes;
64696462 }
......@@ -6482,7 +6475,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
64826475 TypeTableEntry *array_type = actual_type->data.pointer.child_type;
64836476
64846477 if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) &&
6485 types_match_const_cast_only(ptr_type->data.pointer.child_type, array_type->data.array.child_type))
6478 types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, array_type->data.array.child_type))
64866479 {
64876480 return ImplicitCastMatchResultYes;
64886481 }
......@@ -6498,7 +6491,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
64986491 expected_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry;
64996492 assert(ptr_type->id == TypeTableEntryIdPointer);
65006493 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
6501 types_match_const_cast_only(ptr_type->data.pointer.child_type, actual_type->data.array.child_type))
6494 types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type))
65026495 {
65036496 return ImplicitCastMatchResultYes;
65046497 }
......@@ -6513,7 +6506,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
65136506 expected_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry;
65146507 assert(ptr_type->id == TypeTableEntryIdPointer);
65156508 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
6516 types_match_const_cast_only(ptr_type->data.pointer.child_type, actual_type->data.array.child_type))
6509 types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type))
65176510 {
65186511 return ImplicitCastMatchResultYes;
65196512 }
......@@ -6593,7 +6586,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
65936586 // implicitly take a const pointer to something
65946587 if (!type_requires_comptime(actual_type)) {
65956588 TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true);
6596 if (types_match_const_cast_only(expected_type, const_ptr_actual)) {
6589 if (types_match_const_cast_only(ira->codegen, expected_type, const_ptr_actual)) {
65976590 return ImplicitCastMatchResultYes;
65986591 }
65996592 }
......@@ -6769,11 +6762,11 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
67696762 }
67706763 }
67716764
6772 if (types_match_const_cast_only(prev_type, cur_type)) {
6765 if (types_match_const_cast_only(ira->codegen, prev_type, cur_type)) {
67736766 continue;
67746767 }
67756768
6776 if (types_match_const_cast_only(cur_type, prev_type)) {
6769 if (types_match_const_cast_only(ira->codegen, cur_type, prev_type)) {
67776770 prev_inst = cur_inst;
67786771 continue;
67796772 }
......@@ -6796,26 +6789,26 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
67966789 }
67976790
67986791 if (prev_type->id == TypeTableEntryIdErrorUnion &&
6799 types_match_const_cast_only(prev_type->data.error_union.payload_type, cur_type))
6792 types_match_const_cast_only(ira->codegen, prev_type->data.error_union.payload_type, cur_type))
68006793 {
68016794 continue;
68026795 }
68036796
68046797 if (cur_type->id == TypeTableEntryIdErrorUnion &&
6805 types_match_const_cast_only(cur_type->data.error_union.payload_type, prev_type))
6798 types_match_const_cast_only(ira->codegen, cur_type->data.error_union.payload_type, prev_type))
68066799 {
68076800 prev_inst = cur_inst;
68086801 continue;
68096802 }
68106803
68116804 if (prev_type->id == TypeTableEntryIdMaybe &&
6812 types_match_const_cast_only(prev_type->data.maybe.child_type, cur_type))
6805 types_match_const_cast_only(ira->codegen, prev_type->data.maybe.child_type, cur_type))
68136806 {
68146807 continue;
68156808 }
68166809
68176810 if (cur_type->id == TypeTableEntryIdMaybe &&
6818 types_match_const_cast_only(cur_type->data.maybe.child_type, prev_type))
6811 types_match_const_cast_only(ira->codegen, cur_type->data.maybe.child_type, prev_type))
68196812 {
68206813 prev_inst = cur_inst;
68216814 continue;
......@@ -6853,7 +6846,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
68536846
68546847 if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray &&
68556848 cur_type->data.array.len != prev_type->data.array.len &&
6856 types_match_const_cast_only(cur_type->data.array.child_type, prev_type->data.array.child_type))
6849 types_match_const_cast_only(ira->codegen, cur_type->data.array.child_type, prev_type->data.array.child_type))
68576850 {
68586851 convert_to_const_slice = true;
68596852 prev_inst = cur_inst;
......@@ -6862,7 +6855,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
68626855
68636856 if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray &&
68646857 cur_type->data.array.len != prev_type->data.array.len &&
6865 types_match_const_cast_only(prev_type->data.array.child_type, cur_type->data.array.child_type))
6858 types_match_const_cast_only(ira->codegen, prev_type->data.array.child_type, cur_type->data.array.child_type))
68666859 {
68676860 convert_to_const_slice = true;
68686861 continue;
......@@ -6871,7 +6864,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
68716864 if (cur_type->id == TypeTableEntryIdArray && is_slice(prev_type) &&
68726865 (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||
68736866 cur_type->data.array.len == 0) &&
6874 types_match_const_cast_only(prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type,
6867 types_match_const_cast_only(ira->codegen, prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type,
68756868 cur_type->data.array.child_type))
68766869 {
68776870 convert_to_const_slice = false;
......@@ -6881,7 +6874,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
68816874 if (prev_type->id == TypeTableEntryIdArray && is_slice(cur_type) &&
68826875 (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const ||
68836876 prev_type->data.array.len == 0) &&
6884 types_match_const_cast_only(cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type,
6877 types_match_const_cast_only(ira->codegen, cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.child_type,
68856878 prev_type->data.array.child_type))
68866879 {
68876880 prev_inst = cur_inst;
......@@ -7449,6 +7442,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
74497442 return result;
74507443}
74517444
7445// TODO this is an explicit cast and should actually coerce the type
74527446static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value,
74537447 TypeTableEntry *wanted_type)
74547448{
......@@ -7999,7 +7993,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
79997993 return value;
80007994
80017995 // explicit match or non-const to const
8002 if (types_match_const_cast_only(wanted_type, actual_type)) {
7996 if (types_match_const_cast_only(ira->codegen, wanted_type, actual_type)) {
80037997 return ir_resolve_cast(ira, source_instr, value, wanted_type, CastOpNoop, false);
80047998 }
80057999
......@@ -8045,7 +8039,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
80458039 TypeTableEntry *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry;
80468040 assert(ptr_type->id == TypeTableEntryIdPointer);
80478041 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
8048 types_match_const_cast_only(ptr_type->data.pointer.child_type, actual_type->data.array.child_type))
8042 types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type))
80498043 {
80508044 return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type);
80518045 }
......@@ -8063,7 +8057,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
80638057 TypeTableEntry *array_type = actual_type->data.pointer.child_type;
80648058
80658059 if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) &&
8066 types_match_const_cast_only(ptr_type->data.pointer.child_type, array_type->data.array.child_type))
8060 types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, array_type->data.array.child_type))
80678061 {
80688062 return ir_analyze_array_to_slice(ira, source_instr, value, wanted_type);
80698063 }
......@@ -8079,7 +8073,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
80798073 wanted_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry;
80808074 assert(ptr_type->id == TypeTableEntryIdPointer);
80818075 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
8082 types_match_const_cast_only(ptr_type->data.pointer.child_type, actual_type->data.array.child_type))
8076 types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type))
80838077 {
80848078 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value);
80858079 if (type_is_invalid(cast1->value.type))
......@@ -8102,7 +8096,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
81028096 wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry;
81038097 assert(ptr_type->id == TypeTableEntryIdPointer);
81048098 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
8105 types_match_const_cast_only(ptr_type->data.pointer.child_type, actual_type->data.array.child_type))
8099 types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type))
81068100 {
81078101 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.maybe.child_type, value);
81088102 if (type_is_invalid(cast1->value.type))
......@@ -8164,7 +8158,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
81648158
81658159 // explicit cast from child type of maybe type to maybe type
81668160 if (wanted_type->id == TypeTableEntryIdMaybe) {
8167 if (types_match_const_cast_only(wanted_type->data.maybe.child_type, actual_type)) {
8161 if (types_match_const_cast_only(ira->codegen, wanted_type->data.maybe.child_type, actual_type)) {
81688162 return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type);
81698163 } else if (actual_type->id == TypeTableEntryIdNumLitInt ||
81708164 actual_type->id == TypeTableEntryIdNumLitFloat)
......@@ -8186,7 +8180,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
81868180
81878181 // explicit cast from child type of error type to error type
81888182 if (wanted_type->id == TypeTableEntryIdErrorUnion) {
8189 if (types_match_const_cast_only(wanted_type->data.error_union.payload_type, actual_type)) {
8183 if (types_match_const_cast_only(ira->codegen, wanted_type->data.error_union.payload_type, actual_type)) {
81908184 return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type);
81918185 } else if (actual_type->id == TypeTableEntryIdNumLitInt ||
81928186 actual_type->id == TypeTableEntryIdNumLitFloat)
......@@ -8208,7 +8202,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
82088202 wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index].type_entry;
82098203 assert(ptr_type->id == TypeTableEntryIdPointer);
82108204 if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) &&
8211 types_match_const_cast_only(ptr_type->data.pointer.child_type, actual_type->data.array.child_type))
8205 types_match_const_cast_only(ira->codegen, ptr_type->data.pointer.child_type, actual_type->data.array.child_type))
82128206 {
82138207 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);
82148208 if (type_is_invalid(cast1->value.type))
......@@ -8235,7 +8229,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
82358229 actual_type->id != TypeTableEntryIdMaybe)
82368230 {
82378231 TypeTableEntry *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type;
8238 if (types_match_const_cast_only(wanted_child_type, actual_type) ||
8232 if (types_match_const_cast_only(ira->codegen, wanted_child_type, actual_type) ||
82398233 actual_type->id == TypeTableEntryIdNullLit ||
82408234 actual_type->id == TypeTableEntryIdNumLitInt ||
82418235 actual_type->id == TypeTableEntryIdNumLitFloat)
......@@ -8385,7 +8379,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
83858379 // explicit cast from something to const pointer of it
83868380 if (!type_requires_comptime(actual_type)) {
83878381 TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true);
8388 if (types_match_const_cast_only(wanted_type, const_ptr_actual)) {
8382 if (types_match_const_cast_only(ira->codegen, wanted_type, const_ptr_actual)) {
83898383 return ir_analyze_cast_ref(ira, source_instr, value, wanted_type);
83908384 }
83918385 }
......@@ -10386,12 +10380,17 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
1038610380
1038710381 {
1038810382 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
10389 TypeTableEntry *return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node);
10390 if (type_is_invalid(return_type))
10383 TypeTableEntry *specified_return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node);
10384 if (type_is_invalid(specified_return_type))
1039110385 return ira->codegen->builtin_types.entry_invalid;
10392 inst_fn_type_id.return_type = return_type;
10386 if (fn_proto_node->data.fn_proto.auto_err_set) {
10387 TypeTableEntry *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn);
10388 inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type);
10389 } else {
10390 inst_fn_type_id.return_type = specified_return_type;
10391 }
1039310392
10394 if (type_requires_comptime(return_type)) {
10393 if (type_requires_comptime(specified_return_type)) {
1039510394 // Throw out our work and call the function as if it were comptime.
1039610395 return ir_analyze_fn_call(ira, call_instruction, fn_entry, fn_type, fn_ref, first_arg_ptr, true, FnInlineAuto);
1039710396 }
std/fmt/index.zig+1-1
......@@ -220,7 +220,7 @@ pub fn formatValue(value: var, context: var, comptime Errors: type, output: fn(@
220220 return formatValue(err, context, Errors, output);
221221 }
222222 },
223 builtin.TypeId.Error => {
223 builtin.TypeId.ErrorSet => {
224224 try output(context, "error.");
225225 return output(context, @errorName(value));
226226 },
std/io.zig+5-3
......@@ -26,7 +26,9 @@ test "import io tests" {
2626 }
2727}
2828
29pub fn getStdErr() !File {
29const GetStdIoErrs = os.WindowsGetStdHandleErrs;
30
31pub fn getStdErr() GetStdIoErrs!File {
3032 const handle = if (is_windows)
3133 try os.windowsGetStdHandle(system.STD_ERROR_HANDLE)
3234 else if (is_posix)
......@@ -36,7 +38,7 @@ pub fn getStdErr() !File {
3638 return File.openHandle(handle);
3739}
3840
39pub fn getStdOut() !File {
41pub fn getStdOut() GetStdIoErrs!File {
4042 const handle = if (is_windows)
4143 try os.windowsGetStdHandle(system.STD_OUTPUT_HANDLE)
4244 else if (is_posix)
......@@ -46,7 +48,7 @@ pub fn getStdOut() !File {
4648 return File.openHandle(handle);
4749}
4850
49pub fn getStdIn() !File {
51pub fn getStdIn() GetStdIoErrs!File {
5052 const handle = if (is_windows)
5153 try os.windowsGetStdHandle(system.STD_INPUT_HANDLE)
5254 else if (is_posix)
std/mem.zig+2-2
......@@ -40,7 +40,7 @@ pub const Allocator = struct {
4040 }
4141
4242 fn alignedAlloc(self: &Allocator, comptime T: type, comptime alignment: u29,
43 n: usize) %[]align(alignment) T
43 n: usize) ![]align(alignment) T
4444 {
4545 const byte_count = try math.mul(usize, @sizeOf(T), n);
4646 const byte_slice = try self.allocFn(self, byte_count, alignment);
......@@ -56,7 +56,7 @@ pub const Allocator = struct {
5656 }
5757
5858 fn alignedRealloc(self: &Allocator, comptime T: type, comptime alignment: u29,
59 old_mem: []align(alignment) T, n: usize) %[]align(alignment) T
59 old_mem: []align(alignment) T, n: usize) ![]align(alignment) T
6060 {
6161 if (old_mem.len == 0) {
6262 return self.alloc(T, n);
std/os/index.zig+6-1
......@@ -1158,7 +1158,12 @@ pub fn posix_setregid(rgid: u32, egid: u32) !void {
11581158 };
11591159}
11601160
1161pub fn windowsGetStdHandle(handle_id: windows.DWORD) !windows.HANDLE {
1161pub const WindowsGetStdHandleErrs = error {
1162 NoStdHandles,
1163 Unexpected,
1164};
1165
1166pub fn windowsGetStdHandle(handle_id: windows.DWORD) WindowsGetStdHandleErrs!windows.HANDLE {
11621167 if (windows.GetStdHandle(handle_id)) |handle| {
11631168 if (handle == windows.INVALID_HANDLE_VALUE) {
11641169 const err = windows.GetLastError();