-
Notifications
You must be signed in to change notification settings - Fork 59
fix: check t[k] should not warn unnecessary-if #972
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,4 +26,21 @@ mod test { | |
| "# | ||
| )); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_table_generic_index_not_unnecessary() { | ||
| let mut ws = VirtualWorkspace::new(); | ||
| assert!(ws.check_code_for( | ||
| DiagnosticCode::UnnecessaryIf, | ||
| r#" | ||
| ---@type table<string, number> | ||
| local t = {} | ||
| local k = "hello" | ||
| local v = t[k] | ||
| if v then | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd argue this is unnecessary. If you want it not to be then the type of
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thats what I did, quite counterintuitive to me, but u r right |
||
| print(v) | ||
| end | ||
| "# | ||
| )); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test name
test_table_generic_index_not_unnecessarysuggests that this test should pass if theUnnecessaryIfdiagnostic is not found. Based on other tests in this file,check_code_forseems to returntruewhen a diagnostic is found. If that's the case, this assertion should be inverted toassert!(!ws.check_code_for(...))to correctly verify the fix.