Skip to content

Commit c76a245

Browse files
committed
resolve return type of function with invalid parameter
fixes #2298
1 parent 3840469 commit c76a245

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

src/analysis.zig

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,20 +2264,20 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, node_handle: NodeWithHandle) e
22642264
param_name = tree.tokenSlice(name_token);
22652265
}
22662266

2267-
const param_type = blk: {
2268-
if (param.type_expr) |type_expr| {
2267+
const param_type = param_type: {
2268+
if (param.type_expr) |type_expr| blk: {
22692269
const ty = try analyser.resolveTypeOfNode(.of(type_expr, handle)) orelse {
2270-
return null;
2270+
break :blk;
22712271
};
22722272
if (!ty.is_type_val) {
2273-
return null;
2273+
break :blk;
22742274
}
2275-
break :blk ty;
2275+
break :param_type ty;
22762276
}
22772277
if (param.anytype_ellipsis3) |token_index| {
22782278
switch (tree.tokenTag(token_index)) {
22792279
.keyword_anytype => {
2280-
break :blk null;
2280+
break :param_type null;
22812281
},
22822282
.ellipsis3 => {
22832283
has_varargs = true;
@@ -2286,7 +2286,7 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, node_handle: NodeWithHandle) e
22862286
else => unreachable,
22872287
}
22882288
}
2289-
return null;
2289+
break :param_type Type.fromIP(analyser, InternPool.Index.unknown_type, null);
22902290
};
22912291

22922292
try parameters.append(analyser.arena.allocator(), .{

tests/lsp_features/completion.zig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,19 @@ test "function call" {
553553
});
554554
}
555555

556+
test "resolve return type of function with invalid parameter" {
557+
try testCompletion(
558+
\\fn Foo(foo: unknown) type {
559+
\\ _ = foo;
560+
\\ return struct { alpha: u32 };
561+
\\}
562+
\\var foo: Foo() = undefined;
563+
\\const bar = foo.<cursor>
564+
, &.{
565+
.{ .label = "alpha", .kind = .Field, .detail = "u32" },
566+
});
567+
}
568+
556569
test "optional" {
557570
try testCompletion(
558571
\\const foo: ?u32 = undefined;

0 commit comments

Comments
 (0)