Fixed slice access type resolution

This commit is contained in:
Alexandros Naskos 2020-07-23 21:33:43 +03:00
parent 8ddd80b788
commit e7a1f5c34f
2 changed files with 26 additions and 49 deletions

View File

@ -466,46 +466,35 @@ fn resolveBracketAccessType(
else => return null, else => return null,
}; };
if (lhs_node.cast(ast.Node.SimplePrefixOp)) |pop| { if (lhs_node.castTag(.SliceType)) |slice_type| {
switch (lhs_node.tag) { if (rhs == .Single)
.SliceType => { return ((try resolveTypeOfNodeInternal(store, arena, .{
if (rhs == .Single) .node = slice_type.rhs,
return ((try resolveTypeOfNodeInternal(store, arena, .{ .handle = lhs.handle,
.node = pop.rhs, }, bound_type_params)) orelse return null).instanceTypeVal();
.handle = lhs.handle, return lhs;
}, bound_type_params)) orelse return null).instanceTypeVal(); } else if (lhs_node.castTag(.ArrayType)) |array_type| {
return lhs; if (rhs == .Single)
}, return ((try resolveTypeOfNodeInternal(store, arena, .{
.ArrayType => { .node = array_type.rhs,
if (rhs == .Single) .handle = lhs.handle,
return ((try resolveTypeOfNodeInternal(store, arena, .{ }, bound_type_params)) orelse return null).instanceTypeVal();
.node = pop.rhs, return TypeWithHandle{
.handle = lhs.handle, .type = .{ .data = .{ .slice = array_type.rhs }, .is_type_val = false },
}, bound_type_params)) orelse return null).instanceTypeVal(); .handle = lhs.handle,
return TypeWithHandle{ };
.type = .{ .data = .{ .slice = pop.rhs }, .is_type_val = false }, } else if (lhs_node.castTag(.PtrType)) |ptr_type| {
if (ptr_type.rhs.castTag(.ArrayType)) |child_arr| {
if (rhs == .Single) {
return ((try resolveTypeOfNodeInternal(store, arena, .{
.node = child_arr.rhs,
.handle = lhs.handle, .handle = lhs.handle,
}; }, bound_type_params)) orelse return null).instanceTypeVal();
}, }
.PtrType => { return lhs;
if (pop.rhs.cast(ast.Node.SimplePrefixOp)) |child_pop| {
switch (pop.rhs.tag) {
.ArrayType => {
if (rhs == .Single) {
return ((try resolveTypeOfNodeInternal(store, arena, .{
.node = child_pop.rhs,
.handle = lhs.handle,
}, bound_type_params)) orelse return null).instanceTypeVal();
}
return lhs;
},
else => {},
}
}
},
else => {},
} }
} }
return null; return null;
} }

View File

@ -451,18 +451,6 @@ fn nodeToCompletion(
.kind = .Field, .kind = .Field,
}); });
}, },
.ContainerDecl => {
log(std.log.Level.debug, .cont, "Unhandled container decl", .{});
const container = node.castTag(.ContainerDecl).?;
for (container.fieldsAndDecls()) |snode|
if (snode.castTag(.ContainerField)) |field|
try list.append(.{
.label = handle.tree.tokenSlice(field.name_token),
.kind = .Field,
.documentation = doc,
.detail = analysis.getContainerFieldSignature(handle.tree, field),
});
},
else => if (analysis.nodeToString(handle.tree, node)) |string| { else => if (analysis.nodeToString(handle.tree, node)) |string| {
try list.append(.{ try list.append(.{
.label = string, .label = string,