Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/analysis.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2264,20 +2264,20 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, node_handle: NodeWithHandle) e
param_name = tree.tokenSlice(name_token);
}

const param_type = blk: {
if (param.type_expr) |type_expr| {
const param_type = param_type: {
if (param.type_expr) |type_expr| blk: {
const ty = try analyser.resolveTypeOfNode(.of(type_expr, handle)) orelse {
return null;
break :blk;
};
if (!ty.is_type_val) {
return null;
break :blk;
}
break :blk ty;
break :param_type ty;
}
if (param.anytype_ellipsis3) |token_index| {
switch (tree.tokenTag(token_index)) {
.keyword_anytype => {
break :blk null;
break :param_type null;
},
.ellipsis3 => {
has_varargs = true;
Expand All @@ -2286,7 +2286,7 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, node_handle: NodeWithHandle) e
else => unreachable,
}
}
return null;
break :param_type Type.fromIP(analyser, InternPool.Index.unknown_type, null);
};

try parameters.append(analyser.arena.allocator(), .{
Expand Down
13 changes: 13 additions & 0 deletions tests/lsp_features/completion.zig
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,19 @@ test "function call" {
});
}

test "resolve return type of function with invalid parameter" {
try testCompletion(
\\fn Foo(foo: unknown) type {
\\ _ = foo;
\\ return struct { alpha: u32 };
\\}
\\var foo: Foo() = undefined;
\\const bar = foo.<cursor>
, &.{
.{ .label = "alpha", .kind = .Field, .detail = "u32" },
});
}

test "optional" {
try testCompletion(
\\const foo: ?u32 = undefined;
Expand Down