Skip to content

continue control flow in else branch of while applies to wrong loop #12109

@andrewrk

Description

@andrewrk

Zig Version: 0.10.0-dev.2992+1fee9eac8

test "else continue outer while" {
    var i: usize = 0;
    while (true) {
        i += 1;
        while (i > 5) {
            return;
        } else continue;
    }
}

Expected to pass; instead infinitely loops.

This is the root cause of

zig/lib/std/net/test.zig

Lines 106 to 107 in 1fee9ea

test "resolve DNS" {
if (@import("builtin").zig_backend != .stage1) return error.SkipZigTest;

For loops have the same problem:

test "else continue outer for" {
    var i: usize = 6;
    var buf: [5]u8 = undefined;
    while (true) {
        i -= 1;
        for (buf[i..5]) |_| {
            return;
        } else continue;
    }
}

Metadata

Metadata

Assignees

Labels

bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.miscompilationThe compiler reports success but produces semantically incorrect code.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions