Skip to content

Commit

Permalink
resolve type of comparison op to @vector(N, bool) if lhs is a vector (#…
Browse files Browse the repository at this point in the history
…1982)

Co-authored-by: Techatrix <techatrix@mailbox.org>
  • Loading branch information
janis-bhm and Techatrix committed Aug 5, 2024
1 parent dfe958e commit f2f5339
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/analysis.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2071,6 +2071,28 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, node_handle: NodeWithHandle) e
.greater_than,
.less_or_equal,
.greater_or_equal,
=> {
const ty = try analyser.resolveTypeOfNodeInternal(
.{ .node = datas[node].lhs, .handle = handle },
) orelse return try Type.typeValFromIP(analyser, .bool_type);
const typeof = ty.typeOf(analyser);

if (typeof.data == .ip_index) {
const key = analyser.ip.indexToKey(typeof.data.ip_index.index);
if (key == .vector_type) {
const vector_ty_ip_index = try analyser.ip.get(analyser.gpa, .{
.vector_type = .{
.len = key.vector_type.len,
.child = .bool_type,
},
});

return try Type.typeValFromIP(analyser, vector_ty_ip_index);
}
}
return try Type.typeValFromIP(analyser, .bool_type);
},

.bool_and,
.bool_or,
.bool_not,
Expand Down
4 changes: 4 additions & 0 deletions tests/lsp_features/inlay_hints.zig
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ test "inlay destructuring" {
, .{ .kind = .Type });
}
test "var decl" {
try testInlayHints(
\\const a<@Vector(2,u8)> = @Vector(2, u8){1,2};
\\const foo<@Vector(2,bool)> = a == a;
, .{ .kind = .Type });
try testInlayHints(
\\const foo<comptime_int> = 5;
, .{ .kind = .Type });
Expand Down

0 comments on commit f2f5339

Please sign in to comment.