Skip to content

Closure that names a global var panics MirLower: "anonymous capture lacks a concrete local type" #1313

Closed

Description

@ehartford

Found while writing the #1296 test (closure body () => g += 10 over a global). Any closure that mentions a global var — read or write — dies in MirBuilder.prepare_anonymous_body (src/MirLower.w ~13013) instead of reading the global directly.

Repro (installed with v0.15.2.1-g478b26481, also on a fresh stage1 from main bbb9c5b):

use std.builtins.print_i32
var g: i32 = 0
fn main:
    let r: fn() -> i32 = () => g + 1
    print_i32(r())
BUG: anonymous capture lacks a concrete local type: node=7474 symbol=747 [src/MirLower.w:13013 MirBuilder.prepare_anonymous_body]

Expected: a global is not a capture (§9.3 closures capture locals; §9.1c/D52 globals are places every function may read and write); the closure reads g and prints 1. Actual: Sema apparently lists the global symbol among the closure's captures, and MirLower finds no local type for it.

Same for () => g += 10 and a block body () => { g = 3 }. A closure over a captured local var n works. Workaround: none inside the closure; pass the value in.

Activity

  1. added 2 commits that reference this issue on Sep 22, 2026
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