LuaLS / LuaLS/lua-language-server

duplicate field error when setting a field to a function in an if/else

Open
#1,794 2 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Diagnostics/Syntax Checking

### Expected Behaviour

No duplicate field error

### Actual Behaviour

![image](https://user-images.githubusercontent.com/12116957/209880315-80b766fb-41da-4a94-9454-d0229cc7a943.png)
``` local t = {}
if x then
t.s = function() return 1 end
else
t.s = function() return 2 end
end
```
This is not a duplicate field and should not be an error

### Reproduction steps

``` local t = {}
if x then
t.s = function() return 1 end
else
t.s = function() return 2 end
end
```
Write that into the editor. See error as indicated above.

### Additional Notes

v3.6.4

### Log File

[file_c%3A_Users_User_AppData_Roaming_Factorio_mods_space-exploration.log](https://github.com/sumneko/lua-language-server/files/10316714/file_c.3A_Users_User_AppData_Roaming_Factorio_mods_space-exploration.log)

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

Reproduce the diagnostic in the Visual Studio Code extension using the provided conditional-assignment snippet, focusing on the Diagnostics/Syntax Checking entry point. Trace why the two branch assignments are reported as a duplicate field, then verify that the same example no longer produces the error.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.