Skip to content

Add an infinite-loop construct #1906

@catamorphism

Description

@catamorphism

This idea has come up before, but #1905 reminded me that we never really reached agreement on it. I propose adding a new looping construct, forever [block], that has the same semantics as while (true) [block]. The reason to add a special construct would be to allow typestate to recognize that infinite loops run forever, and not yield spurious-looking errors (see #1905 for an example) about functions not returning a value. The current workaround is to do while (true) { ... }; fail "Unreachable";, which isn't terribly burdensome, but is annoying.

I realize we're trying not to add stuff, but this issue seems to be a source of confusion, and while (true) loops seem to be pretty common.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions