LuaLS / LuaLS/lua-language-server
BUG: 当_ENV作为多重赋值的第一个变量时, 后续变量会错误的识别成局部变量.
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)错误提示.

### Actual Behaviour
错误的将多重赋值语句, 识别成了局部变量定义语句.
### Reproduction steps
.
### Additional Notes
_No response_
### Log File
_No response_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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