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

stage2: Inferring the type of chained ifs differ in behavior between stage1 and 2 #11969

Open
Hejsil opened this issue Jun 30, 2022 · 0 comments
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@Hejsil
Copy link
Contributor

Hejsil commented Jun 30, 2022

Zig Version

0.10.0-dev.2803+c248af3bd

Steps to Reproduce

// test.zig
const std = @import("std");

const testing = std.testing;

test {
    var a = false;
    var b = false;
    const name = if (a)
        "ab"
    else if (b)
        return error.TestFailed
    else
        null;
    try testing.expect(name == null);
}
$ stage1/zig test test.zig
$ stage2/zig test test.zig

Expected Behavior

I would expect the stage2 compiler to figure this out in the same way, stage1 does.

Actual Behavior

$ stage2/zig test test.zig
test.zig:10:10: error: value with comptime only type '@TypeOf(null)' depends on runtime control flow
    else if (b)
         ^
test.zig:10:14: note: runtime control flow here
    else if (b)
@Hejsil Hejsil added the bug Observed behavior contradicts documented or intended behavior label Jun 30, 2022
@Vexu Vexu added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Jun 30, 2022
@Vexu Vexu added this to the 0.10.0 milestone Jun 30, 2022
@andrewrk andrewrk modified the milestones: 0.10.0, 0.10.1 Oct 12, 2022
@andrewrk andrewrk modified the milestones: 0.10.1, 0.11.0 Jan 10, 2023
@andrewrk andrewrk modified the milestones: 0.11.0, 0.11.1 Jul 20, 2023
@andrewrk andrewrk modified the milestones: 0.11.1, 0.12.0, 0.13.0 Jan 29, 2024
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