Skip to content

error: unreachable code breaks noreturn case in generic context #3256

@vi

Description

@vi
const assert = @import("std").debug.assert;
const warn = @import("std").debug.warn;

fn v(comptime T:type, vv: fn()T)T {
    const L = struct {
        fn a(vv2:fn()T) T {
            return vv2();
        }

        fn b(vv1:fn()T) T {
            return a(vv1);
        }
    };
    return L.b(vv);
}

fn voidy() void {

}

fn noreturny() noreturn {
    while(true){}
}

test "noreturny?" {
    v(void, voidy);
    v(noreturn, noreturny);
}
/tmp/emb/test.zig:14:5: error: unreachable code
    return L.b(vv);

"unreachable code" in general looks like a lint aiming for clean code, not a hard error preventing compilation.

There should be either

  • Ignoring code being unreachable only because of noreturn coming from generic T
  • Explicit suppressing of unreachable code check.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions