Skip to content

Parser: a dedent to a level no enclosing block has is accepted, and the line joins the outer block #1781

Closed

Description

@ehartford

Spec

§29.13 (indentation bodies). A dedent must return to an enclosing indentation level; Python reports "unindent does not match any outer indentation level".

Repro

fn main:
    let c = false
    if c:
            let x = 1
        print(f"inner {x}")
    print("end")

The if body takes its indentation (12) from its first line; the next line (8) matches no enclosing level (4 for main's body).

Actual

Base stage1 at 76cf0bf: with run prints inner 1 then end — the print at indentation 8 runs with c false, reading x from an arm that never ran. With batch2-ownership's scoping fix (a one-statement body is its own scope) it becomes undefined variable instead, but the parser still accepts the layout silently.

Expected

A parse error at the inconsistent dedent, naming the line and the levels.

Found

In the compiler itself: MirLower.lower_method_call's static-constructor fallback had its let ret_type = ... indented one level deeper than the four lines after it, so those four lines ran on every method call (fixed on batch2-ownership: "MirLower.lower_method_call: the static-constructor fallback runs only when the receiver type is unknown").

Activity

  1. added 6 commits that reference this issue on Sep 28, 2026
    49bee1d
    9161d09
    0ae7cf9
    3b1fcef
    322867a
    eb343a9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions