E3027

E3027 — A function whose return type is a closure. A closure value points into the frame that made it, so it cannot outlive that frame yet.

What the compiler reports

E3027{{.*}}function 'make' returns a closure

The fragments the test suite holds the compiler to. An ellipsis marks text the test does not constrain; the emitted message also carries a source location.

A program that triggers it

//
// A closure value points into the frame that made it. Passing one down is fine, the frame is
// alive; returning one, so that it outlives its frame, is refused until a closure can own its
// environment.

fn make() -> ||->i32 {
  let n = 42;
  let c = || n;
  return c as ||->i32;
}

fn main() -> i32 {
  return 0;
}

From tests/frontend/fail/returning_a_closure.vx, which asserts this diagnostic on every commit.

Related