Simplified some code

This commit is contained in:
Alexandros Naskos 2020-06-14 23:43:29 +03:00
parent 48019dd7e2
commit e68bec8673

View File

@ -217,25 +217,25 @@ fn findReturnStatementInternal(
var child_idx: usize = 0; var child_idx: usize = 0;
while (base_node.iterate(child_idx)) |child_node| : (child_idx += 1) { while (base_node.iterate(child_idx)) |child_node| : (child_idx += 1) {
switch (child_node.id) { switch (child_node.id) {
.ControlFlowExpression => { .ControlFlowExpression => blk: {
const cfe = child_node.cast(ast.Node.ControlFlowExpression).?; const cfe = child_node.cast(ast.Node.ControlFlowExpression).?;
if (cfe.kind == .Return) { if (cfe.kind != .Return) break :blk;
// If we are calling ourselves recursively, ignore this return.
if (cfe.rhs) |rhs| { // If we are calling ourselves recursively, ignore this return.
if (rhs.cast(ast.Node.Call)) |call_node| { if (cfe.rhs) |rhs| {
if (call_node.lhs.id == .Identifier) { if (rhs.cast(ast.Node.Call)) |call_node| {
if (std.mem.eql(u8, getDeclName(tree, call_node.lhs).?, getDeclName(tree, &fn_decl.base).?)) { if (call_node.lhs.id == .Identifier) {
continue; if (std.mem.eql(u8, getDeclName(tree, call_node.lhs).?, getDeclName(tree, &fn_decl.base).?)) {
} continue;
} }
} }
} }
if (already_found.*) return null;
already_found.* = true;
result = cfe;
continue;
} }
if (already_found.*) return null;
already_found.* = true;
result = cfe;
continue;
}, },
else => {}, else => {},
} }
@ -262,16 +262,12 @@ fn resolveReturnType(
// If this is a type function and it only contains a single return statement that returns // If this is a type function and it only contains a single return statement that returns
// a container declaration, we will return that declaration. // a container declaration, we will return that declaration.
const ret = findReturnStatement(handle.tree, fn_decl) orelse return null; const ret = findReturnStatement(handle.tree, fn_decl) orelse return null;
if (ret.rhs) |rhs| if (ret.rhs) |rhs| {
if (try resolveTypeOfNodeInternal(store, arena, .{ return try resolveTypeOfNodeInternal(store, arena, .{
.node = rhs, .node = rhs,
.handle = handle, .handle = handle,
}, bound_type_params)) |res_rhs| switch (res_rhs.node.id) { }, bound_type_params);
.ContainerDecl => { }
return res_rhs;
},
else => return null,
};
return null; return null;
} }