Skip to content

Upstream PR candidate: bare ? type literal lowers to nil (LuaLS T|?), fork 14c7537a #37

Closed

Description

@mareklangiewicz

Part of #14. The fix is #12 (closed, with the full measurements); this issue tracks only whether and how it goes upstream.

Why it's a candidate

It's upstream's own regression: 0.25.1 lowered a bare ? literal to nil, and upstream 3474c99 ("refactor project") lost that arm. Every ---@field x T|? then reads as required. The fork fix is one arm in semantic_db/query.rs, plus deleting the fork-only text check in sub_type_call (42537ac).

Before a draft (AGENTS.md "Porting a fork fix upstream")

  • Branch off upstream main in a scratch worktree. Cherry-pick only the query.rs arm and the test. sub_type_call is fork-only (42537ac), so check what upstream main has in its place.
  • The test (test_union_with_bare_question_is_optional) fails on main's source and passes with the arm.
  • Corpus diff with upstream main as the base (fork numbers don't carry over), with --against a same-day 0.25.1 run.
  • gndx emmylua lint on the branch.
  • Duplicate search on upstream issues/PRs (T|?, |?, missing-fields optional).

Opening the draft (gh pr create --draft) is Marek's call.

Activity

  1. added
    ready-for-agent
    and removed
    needs-triage
    on Nov 17, 2026
  2. mareklangiewicz commented on Nov 17, 2026

    @mareklangiewicz
    OwnerAuthor

    Upstream branch prepared (2026-11-17), every checklist item done

    Branch fix-bare-question-optional, worktree ~/code/rust/emmylua-analyzer-rust-worktrees/bareq, one commit 52142e59 on upstream main 41366714. Local only, not pushed; tracking is unset so it can't push to upstream by accident. Contents: the query.rs arm plus test_union_with_bare_question_is_optional. The commit message mentions no fork issues.

    sub_type_call: upstream main has no L - R lowering at all (42537ac is fork-only, and LuaTypeBinaryOperator::Sub appears only in the parser). So the port needs no doc_types.rs change and T -? isn't involved. The earlier unverified belief is now checked.

    Red/green: the test fails on main's source (integer|?: [MissingFields] "Missing required fields: x") and passes with the arm, run alone, 1 test. Full emmylua_code_analysis: 1911 passed. gndx emmylua lint passes, recorded on the commit.

    Corpus: corpus diff up-41366714-1117 bareq-52142e59-1117 --against v0251-1117 → totals 58021 → 57890, 294 changed lines: 215 agree, 79 fork-only, 0 uncompared. The diff prints NOT COMPARABLE because 5 trees are refused, all the same on both sides: upstream main crashes on async.nvim, neotest, neovim-runtime and tuis.nvim in both builds, and mason.nvim is the excluded blowup.

    The 79 fork-only lines: 77 are in obsidian.nvim, which spells optionals T|? throughout (442 annotation lines); the other two are diffview config.lua:338 and nui tree/init.lua:239. 55 of the 79 don't appear in the fork's #12 diff. Verified as a whole: I respelled every annotation |? in a copy of obsidian.nvim as |nil. Upstream main without the arm on that copy gives the same 1053 hits as the branch on the original (0 differing lines). Control: main on the original gives 1184. So on obsidian.nvim the arm is exactly upstream's own T|nil behaviour, and the new hits are existing upstream T|nil checks that the old unknown was hiding.

    Example of what it uncovers, and a possible separate finding. This fires on upstream main (4136671 and 2c400ee) with the field spelled string|nil, with or without the arm. It's clean on the fork (14c7537) and on 0.25.1:

    ---@class Opts
    ---@field title string|nil
    
    ---@param a string?
    local function f3(a) return a end
    
    ---@param opts Opts|nil
    local function g(opts)
      opts = opts or {}
      f3(opts.title) -- upstream main: param-type-mismatch "expected `string?` but found `nil`"
    end
    return g

    Ran with emmylua_check . and .emmyrc.json = {}. An upstream reviewer running the PR on T|? code will see these new hits. The PR body should explain them as "T|? now equals T|nil" so they don't read as regressions.

    Opening the draft is Marek's call.

  3. mareklangiewicz commented on Nov 17, 2026

    @mareklangiewicz
    OwnerAuthor

    Opened as upstream EmmyLuaLs#1421 (draft), 2026-11-17, from marek/fix-bare-question-optional @ 52142e5. The body has the before/after test, the corpus numbers and the |? → |nil equivalence. No fork issue numbers in it. Marking it ready is Marek's call. Row added to #14. Leaving this open until upstream merges or closes it.

  4. mareklangiewicz commented on Nov 17, 2026

    @mareklangiewicz
    OwnerAuthor

    Upstream closed 1421 (2026-11-17, "Should have been fixed"): re-measured on upstream main fcc0416 (2026-11-18)

    Upstream reworked semantic_db/query.rs itself between 4136671 and fcc0416 (76c776b, b38ed6f "preserve nil for optional fields in member type queries", 991b3eb, 2985e88), so 1421's arm no longer applies there. Upstream main has no Question → nil mapping. The only Question arms left (facts.rs:730, flow/stats.rs:195) map it to None.

    gndx emmylua probe with .emmyrc.json = {} (bin1 = old main 4136671):

    ---@class A
    ---@field x integer|?
    ---@field y integer|?|nil
    ---@field z integer?|?
    ---@type A
    local a = {}                 -- line 7
    
    ---@param n integer|?
    local function f(n) return n end
    f()                          -- line 11

    plus controls ---@field w integer (line 16) and ---@param m integer (line 20).

    hit 0.25.1 upstream fcc0416 fork 50b2155 main 4136671
    7 missing-fields x ✓
    11 missing-parameter (integer|? param) ✓ ✓
    16 missing-fields w (control) ✓ ✓ ✓ ✓
    20 missing-parameter m (control) ✓ ✓ ✓ ✓
    • Fields: fixed upstream. integer|? fields are optional again on fcc0416.
    • Params: still broken upstream. ---@param n integer|? is still a required parameter on fcc0416, while 0.25.1 and the fork treat it as optional. This is the case 06fc02b added to 1421. The maintainer's "should have been fixed" covers the field half only.

    Next is Marek's call: tell upstream about the param half (a reply on 1421 or a new issue with the 7-line repro above), or leave it. The fork's arm stays either way until a merge brings in the reworked query.rs.

  5. mareklangiewicz commented on Nov 17, 2026

    @mareklangiewicz
    OwnerAuthor

    Posted the @param half upstream as plain-text "upstream EmmyLuaLs#1425" (2026-11-18): repro, four-build table, cause (bare ? still hits _ => TypeShell::unknown() in query.rs on fcc0416), and verified that 1421's arm cherry-picked onto fcc0416 (build ref-994ddc30) fixes it. Offered to reopen 1421 or open a fresh PR. Waiting on upstream.

  6. mareklangiewicz commented on Nov 20, 2026

    @mareklangiewicz
    OwnerAuthor

    Re-measured on upstream main 70dbcf4 (2026-11-20); branch rebased, local only

    upstream EmmyLuaLs#1425 has no reply yet. The @param half is still broken on 70dbcf4 (gndx emmylua probe, {} config):

    hit 0.25.1 upstream 70dbcf4 fork c60fdcd branch 83559d96
    f() with ---@param n integer|?: missing-parameter ✓
    controls (w field, m param) ✓ ✓ ✓ ✓

    Branch fix-bare-question-optional in worktree bareq, rebased cleanly onto 70dbcf4: 468d38ca (the query.rs arm) + 83559d96 (tests). It is not pushed, so marek/fix-bare-question-optional still points at 06fc02b.

    • Red/green (gndx emmylua test bareq --filter=… --red-revert=468d38ca): test_param_union_with_bare_question_is_optional fails with the arm reverted and passes with it. test_union_with_bare_question_is_optional (fields) passes either way, since upstream fixed the field half. It stays as a guard. Full suite: 1983 passed. Lint passes.
    • Corpus corpus diff up-70dbcf4d-1120 bareq-83559d96-1120 --against v0251-1120: 57387 → 57276, 257 changed lines, 186 agree with 0.25.1, 71 differ (65 in obsidian.nvim). "NOT COMPARABLE" only because the same trees are refused on both sides (crashes on upstream: async.nvim, bufferline.nvim, neotest, neovim-runtime, tuis.nvim; mason.nvim excluded).
    • Lowering control: obsidian.nvim copied with every annotation |? respelled |nil. Upstream on the copy gives 1027, the branch on the original gives 1027, and upstream on the original (control) gives 1137. On obsidian the arm is exactly upstream's own T|nil behaviour.

    Next is Marek's call: push the rebased branch and reopen 1421 or open a fresh draft PR, or keep waiting on EmmyLuaLs#1425.

  7. mareklangiewicz commented on Nov 20, 2026

    @mareklangiewicz
    OwnerAuthor

    Upstream 1421 can't be reopened by its author (a maintainer closed it), so the param half went up as a fresh draft: upstream EmmyLuaLs#1445 (2026-11-20), from marek/fix-bare-question-optional. The branch was force-pushed with two commits on 70dbcf4: 5aa3687 (the arm + test_param_union_with_bare_question_is_optional, red → green with --red-revert=5aa36874) and 0e3703e (field spellings as guard tests). The code comment no longer mentions T -?, which upstream doesn't lower. The body has the 70dbcf4 corpus numbers and the obsidian control from the comment above, and it links upstream EmmyLuaLs#1425 and 1421. Marking it ready is Marek's call. Row updated in #14.

  8. mareklangiewicz commented on Nov 20, 2026

    @mareklangiewicz
    OwnerAuthor

    Upstream PR 1445 marked ready for review 2026-11-20 (all CI green; the bot review was answered in 8e4f67e).

  9. mareklangiewicz commented on Nov 23, 2026

    @mareklangiewicz
    OwnerAuthor

    Upstream 1445 merged 2026-11-23 (upstream commit 53c20d3, merged by CppCXY): bare ? lowers to nil upstream, so ---@param n integer|? is optional (upstream issue 1425). The fork's own version (14c7537) meets upstream's 5aa3687 on the next gndx emmylua sync.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

ready-for-agent

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions