-
Notifications
You must be signed in to change notification settings - Fork 53
fix(diagnostics): compare non-nil with nil #906
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
base: main
Are you sure you want to change the base?
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 | ||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -127,4 +127,21 @@ mod test { | |||||||||||||||||||||||||||||||||||||||||||||||||
| "# | ||||||||||||||||||||||||||||||||||||||||||||||||||
| )); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| fn test_nonnli_with_nil() { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut ws = VirtualWorkspace::new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assert!(!ws.check_code_for( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| DiagnosticCode::UnnecessaryAssert, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| r#" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assert("abc" ~= nil) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "# | ||||||||||||||||||||||||||||||||||||||||||||||||||
| )); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assert!(!ws.check_code_for( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| DiagnosticCode::UnnecessaryAssert, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| r#" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assert(1 == nil) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "# | ||||||||||||||||||||||||||||||||||||||||||||||||||
| )); | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+134
to
+145
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. The logic of these tests is incorrect. With the changes in Therefore,
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -26,4 +26,25 @@ mod test { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #[test] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fn test_nonnil_with_nil() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut ws = VirtualWorkspace::new(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert!(!ws.check_code_for( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DiagnosticCode::UnnecessaryIf, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| r#" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if 1 ~= nil then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| error("Impossible") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| assert!(!ws.check_code_for( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DiagnosticCode::UnnecessaryIf, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| r#" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if "abc" == nil then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| error("Impossible") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "# | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| )); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+33
to
+48
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. The logic of these tests is incorrect. With the changes in Therefore,
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -506,6 +506,16 @@ fn infer_cmp_expr(_: &DbIndex, left: LuaType, right: LuaType, op: BinaryOperator | |||||||||||||||||||||||||||||||
| BinaryOperator::OpNe => Ok(LuaType::BooleanConst(i != j)), | ||||||||||||||||||||||||||||||||
| _ => Ok(LuaType::Boolean), | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| (LuaType::Nil, right) if right.is_const() => match op { | ||||||||||||||||||||||||||||||||
| BinaryOperator::OpEq => Ok(LuaType::BooleanConst(false)), | ||||||||||||||||||||||||||||||||
| BinaryOperator::OpNe => Ok(LuaType::BooleanConst(true)), | ||||||||||||||||||||||||||||||||
| _ => Ok(LuaType::Boolean), | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
| (left, LuaType::Nil) if left.is_const() => match op { | ||||||||||||||||||||||||||||||||
| BinaryOperator::OpEq => Ok(LuaType::BooleanConst(false)), | ||||||||||||||||||||||||||||||||
| BinaryOperator::OpNe => Ok(LuaType::BooleanConst(true)), | ||||||||||||||||||||||||||||||||
| _ => Ok(LuaType::Boolean), | ||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||
|
Comment on lines
+509
to
+518
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. These two match arms handle the cases
Suggested change
|
||||||||||||||||||||||||||||||||
| (left, right) if left.is_const() && right.is_const() => Ok(LuaType::BooleanConst(false)), | ||||||||||||||||||||||||||||||||
| _ => Ok(LuaType::Boolean), | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
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.
There's a typo in the test function name. It should be
test_nonnil_with_nilto match the other test file and for clarity.