Skip to content

Commit fb9843a

Browse files
Fix resolved type of type function with unknown return type
1 parent d455609 commit fb9843a

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

src/analysis.zig

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -858,16 +858,17 @@ fn resolveReturnValueOfFuncNode(
858858
const fn_proto = tree.fullFnProto(&buf, func_node).?;
859859
const has_body = tree.nodeTag(func_node) == .fn_decl;
860860

861-
if (isTypeFunction(tree, fn_proto) and has_body) {
861+
if (isTypeFunction(tree, fn_proto)) {
862+
if (!has_body) return .unknown_type;
862863
const body = tree.nodeData(func_node).node_and_node[1];
863864
// If this is a type function and it only contains a single return statement that returns
864865
// a container declaration, we will return that declaration.
865-
const return_node = findReturnStatement(tree, body) orelse return null;
866+
const return_node = findReturnStatement(tree, body) orelse return .unknown_type;
866867
if (tree.nodeData(return_node).opt_node.unwrap()) |return_expr| {
867-
return try analyser.resolveTypeOfNodeInternal(.of(return_expr, handle));
868+
return try analyser.resolveTypeOfNodeInternal(.of(return_expr, handle)) orelse .unknown_type;
868869
}
869870

870-
return null;
871+
return .unknown_type;
871872
}
872873

873874
const return_type = fn_proto.ast.return_type.unwrap() orelse return null;
@@ -2430,7 +2431,7 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, options: ResolveOptions) Error
24302431
else => unreachable,
24312432
}
24322433
}
2433-
break :param_type Type.fromIP(analyser, .type_type, .unknown_type);
2434+
break :param_type .unknown_type;
24342435
};
24352436

24362437
try parameters.append(analyser.arena, .{

tests/analysis/function.zig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,11 @@ fn func() addrspace(.generic) linksection(.{}) callconv(.auto) void {}
22
// ^^^^^^^^ (AddressSpace)()
33
// ^ ([]const u8)()
44
// ^^^^^ (void)()
5+
6+
// zig fmt: off
7+
fn Unknown() type { return undefined.Unknown; }
8+
// ^^^^^^^ (fn () type)()
9+
// zig fmt: on
10+
11+
const UnknownCall = Unknown();
12+
// ^^^^^^^^^^^ (type)((unknown type))

0 commit comments

Comments
 (0)