Skip to content

Commit

Permalink
Resolve orelse if rhs could not be analyzed
Browse files Browse the repository at this point in the history
  • Loading branch information
7phs authored and llogick committed Nov 17, 2024
1 parent 78b4051 commit 3bb4ae7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/analysis.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1581,7 +1581,7 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, node_handle: NodeWithHandle) e
.unwrap_optional => try analyser.resolveOptionalUnwrap(base_type),
.array_access => try analyser.resolveBracketAccessType(base_type, .Single),
.@"orelse" => {
const type_right = try analyser.resolveTypeOfNodeInternal(.{ .node = datas[node].rhs, .handle = handle }) orelse return null;
const type_right = try analyser.resolveTypeOfNodeInternal(.{ .node = datas[node].rhs, .handle = handle }) orelse return try analyser.resolveOptionalUnwrap(base_type);
return try analyser.resolveOrelseType(base_type, type_right);
},
.@"catch" => try analyser.resolveUnwrapErrorUnionType(base_type, .payload),
Expand Down
18 changes: 18 additions & 0 deletions tests/lsp_features/completion.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2560,6 +2560,24 @@ test "@extern" {
});
}

test "@orelse with block" {
try testCompletion(
\\test {
\\ const S = struct {
\\ alpha: u32,
\\ };
\\ const v: ?*const S = &S{ .alpha = 5 };
\\ const foo = v orelse {
\\ return;
\\ };
\\ foo.<cursor>
\\}
, &.{
.{ .label = "*", .kind = .Operator, .detail = "S" },
.{ .label = "alpha", .kind = .Field, .detail = "u32" },
});
}

test "builtin fns return type" {
try testCompletion(
\\pub const chip_mod = struct {
Expand Down

0 comments on commit 3bb4ae7

Please sign in to comment.