Fix inferred error set return types

This commit is contained in:
Luuk de Gram
2021-03-07 18:45:37 +01:00
parent e2f4bbf2f3
commit 53c37765c0
3 changed files with 21 additions and 5 deletions

View File

@@ -467,8 +467,24 @@ pub fn resolveReturnType(
}
if (fn_decl.ast.return_type == 0) return null;
return ((try resolveTypeOfNodeInternal(store, arena, .{
.node = fn_decl.ast.return_type,
const return_type = fn_decl.ast.return_type;
const is_inferred_error = tree.tokens.items(.tag)[tree.firstToken(return_type) - 1] == .bang;
return if (is_inferred_error) block: {
const child_type = (try resolveTypeOfNodeInternal(store, arena, .{
.node = return_type,
.handle = handle,
}, bound_type_params)) orelse return null;
const child_type_node = switch (child_type.type.data) {
.other => |n| n,
else => return null,
};
break :block TypeWithHandle{
.type = .{ .data = .{ .error_union = child_type_node }, .is_type_val = false },
.handle = child_type.handle,
};
} else ((try resolveTypeOfNodeInternal(store, arena, .{
.node = return_type,
.handle = handle,
}, bound_type_params)) orelse return null).instanceTypeVal();
}
@@ -509,6 +525,7 @@ fn resolveUnwrapErrorType(
},
.primitive, .slice, .pointer => return null,
};
if (rhs.handle.tree.nodes.items(.tag)[rhs_node] == .error_union) {
return ((try resolveTypeOfNodeInternal(store, arena, .{
.node = rhs.handle.tree.nodes.items(.data)[rhs_node].rhs,