Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Diagnostics for unnecessary assert #3128

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

Merged
sumneko merged 3 commits into LuaLS:master from ribru17:unnecessary_assert
Apr 5, 2025
Merged

Conversation

Copy link
Contributor

@ribru17 ribru17 commented Mar 22, 2025

@ribru17 ribru17 force-pushed the unnecessary_assert branch 2 times, most recently from ccb359f to d062eb5 Compare March 22, 2025 01:23
Copy link
Contributor

Judging from the screenshot, the message expression of type `boolean` is always truthy from assert(true) seems a bit misleading 😕 .

  • false is also a boolean type, but assert(false) won't cause problem

Copy link
Contributor Author

ribru17 commented Mar 22, 2025

Ah true, not sure why the printed type evaluates to boolean instead of true. I'll investigate

Copy link
Contributor Author

ribru17 commented Mar 22, 2025

Opted to just not print the expression type for now

tomlau10 reacted with laugh emoji

Copy link
Member

CppCXY commented Mar 24, 2025

is it test for multi return function?

---@return string?, string?
local function f() end
assert(f())

Copy link
Member

CppCXY commented Mar 24, 2025

I think that if it is always falsy is also an unnecessary assertion. right?

assert(nil and 5) -- always falsy

Copy link
Contributor Author

ribru17 commented Mar 24, 2025
edited
Loading

I think that if it is always falsy is also an unnecessary assertion. right?

assert(nil and 5) -- always falsy

True, but this PR only handles unnecessary if true. I'll add that as well, but wanted to keep the scope small at first.

is it test for multi return function?

---@return string?, string?
local function f() end
assert(f())

Works here as well, I added a test

@sumneko sumneko merged commit 1c02832 into LuaLS:master Apr 5, 2025
11 checks passed
Copy link
Collaborator

sumneko commented Apr 5, 2025

Thank you!

ribru17 reacted with heart emoji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /