Skip to content

Diagnostics nil check is suppressed by the field value matching the parameter type #3056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
TIMONz1535 opened this issue Jan 26, 2025 · 2 comments · Fixed by #3098
Closed

Comments

@TIMONz1535
Copy link
Contributor

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

Diagnostics nil check does not depend on the field parameter value

---@class A
---@field b string

---@type A?
local a

if a.b == "string1" then end  -- Need check nil
if a.b == "string" then end  -- Need check nil

Actual Behaviour

The string value "string" suppresses the triggering of diagnostics, because of type string of field b.

Image

Reproduction steps

  1. Copy the sample code
  2. Check the diagnostics a.b == "string" when a should trigger "Need check nil"

Additional Notes

No response

Log File

No response

@idbrii
Copy link

idbrii commented Feb 26, 2025

Did this break recently? I'm on luals 3.9.3 and I get nil check warnings:

file.lua variable 'a' is never set
file.lua Empty block.
file.lua Need check nil.
file.lua empty if branch
file.lua Empty block.
file.lua Need check nil.
file.lua empty if branch

@tomlau10
Copy link
Contributor

a git bisect yields the following:

5c3086acd08765f9122ed5b7f806e2b2bf3737e3 is the first bad commit
commit 5c3086acd08765f9122ed5b7f806e2b2bf3737e3 (HEAD)
Author: Lewis Russell <[email protected]>
Date:   Sun Sep 22 17:19:12 2024 +0100

    feat: type narrow types with literal fields

 changelog.md                   |  1 +
 script/vm/tracer.lua           | 59 ++++++++++++++++++++++++++++++++++++++++++
 test/type_inference/common.lua | 50 +++++++++++++++++++++++++++++++++++
 3 files changed, 110 insertions(+)

which is #2864 by @lewis6991


There seems to be quite a number of regression issues related to that PR now 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants