Skip to content

Stage2 orelse type inference incorrect #12537

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

Closed
Sirius902 opened this issue Aug 20, 2022 · 3 comments
Closed

Stage2 orelse type inference incorrect #12537

Sirius902 opened this issue Aug 20, 2022 · 3 comments
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@Sirius902
Copy link

Sirius902 commented Aug 20, 2022

Zig Version

0.10.0-dev.3659+e5e6eb983

Steps to Reproduce

Compile the following zig program.

pub fn main() void {
    const foo: [*c]const u8 = "hey";
    const d = foo orelse return;
    @compileLog(@TypeOf(d));
}

Expected Behavior

I expect the output of this compile log statement to indicate that the type of d is [*c]const u8, the same as foo.
After discussion it would seem [*]const u8 would be a more reasonable type for d.

Actual Behavior

On stage1 the compiler outputs the type [*c]const u8 in the compiler log output, however stage2 reports the type of d to be *const allowzero u8.

@Sirius902 Sirius902 added the bug Observed behavior contradicts documented or intended behavior label Aug 20, 2022
@nektro
Copy link
Contributor

nektro commented Aug 21, 2022

type should prolly be [*]const u8 but stage2 is the more correct one here

@Vexu Vexu added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Aug 21, 2022
@Vexu Vexu added this to the 0.10.0 milestone Aug 21, 2022
@Sirius902
Copy link
Author

@nektro Right, I think [*]const u8 would make more sense here. The main issue with stage2's current approach is that a multi pointer is becoming a single pointer, making d pretty much unusable.

@Sirius902 Sirius902 changed the title Stage3 orelse type inference incorrect Stage2 orelse type inference incorrect Aug 21, 2022
@Vexu
Copy link
Member

Vexu commented Aug 21, 2022

Related #6597

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

3 participants