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

unreachable code not detected #137

Open
chqrlie opened this issue Dec 21, 2024 · 1 comment
Open

unreachable code not detected #137

chqrlie opened this issue Dec 21, 2024 · 1 comment
Labels

Comments

@chqrlie
Copy link
Contributor

chqrlie commented Dec 21, 2024

simple cases of unreachable code are not detected:

fn i32 test1(i32 n) {
    switch (n) {
    case 1:
        return 1;
    default:
        return 0;
    }
    return 2;
}

fn i32 test3(i32 n) {
    while (true) {
        return 1;
    }
    return 2;
}

fn i32 test4(i32 n) {
    for (;;) {
        return 1;
    }
    return 2;
}

fn i32 test5(i32 n) {
    while (true) {
    }
    return 2;
}

fn i32 test6(i32 n) {
    for (;;) {
    }
    return 2;
}

fn i32 test7(i32 n) {
    for (;;) {
        switch (n) {
        case 1:
            continue;
        default:
            return 0;
        }
        return 2;
    }
    return 3;
}

fn i32 test8(i32 n) {
    for (;;) {
        switch (n) {
        case 1:
            return 1;
        default:
            return 0;
        }
    }
    return 2;
}

The compiler might also flag endless loops for (;;) {} and while (true) {}

@bvdberg
Copy link
Member

bvdberg commented Dec 21, 2024

Can you create a (failing) unit test for this? than send a pull request for that...

@bvdberg bvdberg added the bug label Dec 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants