Skip to content

Upstream candidate: if not t.x then return end does not narrow t.x on main (fork and 0.25.1 do) #42

Closed

Description

@mareklangiewicz

Part of #14. Found while tracing upstream 1360's corpus additions (diffs.nvim lua/diffs/review.lua:559).

Repro (runs as written)

.emmyrc.json = {}, then emmylua_check .:

---@class Norm
---@field target string?

---@param s string
local function take(s) return s end

---@param n Norm
local function early_return(n)
  if not n.target then
    return
  end
  take(n.target) -- line 12
end

---@param n Norm
local function positive(n)
  if n.target then
    take(n.target)
  end
end

---@param n Norm
local function early_return_value(n)
  if not n.target then
    return 1
  end
  take(n.target) -- line 27
  return 2
end

---@param n Norm
local function eq_nil(n)
  if n.target == nil then
    return
  end
  take(n.target)
end

---@param n Norm
local function via_local(n)
  local t = n.target
  if not t then
    return
  end
  take(t)
end
return early_return, positive, early_return_value, eq_nil, via_local
build param-type-mismatch ("expected string but found string?")
0.25.1 none
upstream main 4136671 and 2c400ee lines 12 and 27
fork (installed, 0.30.0-main-14c7537a) none

Only the negated member test followed by an early exit fails. A positive test, == nil, and the same test on a local all narrow.

Correction to my #14 comment of 2026-11-17: I described this there as "a member guard doesn't hold when the receiver is a local narrowed from Norm?". The receiver's narrowing doesn't matter: a plain ---@param n Norm fails the same way.

Next

Activity

  1. added
    bug
    needs-triage
    on Nov 17, 2026
  2. mareklangiewicz commented on Nov 17, 2026

    @mareklangiewicz
    OwnerAuthor

    Fixed upstream by fcc0416 "fix(flow): narrow members" (xuhuanzy, 2026-11-18)

    I re-ran the repro above as written, plus a control take(n.target) with no guard (line 50), using gndx emmylua probe with .emmyrc.json = {}:

    hit 0.25.1 upstream fcc0416 fork 50b2155 main 4136671
    12 param-type-mismatch ✓
    27 param-type-mismatch ✓
    50 param-type-mismatch (control) ✓ ✓ ✓ ✓

    Upstream main now narrows if not n.target then return end, and the control still reports, so the check is live. Nothing to port. I suggest closing this as fixed upstream once the next gndx emmylua sync merges fcc0416 (at that merge, check that the fork's narrowing and upstream's new flow.rs don't conflict).

  3. mareklangiewicz commented on Nov 18, 2026

    @mareklangiewicz
    OwnerAuthor

    Merged upstream fcc0416 into the fork as 8581c78 (local, not pushed yet). The fork keeps its own flow.rs, which already narrowed this case. Upstream's new tests for the same area (test_not_member_true_branch_narrows_to_nil and the rest of fcc0416's need_check_nil tests) pass on the merge, after porting fcc0416's falsy branch for if not t.x then. Nothing is left to port upstream for this issue.

  4. mareklangiewicz commented on Nov 20, 2026

    @mareklangiewicz
    OwnerAuthor

    Gone upstream; closing. I re-ran the repro above as written (gndx emmylua probe, empty config) on 2026-11-20:

    build param-type-mismatch lines 12, 27
    0.25.1 none
    upstream main 70dbcf4 none
    fork 0.30.0-main-c60fdcd9 none

    Upstream fixed it somewhere between 2c400ee and 70dbcf4, and the fork has merged that range (7d6084b). There's nothing to port, so I didn't look for the fork commit that avoided it. The flow.md placement is updated in 4912ed4.

  5. added a commit that references this issue on Nov 20, 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

    bugneeds-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions