Skip to content

Loop IR node should have content-dependent type #88

@stephanemagnenat

Description

@stephanemagnenat

Currently loops are typed as (), which is incorrect. For example, even with no break-returning value statement, a loop should have type never if there is no break, or () if there is at least one break in it. Later, when break can return values, then the type of that value should be used.

One clean way to do that is to add loop information in the typing context, using a LoopFrame:

struct LoopFrame {
    result_ty: TypeVar,   // the α for this loop
    saw_break: bool,      // whether any break occurred
    label: Option<Name>,  // if labeled breaks are supported
}

This would also allow nicely the detection of breaks outside loops.

Metadata

Metadata

Assignees

No one assigned

    Labels

    typeThe HM(X) type system, excluding the trait part

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions