Skip to content
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

Add bitwise_for_parity_check #83

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

manlikeHB
Copy link

closes #65

@manlikeHB manlikeHB marked this pull request as ready for review September 19, 2024 17:27
@manlikeHB manlikeHB changed the title Add bitwise_for_parity_check #65 Add bitwise_for_parity_check Sep 20, 2024

//! > cairo_code
fn main() {
let a = 200 & 1;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let a = 200 & 1;
let a = 200_u32 & 1;

pub fn fix_bitwise_for_parity_check(&self, db: &dyn SyntaxGroup, node: ExprBinary) -> String {
let lhs = node.lhs(db).as_syntax_node().get_text(db);

format!("DivRem::div_rem({}, 2)", lhs.trim())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
format!("DivRem::div_rem({}, 2)", lhs.trim())
format!("{} % 2", lhs.trim())

pub const BITWISE_FOR_PARITY: &str =
"You seem to be trying to use `&` for parity check. Consider using `DivRem::div_rem()` instead.";

pub fn check_bitwise_for_parity(db: &dyn SyntaxGroup, node: &ExprBinary, diagnostics: &mut Vec<PluginDiagnostic>) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should check that this type indeed implements DivRem so i don't think you should be using SyntaxGroup but use SemanticGroup

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 this pull request may close these issues.

Add bitwise_for_parity_check
2 participants