Skip to content

Recursive closures not being picked up properly #977

Closed

Description

@dquixote-jr

Problem

Closures defined recursively show up as not defined.

PoC - test.lua:

local fact = function(n)
  if n == 0 then
    return 1
  end
  return n * fact(n - 1)
end

return fact

.emmyrc.json:

{
  "format": {
    "externalTool": {
      "program": "stylua",
      "args": ["-", "--stdin-filepath", "${file}"]
    }
  },
  "runtime": {
    "version": "LuaJIT"
  },
  "diagnostics": {
    "globals": ["ngx"],
    "disable": ["unnecessary-if", "invert-if"],
    "enables": [
      "incomplete-signature-doc",
      "missing-global-doc"
    ]
  }
}

Command:

$ emmylua_check -c "$(pwd)/.emmyrc.json" --warnings-as-errors -- --path test.lua
--- /Users/atammy/GIT/kong-plugins/test.lua [1 error]
error: undefined global variable: fact [undefined-global]
  -->: /Users/atammy/GIT/kong-plugins/test.lua:5:14

  4 │   end
  5 │   return n * fact(n - 1)
  6 │ end



Summary
  1 error

Check failed
Error: "exit code: 1"

Acceptance criteria

The above code passes the code checks.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions