Skip to content

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

@Hejsil

Description

@Hejsil

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions