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

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

Open
vi opened this issue Sep 19, 2019 · 2 comments
Open

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

vi opened this issue Sep 19, 2019 · 2 comments
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@vi
Copy link

vi commented Sep 19, 2019

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.
@andrewrk andrewrk added this to the 0.6.0 milestone Sep 20, 2019
@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Sep 20, 2019
@vi
Copy link
Author

vi commented Sep 20, 2019

Like #224 , unreachable code error should be degradable to warning both temporarily globally (--sloppy mode) and permanently individually (in this case with no warning).

@andrewrk
Copy link
Member

Related: #2198

@andrewrk andrewrk removed bug Observed behavior contradicts documented or intended behavior stage1 The process of building from source via WebAssembly and the C backend. labels Jan 7, 2020
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Jan 7, 2020
@andrewrk andrewrk added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Jan 7, 2020
@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 27, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 May 19, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 23, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Apr 16, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Apr 9, 2023
@andrewrk andrewrk modified the milestones: 0.13.0, 0.12.0 Jul 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

2 participants