LuaLS / LuaLS/LuaParser

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

Open
#9 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
76
Forks
13
PR merge metrics
No merged PRs in 30d

Description

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

```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)

Contributor guide

No contributing guide indexed for this repository

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 by reproducing the Lua snippet through parser.compile and inspect state.ast.locals and the ast.type values for each assignment target. Compare the result for _ENV, a, a.x, and a[1]; done means the assignment no longer creates incorrect local variables or marks every target as 'local'.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
compilers
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.