LuaLS / LuaLS/lua-language-server

BUG: 当_ENV作为多重赋值的第一个变量时, 后续变量会错误的识别成局部变量.

Open
#2,614 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

### 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?

Type Checking

### Expected Behaviour

这是非常罕见的场景, 并且建议避免编写这种代码.

```lua
local env = _ENV
_ENV, a = {}, 1
env.print(env.a, a) -- 1 nil
```
使用parser.compile函数解析得到的state.ast.locals会多出错误的局部变量_ENV和a.
整个多重赋值语句都会识别成local变量定义, 不管是a, a.x, a[1]形式, 生成的ast.type字段都会被错误的标识成'local'.

同时也会导致[vscode插件](https://github.com/LuaLS/lua-language-server)错误提示.
![image](https://github.com/LuaLS/LuaParser/assets/73267079/19d1acbc-a837-408f-bc68-96b1109f6f63)

### Actual Behaviour

错误的将多重赋值语句, 识别成了局部变量定义语句.

### Reproduction steps

.

### Additional Notes

_No response_

### Log File

_No response_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with parser.compile and inspect state.ast.locals for the supplied `_ENV, a = {}, 1` example, comparing the generated AST with the assignment targets. Done means the multiple assignment no longer creates false local variables or produces the related VS Code diagnostic, including for `a`, `a.x`, and `a[1]` targets.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.