Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: mutator/init.lua:557: bad argument #1 to 'next' (table expected, got function) #561

Closed
3 tasks done
stevalkr opened this issue Jan 19, 2025 · 1 comment
Closed
3 tasks done
Labels
bug Something isn't working

Comments

@stevalkr
Copy link
Contributor

Did you check the docs and existing issues?

  • I have read the docs
  • I have searched the existing issues

Neovim version (nvim -v)

NVIM v0.11.0-dev-1417+g487c48ec86-Homebrew Build type: Release LuaJIT 2.1.1736781742 Run "nvim -V1 -v" for more info

Operating system/version

macOS 15.2

Describe the bug

When I was debugging, I encountered this issue.

.../mutator/init.lua:557: bad argument #1 to 'next' (table expected, got function)

---@diagnostic disable-next-line: param-type-mismatch
local bufnr, errs = next(pairs(all_errors))
vim.api.nvim_win_set_buf(0, bufnr)
pcall(vim.api.nvim_win_set_cursor, 0, { errs[1].lnum + 1, errs[1].col })

According to the Lua documentation (https://www.lua.org/pil/7.3.html), the 'pairs' function should return the 'next' argument as the first element, which is actually a function.

The pairs function, which iterates over all elements in a table, is similar, except that the iterator function is the next function, which is a primitive function in Lua:

function pairs (t)
  return next, t, nil
end

What is the severity of this bug?

breaking (some functionality is broken)

Steps To Reproduce

  1. open oil buffer
  2. try create a new file like /abc to trigger an error
  3. leave this directory (to a oil buffer without error)
  4. :w

Expected Behavior

No error

Directory structure

No response

Repro

-- save as repro.lua
-- run with nvim -u repro.lua
-- DO NOT change the paths
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "runtime", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  "folke/tokyonight.nvim",
  {
        "stevearc/oil.nvim",
        config = function()
            require("oil").setup({
              -- add any needed settings here
            })
        end,
  },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

Did you check the bug with a clean config?

  • I have confirmed that the bug reproduces with nvim -u repro.lua using the repro.lua file above.
@stevalkr stevalkr added the bug Something isn't working label Jan 19, 2025
@stevearc
Copy link
Owner

Fixed. Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants