Fixed dereference resolution of Type.data.pointer values

This commit is contained in:
Alexandros Naskos 2021-03-30 16:45:49 +03:00
parent f382a1b22d
commit 5a88f26980
No known key found for this signature in database
GPG Key ID: 02BF2E72B0EA32D2
2 changed files with 32 additions and 5 deletions

View File

@ -566,6 +566,13 @@ fn resolveDerefType(
) !?TypeWithHandle {
const deref_node = switch (deref.type.data) {
.other => |n| n,
.pointer => |n| return TypeWithHandle{
.type = .{
.is_type_val = false,
.data = .{ .other = n },
},
.handle = deref.handle,
},
else => return null,
};
const tree = deref.handle.tree;
@ -1242,7 +1249,13 @@ pub fn getFieldAccessType(
.unwrapped = try resolveDerefType(store, arena, current_type, &bound_type_params),
},
.identifier => {
if (try lookupSymbolGlobal(store, arena, current_type.handle, tokenizer.buffer[tok.loc.start..tok.loc.end], source_index)) |child| {
if (try lookupSymbolGlobal(
store,
arena,
current_type.handle,
tokenizer.buffer[tok.loc.start..tok.loc.end],
source_index,
)) |child| {
current_type = (try child.resolveType(store, arena, &bound_type_params)) orelse return null;
} else return null;
},
@ -1278,11 +1291,20 @@ pub fn getFieldAccessType(
tokenizer.buffer[after_period.loc.start..after_period.loc.end],
!current_type.type.is_type_val,
)) |child| {
current_type = (try child.resolveType(store, arena, &bound_type_params)) orelse return null;
current_type = (try child.resolveType(
store,
arena,
&bound_type_params,
)) orelse return null;
} else return null;
},
.question_mark => {
current_type = (try resolveUnwrapOptionalType(store, arena, current_type, &bound_type_params)) orelse return null;
current_type = (try resolveUnwrapOptionalType(
store,
arena,
current_type,
&bound_type_params,
)) orelse return null;
},
else => {
log.debug("Unrecognized token {} after period.", .{after_period.tag});
@ -1291,7 +1313,12 @@ pub fn getFieldAccessType(
}
},
.period_asterisk => {
current_type = (try resolveDerefType(store, arena, current_type, &bound_type_params)) orelse return null;
current_type = (try resolveDerefType(
store,
arena,
current_type,
&bound_type_params,
)) orelse return null;
},
.l_paren => {
const current_type_node = switch (current_type.type.data) {

View File

@ -1141,8 +1141,8 @@ fn completeFieldAccess(
var tokenizer = std.zig.Tokenizer.init(position.line[range.start..range.end]);
if (try analysis.getFieldAccessType(&document_store, arena, handle, position.absolute_index, &tokenizer)) |result| {
try typeToCompletion(arena, &completions, result, handle, config);
truncateCompletions(completions.items, config.max_detail_length);
}
truncateCompletions(completions.items, config.max_detail_length);
try send(arena, types.Response{
.id = id,