Skip to content

Alias of an array of itself causing stack overflow when providing completion #1717

Description

@JanSharp

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Linux

What is the issue affecting?

Annotations, Completion

Expected Behaviour

When having an alias like ---@alias Foo (string|Foo)[] it should understand that { "hello", "world"} or {"hello", {"wordl"}} are both matching that type. That's actually about type checking, which is not the focus of this issue/bug report, see below.

Actual Behaviour

The server errors due to a stack overflow when trying to provide completion inside of a table constructor that is assigned to a variable of type Foo. The error is:

[01:04:07.826][error][#0:script/workspace/scope.lua:58]: script/workspace/scope.lua:58: stack overflow
stack traceback:
	script/workspace/scope.lua:58: in method 'isChildUri'
	script/workspace/scope.lua:216: in function 'workspace.scope.getFolder'
	script/workspace/scope.lua:243: in function 'workspace.scope.getScope'
	script/vm/global.lua:51: in method 'getSets'
	script/vm/def.lua:50: in upvalue 'searchByNode'
	script/vm/def.lua:91: in function 'vm.vm.getDefs'
	script/core/completion/completion.lua:1276: in upvalue 'insertEnum'
	script/core/completion/completion.lua:1277: in upvalue 'insertEnum'
	script/core/completion/completion.lua:1277: in upvalue 'insertEnum'
	script/core/completion/completion.lua:1277: in upvalue 'insertEnum'
	...	(skipping 83317 levels)
	script/core/completion/completion.lua:1277: in upvalue 'insertEnum'
	script/core/completion/completion.lua:1277: in upvalue 'insertEnum'
	script/core/completion/completion.lua:1291: in upvalue 'checkTypingEnum'
	script/core/completion/completion.lua:1309: in upvalue 'checkEqualEnumLeft'
	script/core/completion/completion.lua:1354: in upvalue 'checkEqualEnumInString'
	script/core/completion/completion.lua:1384: in upvalue 'trySpecial'
	script/core/completion/completion.lua:2229: in upvalue 'tryCompletions'
	script/core/completion/completion.lua:2248: in function 'core.completion.completion.completion'
	script/provider/provider.lua:638: in function <script/provider/provider.lua:601>
	[C]: in function 'xpcall'
	script/proto/proto.lua:184: in function <script/proto/proto.lua:159>

Reproduction steps

  1. put this code somewhere
---@alias Foo Foo[]
---@type Foo
local foo
foo = {""}
  1. put the cursor inside of ""
  2. press space bar
  3. wait a second
  4. see error

Additional Notes

language server version: 3.6.3 (even though the log file says 3.5.3, I've got a stupid setup. I can guarantee I'm on 3.6.3)

The real world example is ---@alias LocalisedString string|number|boolean|LuaObject|nil|(string|LocalisedString)[] for Factorio. ---@alias Foo Foo[] is just the minimal reproduction case.

Log File

file_mnt_big_temp_ls_crash_minimal.log

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions