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

script\vm\compiler.lua:2023: attempt to index a nil value #2776

Closed
citRaTTV opened this issue Aug 1, 2024 · 3 comments
Closed

script\vm\compiler.lua:2023: attempt to index a nil value #2776

citRaTTV opened this issue Aug 1, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@citRaTTV
Copy link

citRaTTV commented Aug 1, 2024

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Windows

What is the issue affecting?

Other

Expected Behaviour

No error

Actual Behaviour

Errors are thrown during Diagnose Workspace & while editing files.

Reproduction steps

  1. Open LUA project in VSCode
  2. Wait for workspace diagnostic run
  3. Error pops up during run

Additional Notes

No response

Log File

[17:09:19.163][info] [#0:script\provider\diagnostic.lua:560]: Diagnostics scope [file:///z%3A/projects/fivem-dev], files count:[3121]
[17:09:19.407][error][#0:script\vm\compiler.lua:2023]: script\vm\compiler.lua:2023: attempt to index a nil value
stack traceback:
	script\vm\compiler.lua:2023: in upvalue 'compileByParentNode'
	script\vm\compiler.lua:2052: in function 'vm.vm.compileNode'
	script\vm\function.lua:233: in function 'vm.vm.countReturnsOfSource'
	script\core\diagnostics\missing-return.lua:57: in local 'callback'
	script\parser\guide.lua:756: in function 'parser.guide.eachSourceType'
	script\core\diagnostics\missing-return.lua:51: in function 'core.diagnostics.missing-return'
	script\core\diagnostics\init.lua:119: in upvalue 'check'
	script\core\diagnostics\init.lua:181: in function 'core.diagnostics'
	[C]: in function 'xpcall'
	script\provider\diagnostic.lua:337: in function 'provider.diagnostic.doDiagnostic'
	[C]: in function 'xpcall'
	script\provider\diagnostic.lua:598: in local 'callback'
	script\provider\diagnostic.lua:569: in function 'provider.diagnostic.awaitDiagnosticsScope'
	script\provider\diagnostic.lua:597: in function <script\provider\diagnostic.lua:595>
[17:09:19.412][error][#0:script\vm\compiler.lua:2023]: script\vm\compiler.lua:2023: attempt to index a nil value
stack traceback:
	script\vm\compiler.lua:2023: in upvalue 'compileByParentNode'
	script\vm\compiler.lua:2052: in function 'vm.vm.compileNode'
	script\vm\function.lua:233: in function 'vm.vm.countReturnsOfSource'
	script\core\diagnostics\missing-return.lua:57: in local 'callback'
	script\parser\guide.lua:756: in function 'parser.guide.eachSourceType'
	script\core\diagnostics\missing-return.lua:51: in function 'core.diagnostics.missing-return'
	script\core\diagnostics\init.lua:119: in upvalue 'check'
	script\core\diagnostics\init.lua:181: in function 'core.diagnostics'
	[C]: in function 'xpcall'
	script\provider\diagnostic.lua:337: in function 'provider.diagnostic.doDiagnostic'
	[C]: in function 'xpcall'
	script\provider\diagnostic.lua:598: in local 'callback'
	script\provider\diagnostic.lua:569: in function 'provider.diagnostic.awaitDiagnosticsScope'
	script\provider\diagnostic.lua:597: in function <script\provider\diagnostic.lua:595>
[17:09:19.421][error][#0:script\vm\compiler.lua:2023]: script\vm\compiler.lua:2023: attempt to index a nil value
stack traceback:
	script\vm\compiler.lua:2023: in upvalue 'compileByParentNode'
	script\vm\compiler.lua:2052: in function 'vm.vm.compileNode'
	script\vm\function.lua:233: in function 'vm.vm.countReturnsOfSource'
	script\core\diagnostics\missing-return.lua:57: in local 'callback'
	script\parser\guide.lua:756: in function 'parser.guide.eachSourceType'
	script\core\diagnostics\missing-return.lua:51: in function 'core.diagnostics.missing-return'
	script\core\diagnostics\init.lua:119: in upvalue 'check'
	script\core\diagnostics\init.lua:181: in function 'core.diagnostics'
	[C]: in function 'xpcall'
	script\provider\diagnostic.lua:337: in function 'provider.diagnostic.doDiagnostic'
	[C]: in function 'xpcall'
	script\provider\diagnostic.lua:598: in local 'callback'
	script\provider\diagnostic.lua:569: in function 'provider.diagnostic.awaitDiagnosticsScope'
	script\provider\diagnostic.lua:597: in function <script\provider\diagnostic.lua:595>
[17:09:19.520][error][#0:script\vm\compiler.lua:2023]: script\vm\compiler.lua:2023: attempt to index a nil value
stack traceback:
	script\vm\compiler.lua:2023: in upvalue 'compileByParentNode'
	script\vm\compiler.lua:2052: in function 'vm.vm.compileNode'
	script\vm\function.lua:233: in function 'vm.vm.countReturnsOfSource'
	script\core\diagnostics\missing-return.lua:57: in local 'callback'
	script\parser\guide.lua:756: in function 'parser.guide.eachSourceType'
	script\core\diagnostics\missing-return.lua:51: in function 'core.diagnostics.missing-return'
	script\core\diagnostics\init.lua:119: in upvalue 'check'
	script\core\diagnostics\init.lua:181: in function 'core.diagnostics'
	[C]: in function 'xpcall'
	script\provider\diagnostic.lua:337: in function 'provider.diagnostic.doDiagnostic'
	[C]: in function 'xpcall'
	script\provider\diagnostic.lua:598: in local 'callback'
	script\provider\diagnostic.lua:569: in function 'provider.diagnostic.awaitDiagnosticsScope'
	script\provider\diagnostic.lua:597: in function <script\provider\diagnostic.lua:595>
[17:09:19.630][error][#0:script\vm\compiler.lua:2023]: script\vm\compiler.lua:2023: attempt to index a nil value
stack traceback:
	script\vm\compiler.lua:2023: in upvalue 'compileByParentNode'
	script\vm\compiler.lua:2052: in function 'vm.vm.compileNode'
	script\vm\function.lua:233: in function 'vm.vm.countReturnsOfSource'
	script\core\diagnostics\missing-return.lua:57: in local 'callback'
	script\parser\guide.lua:756: in function 'parser.guide.eachSourceType'
	script\core\diagnostics\missing-return.lua:51: in function 'core.diagnostics.missing-return'
	script\core\diagnostics\init.lua:119: in upvalue 'check'
	script\core\diagnostics\init.lua:181: in function 'core.diagnostics'
	[C]: in function 'xpcall'
	script\provider\diagnostic.lua:337: in function 'provider.diagnostic.doDiagnostic'
	[C]: in function 'xpcall'
	script\provider\diagnostic.lua:598: in local 'callback'
	script\provider\diagnostic.lua:569: in function 'provider.diagnostic.awaitDiagnosticsScope'
	script\provider\diagnostic.lua:597: in function <script\provider\diagnostic.lua:595>
[17:09:19.745][error][#0:script\vm\compiler.lua:2023]: script\vm\compiler.lua:2023: attempt to index a nil value
stack traceback:
	script\vm\compiler.lua:2023: in upvalue 'compileByParentNode'
	script\vm\compiler.lua:2052: in function 'vm.vm.compileNode'
	script\vm\function.lua:233: in function 'vm.vm.countReturnsOfSource'
	script\core\diagnostics\missing-return.lua:57: in local 'callback'
	script\parser\guide.lua:756: in function 'parser.guide.eachSourceType'
	script\core\diagnostics\missing-return.lua:51: in function 'core.diagnostics.missing-return'
	script\core\diagnostics\init.lua:119: in upvalue 'check'
	script\core\diagnostics\init.lua:181: in function 'core.diagnostics'
	[C]: in function 'xpcall'
	script\provider\diagnostic.lua:337: in function 'provider.diagnostic.doDiagnostic'
	[C]: in function 'xpcall'
	script\provider\diagnostic.lua:598: in local 'callback'
	script\provider\diagnostic.lua:569: in function 'provider.diagnostic.awaitDiagnosticsScope'
	script\provider\diagnostic.lua:597: in function <script\provider\diagnostic.lua:595>
@CppCXY CppCXY added the bug Something isn't working label Aug 2, 2024
@tomlau10
Copy link
Contributor

tomlau10 commented Aug 2, 2024

script\vm\compiler.lua:2023 is trying to index the node cache of source object

local function compileByParentNode(source)
if vm.getNode(source):isTyped() then

attempt to index a nil value

This means that the node cache is not found, which it should exist during the whole process of vm.compileNode
I suspect that at sometime, vm.removeNode is called on this source object 🤔


From the diff between 3.9.3 => 3.10.0, two vm.removeNode function call is added:

As the latter one is just calling vm.removeNode inside a foreach of a diagnostics test, I don't think that one is related. This lefts the former one which trying to do vm.removeNode in a matchCall().


Can your workspace reproduce this issue 100%? @citRaTTV
As I don't have a workspace to reproduce this, seems we need your help to debug on your side .
The debugging approach that I can think of:

  • Make sure your can reproduce this 100%, or at least very frequently
  • Then revert the change in fix: inconsistent type narrow due to outdated node caches of call.args #2765, it is just a forloop here:
    if call.args then
    -- clear node caches of args to allow recomputation with the type narrowed call
    for _, arg in ipairs(call.args) do
    vm.removeNode(arg)
    end
    end

    You can do this by modifying the extension script file directly, it should be located in a path like C:\Users\TomLau\.vscode\extensions\sumneko.lua-3.10.0-win32-x64\server\script
  • After modifying, restart vscode to see if this issue persist
  • Until then we can know if this line of change is the culprit, and think about the resolution 🙏

PS:
If it is confirmed that #2765 is the culprit, of course we can request extension author to revert that immediately.
But then as we don't have a reproducible workspace yet, we can never fix #2758 properly without causing error on your side.
So we need your help 🙏

@sumneko sumneko closed this as completed in 8ecec08 Aug 2, 2024
@tomlau10
Copy link
Contributor

tomlau10 commented Aug 2, 2024

glad that it is fixed so quickly 👍

@citRaTTV
Copy link
Author

citRaTTV commented Aug 2, 2024

I didn't even get a chance to help out 😂. Let me know if you need anything else from me, thanks for addressing this so quickly!

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

3 participants