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
10 changes: 3 additions & 7 deletions src/analysis.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5869,13 +5869,9 @@ pub fn lookupSymbolFieldInit(
else => false,
};

while (true) {
const unwrapped =
try analyser.resolveUnwrapErrorUnionType(container_type, .payload) orelse
try analyser.resolveOptionalUnwrap(container_type) orelse
break;
container_type = unwrapped;
}
container_type = try container_type
.resolveDeclLiteralResultType()
.instanceTypeVal(analyser) orelse container_type;

if (is_struct_init) {
return try container_type.lookupSymbol(analyser, field_name);
Expand Down
23 changes: 23 additions & 0 deletions tests/lsp_features/definition.zig
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,29 @@ test "decl literal on generic type" {
);
}

test "decl literal pointer" {
try testDefinition(
\\const S = struct {
\\ const value: S = .{};
\\ const <def><decl>ptr</decl></def>: *const S = &value;
\\};
\\test {
\\ const ptr: *const S = .<>ptr;
\\}
);
try testDefinition(
\\const S = struct {
\\ const value: S = .{};
\\ fn <def><decl>pointerFn</decl></def>() *const S {
\\ return &value;
\\ }
\\};
\\test {
\\ const ptr: *const S = .poi<>nterFn();
\\}
);
}

test "capture" {
try testDefinition(
\\test {
Expand Down
38 changes: 38 additions & 0 deletions tests/lsp_features/hover.zig
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,44 @@ test "decl literal function" {
);
}

test "decl literal pointer" {
try testHover(
\\const S = struct {
\\ const value: S = .{};
\\ const ptr: *const S = &value;
\\};
\\const s: *const S = .pt<cursor>r;
,
\\```zig
\\const ptr: *const S = &value
\\```
\\```zig
\\(*const S)
\\```
\\
\\Go to [S](untitled:///Untitled-0.zig#L1)
);

try testHover(
\\const S = struct {
\\ const value: S = .{};
\\ fn pointerFn() *const S {
\\ return &value;
\\ }
\\};
\\const s: *const S = .poi<cursor>nterFn();
,
\\```zig
\\fn pointerFn() *const S
\\```
\\```zig
\\(fn () *const S)
\\```
\\
\\Go to [S](untitled:///Untitled-0.zig#L1)
);
}

test "decl literal on generic type" {
try testHover(
\\fn Box(comptime T: type) type {
Expand Down