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

Improve ASSERT Macro to Handle Operator Precedence More Intuitively #29

Closed
ping-ee opened this issue Sep 22, 2024 · 3 comments
Closed
Assignees

Comments

@ping-ee
Copy link
Contributor

ping-ee commented Sep 22, 2024

Description

The current implementation of the ASSERT macro requires extra parentheses to handle operator precedence correctly, such as:

`ASSERT((a===b));  // Correct

Without these parentheses, expressions may lead to incorrect logic due to operator precedence rules.

For example, a developer might mistakenly write:

`ASSERT(a === b);  // Wrong

This could be misinterpreted by the compiler as:

if (!a === b)  // Wrong behavior

Instead of the intended:

if (!(a === b))  // Correct logic when using parentheses.

Proposed Solution:

if (!exp) begin \

Use a pair of parentheses to wrap exp such as:

if (!(exp)) begin

Benefits:

  1. Prevents potential logical errors due to misunderstood operator precedence.
  2. Improves developer productivity by making the ASSERT macro behavior more intuitive.
  3. Reduces debugging time caused by precedence-related bugs.

Thanks for your work on this framework, it definitely helps me a lot.

Best Regards

@ping-ee ping-ee changed the title Improve ASSERT Macros to Handle Operator Precedence More Intuitively Improve ASSERT Macro to Handle Operator Precedence More Intuitively Sep 22, 2024
@dpretet
Copy link
Owner

dpretet commented Sep 22, 2024

Hello,

That looks to be definitely a good improvement 😄 It's true I faced sometimes this problem, and adding these extra parentheses makes the code weird to read. I have to do a release with a fix for issue #28, a pull request for that proposal is welcome 🤗

Thanks for your feedback and using this flow !

Best,
Damien

@ping-ee
Copy link
Contributor Author

ping-ee commented Sep 22, 2024

Sure, I will submit a pull request for this issue in a few days.
Thanks for your reply.

dpretet added a commit that referenced this issue Sep 23, 2024
@dpretet dpretet self-assigned this Sep 23, 2024
@dpretet
Copy link
Owner

dpretet commented Sep 23, 2024

Thank you for the contribution!

@dpretet dpretet closed this as completed Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants