LuaLS / LuaLS/lua-language-server

`repeat…until val ~= nil` should satisfy the need for nil checks

Open
#2,531 0 comments 3 reactions 0 assignees View on GitHub
Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

I have some code where I have to wait for a forked process to create a file and I can't get feedback over its return status or stdout, so I use a polling pattern similar to this:

```lua
local val = nil

-- kick off the external process
fork_process(...)

repeat
val = check_for_val(...)
until val ~= nil

val:foo()
```

In this current form, I get a diagnostic that says I need to perform a nil check on `val` before calling `foo`, but the loop condition here should be considered the nil check.

This already works for `while val == nil do...end` so it would be nice to see it for `repeat...until val~= nil` as well.

Contributor guide

Open the contributing guide

Research direction

The issue names no source file or test; start by locating the flow-analysis logic that handles nil checks for while loops and repeat…until conditions. Reproduce the polling example and compare its diagnostic with the existing while val == nil behavior; done when val:foo() no longer requires an extra nil check after repeat…until val ~= nil.

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.