We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
0.11.0-dev.4002+7dd1cf26f
8da21e1
Paste this code into an editor with zls running as lsp. Send a textDocument/hover request of variable c.
pub fn opt_test(a: ?i32, b: ?i32) void { const c = a orelse b; std.debug.print("{s}\n", .{@typeName(@TypeOf(c))}); }
Running this code snippet prints ?i32 as type of c.
const std = @import("std"); pub fn main() !void { const a = null; const b = null; opt_test(a, b); } pub fn opt_test(a: ?i32, b: ?i32) void { const c = a orelse b; std.debug.print("{s}\n", .{@typeName(@TypeOf(c))}); }
Type of c being ?i32 .
zls reports the type of c being i32.
I took a stab at trying to come up with a fix by replacing this switch case with the one below:
.@"orelse" => orelse_type: { const base_right = .{ .node = datas[node].rhs, .handle = handle }; const base_type_right = (try analyser.resolveTypeOfNodeInternal(base_right)); if (base_type_right) |type_right| { const ok = switch (type_right.type.data) { .other => |node_type| switch (node_tags[node_type]) { .optional_type => true, else => false, }, else => false, }; if (ok) { break :orelse_type base_type; } } break :orelse_type try analyser.resolveUnwrapOptionalType(base_type); },
This worked for the example above, but when trying to open hover.zig with this change zls crashes.
The text was updated successfully, but these errors were encountered:
Fix wrong type of orelse expression
a4c1c23
Fixes zigtools#1330
orelse
Successfully merging a pull request may close this issue.
Zig Version
0.11.0-dev.4002+7dd1cf26f
Zig Language Server Version
8da21e1
Steps to Reproduce
Paste this code into an editor with zls running as lsp.
Send a textDocument/hover request of variable c.
Running this code snippet prints ?i32 as type of c.
Expected Behavior
Type of c being ?i32 .
Actual Behavior
zls reports the type of c being i32.
I took a stab at trying to come up with a fix by replacing this switch case with the one below:
This worked for the example above, but when trying to open hover.zig with this change zls crashes.
The text was updated successfully, but these errors were encountered: