Skip to content

Confusing diagnostic when local type transitively captures local var #86200

@hamishknight

Description

@hamishknight

The following gives a confusing diagnostic:

func foo() {
  var x = 0
  func bar() { // error: closure captures 'x' before it is declared
    _ = x
  }
  struct S {
    func baz() {
      bar()
    }
  }
}

The actual issue is that baz is calling bar, and as such bar can't capture local vars.

Metadata

Metadata

Assignees

No one assigned

    Labels

    SILGenArea → compiler: The SIL generation stagebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of Implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions