@@ -4935,9 +4935,8 @@ static IrInstruction *ir_gen_fn_call(IrBuilder *irb, Scope *scope, AstNode *node
4935
4935
size_t arg_count = node->data.fn_call_expr.params.length;
4936
4936
IrInstruction **args = allocate<IrInstruction*>(arg_count);
4937
4937
for (size_t i = 0; i < arg_count; i += 1) {
4938
- IrInstruction *param_result_loc = ir_build_result_param(irb, scope, node, fn_ref, i);
4939
4938
AstNode *arg_node = node->data.fn_call_expr.params.at(i);
4940
- args[i] = ir_gen_node(irb, arg_node, scope, LValNone, param_result_loc );
4939
+ args[i] = ir_gen_node(irb, arg_node, scope, LValNone, nullptr );
4941
4940
if (args[i] == irb->codegen->invalid_instruction)
4942
4941
return args[i];
4943
4942
}
@@ -10885,7 +10884,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10885
10884
}
10886
10885
}
10887
10886
10888
- // cast from error set to error union type
10887
+ // cast from E to E!T
10889
10888
if (wanted_type->id == ZigTypeIdErrorUnion &&
10890
10889
actual_type->id == ZigTypeIdErrorSet)
10891
10890
{
@@ -11200,6 +11199,27 @@ static IrInstruction *ir_implicit_cast_result(IrAnalyze *ira, IrInstruction *res
11200
11199
return ir_analyze_result_error_union_code(ira, result_loc, needed_child_type);
11201
11200
}
11202
11201
11202
+ // cast from T to E!?T
11203
+ if (have_child_type->id == ZigTypeIdErrorUnion &&
11204
+ have_child_type->data.error_union.payload_type->id == ZigTypeIdOptional &&
11205
+ needed_child_type->id != ZigTypeIdOptional)
11206
+ {
11207
+ ZigType *wanted_child_type = have_child_type->data.error_union.payload_type->data.maybe.child_type;
11208
+ if (types_match_const_cast_only(ira, wanted_child_type, needed_child_type, source_node,
11209
+ false).id == ConstCastResultIdOk ||
11210
+ needed_child_type->id == ZigTypeIdNull ||
11211
+ needed_child_type->id == ZigTypeIdComptimeInt ||
11212
+ needed_child_type->id == ZigTypeIdComptimeFloat)
11213
+ {
11214
+ IrInstruction *cast1 = ir_implicit_cast_result(ira, result_loc,
11215
+ have_child_type->data.error_union.payload_type);
11216
+ if (type_is_invalid(cast1->value.type))
11217
+ return ira->codegen->invalid_instruction;
11218
+
11219
+ return ir_implicit_cast_result(ira, cast1, needed_child_type);
11220
+ }
11221
+ }
11222
+
11203
11223
ErrorMsg *parent_msg = ir_add_error_node(ira, source_node,
11204
11224
buf_sprintf("expected type '%s', found '%s'",
11205
11225
buf_ptr(&have_child_type->name),
0 commit comments