Skip to content
New issue

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

No inlay hints for struct_init* fields following a return and the fn's return type is an optional #1990

Open
llogick opened this issue Aug 5, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@llogick
Copy link
Contributor

llogick commented Aug 5, 2024

Zig Version

Zig Language Server Version

dfe958e

Client / Code Editor / Extensions

Steps to Reproduce and Observed Behavior

Can be observed for any fn f() ?T in the codebase that return .{.x ..,
but not for fn that have an explicit error(set), ie fn f() error{E}!?T works.

const T = union(enum) { a: u1 };
fn foo() ?T {
    return .{ .a = 1 };
}

Same even if the type is explicitly specified,

const T = union(enum) { a: u1 };
fn foo() ?T {
    return T{ .a = 1 };
}

Cause:

zls/src/analysis.zig

Lines 4494 to 4498 in dfe958e

if (try analyser.resolveUnwrapErrorUnionType(container_type, .payload)) |unwrapped|
container_type = unwrapped;
if (try analyser.resolveOptionalUnwrap(container_type)) |unwrapped|
container_type = unwrapped;

resolveOptionalUnwrap doesn't do type_vals
E!?T works because resolveUnwrapErrorUnionType returns an 'instance' of ?T

Expected Behavior

Relevant log output

No response

@llogick llogick added the bug Something isn't working label Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant