Skip to content

Commit

Permalink
infer orelse on a C-pointer as a C-pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanderc authored and Techatrix committed Feb 8, 2025
1 parent c8bd727 commit b733071
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/analysis.zig
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,10 @@ pub fn resolveOptionalUnwrap(analyser: *Analyser, optional: Type) error{OutOfMem
std.debug.assert(child_ty.is_type_val);
return try child_ty.instanceTypeVal(analyser);
},
.pointer => |ptr| {
if (ptr.size == .c) return optional;
return null;
},
else => return null,
}
}
Expand Down
13 changes: 13 additions & 0 deletions tests/lsp_features/hover.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,19 @@ test "optional" {
\\(i32)
\\```
);

try testHover(
\\var value: u32 = 123;
\\const ptr: [*c]u32 = &value;
\\const f<cursor>oo = ptr orelse unreachable;
,
\\```zig
\\const foo = ptr orelse unreachable
\\```
\\```zig
\\([*c]u32)
\\```
);
}

test "error union" {
Expand Down

0 comments on commit b733071

Please sign in to comment.