Skip to content

Commit

Permalink
fix address of analysis on primitive value
Browse files Browse the repository at this point in the history
fixes #1709
  • Loading branch information
Techatrix committed Jan 13, 2024
1 parent abe83cf commit f5eecf1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/analysis.zig
Original file line number Diff line number Diff line change
Expand Up @@ -677,11 +677,8 @@ pub fn resolveOptionalChildType(analyser: *Analyser, optional_type: Type) error{
}

pub fn resolveAddressOf(analyser: *Analyser, ty: Type) error{OutOfMemory}!?Type {
if (ty.is_type_val) return null;

const base_type_ptr = try analyser.arena.allocator().create(Type);

base_type_ptr.* = Type{ .data = ty.data, .is_type_val = true };
base_type_ptr.* = ty.typeOf(analyser);
return Type{ .data = .{ .pointer = .{ .size = .One, .is_const = false, .elem_ty = base_type_ptr } }, .is_type_val = false };
}

Expand Down
21 changes: 21 additions & 0 deletions tests/lsp_features/completion.zig
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,27 @@ test "completion - pointer" {
});
}

test "completion - address of" {
try testCompletion(
\\const value: u32 = undefined;
\\const value_ptr = &value;
\\const foo = value_ptr.<cursor>;
, &.{
// TODO detail should be 'u32'
.{ .label = "*", .kind = .Operator },
});
try testCompletion(
\\const S = struct { alpha: u32 };
\\const value: S = undefined;
\\const value_ptr = &value;
\\const foo = value_ptr.<cursor>;
, &.{
// TODO detail should be 'S'
.{ .label = "*", .kind = .Operator },
.{ .label = "alpha", .kind = .Field, .detail = "alpha: u32" },
});
}

test "completion - captures" {
try testCompletion(
\\const S = struct { alpha: u32 };
Expand Down

0 comments on commit f5eecf1

Please sign in to comment.