From 55b1aeb6f7324264c9c1616f3ae3565402ffdf34 Mon Sep 17 00:00:00 2001 From: nullptrdevs <16590917+nullptrdevs@users.noreply.github.com> Date: Wed, 5 Apr 2023 07:28:21 -0700 Subject: [PATCH] Avoid accessing inactive union fields in `completeDot` (#1115) As reported on Discord by CodotakuYT: ```zig fn populate(T: type, index: i32) T { _ = index; @typeInfo(T).struct. } ``` ``` thread 17384 panic: access of union field 'ast_node' while field 'param_payload' is active C:\Users\taoua\zls\src\features\completions.zig:875:61: 0x7ff68070caac in completeDot (zls.exe.obj) const node_data = nodes_data[local_decl.decl.ast_node]; ``` --- src/features/completions.zig | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/features/completions.zig b/src/features/completions.zig index d8a5e81..5958521 100644 --- a/src/features/completions.zig +++ b/src/features/completions.zig @@ -872,6 +872,10 @@ fn completeDot(server: *Server, handle: *const DocumentStore.Handle, source_inde if (maybe_decl) |local_decl| { const nodes_tags = handle.tree.nodes.items(.tag); const nodes_data = handle.tree.nodes.items(.data); + switch (local_decl.decl.*) { + .ast_node => {}, + else => break :struct_init, + } const node_data = nodes_data[local_decl.decl.ast_node]; if (node_data.rhs != 0) { switch (nodes_tags[node_data.rhs]) {