ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.58k stars 2.53k forks source link

Multi return statement on a single line doesn't cause a compilation error #21787

Open eddineimad0 opened 3 hours ago

eddineimad0 commented 3 hours ago

Zig Version

0.13.0

Steps to Reproduce and Observed Behavior

The following function exhibits the bug.

    pub inline fn bytesPerChannel(self:*const Image)usize{
        return ((return self.chan_bit_depth - 1) >> 3) + 1;
    }

only the inner return statement is evaluated and the outter one is ignored and unreachable, yet zig compiler doesn't throw any errors.

Expected Behavior

The compiler should throw an error upon encountering unreachable return statements same way the following code does

    pub inline fn bytesPerChannel(self:*const Image)usize{
        return ((self.chan_bit_depth - 1) >> 3) + 1;
        return 0;
    }
wooster0 commented 3 hours ago

Might be a duplicate of #11686