Skip to content

Conversation

JLLeitschuh
Copy link
Contributor

@JLLeitschuh JLLeitschuh commented Mar 19, 2022

Adds support for assertTrue and assertFalse as guard preconditions.

Not having this was causing false positives in tests where assertTrue was guarding a bit of logic, but CodeQL didn't know that assertTrue was a valid guard.

or
checkTrue = false and m.hasName("assumeFalse")
)
or
exists(Parameter p, IfStmt ifstmt, Expr cond |
Copy link
Contributor

Choose a reason for hiding this comment

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

Might as well generalise this at the same time

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -11,6 +11,8 @@ import java
* is equal to `checkTrue` and throws otherwise.
*/
predicate conditionCheckMethod(Method m, boolean checkTrue) {
conditionCheckMethod(m, 0, checkTrue)
Copy link
Contributor

Choose a reason for hiding this comment

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

Rather than have two mutually recursive functions, just merge these into one method with an argument parameter and set it to zero where required

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking about doing that, but because this was a public API I didn't want to beak any downstream consumers. That being said, this is in a package called internal so I'm happy to make that change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point, keep the two-arg overload to be non-breaking (actually consider giving this a different name; that's usually better than overloading for clarity's sake), but just let that one be a convenience method with a one-line definition rather than a mutually recursive pair.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually consider giving this a different name;

Got any suggestions here?

Copy link
Contributor

Choose a reason for hiding this comment

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

conditionCheckMethodArgument?

}

void test9() {
r(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Test the wrapper-function case using a logical-not operator too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe I've done this, but let me know if I misunderstood the request here.

@JLLeitschuh
Copy link
Contributor Author

Anything else that this PR is missing?

@smowton
Copy link
Contributor

smowton commented Mar 29, 2022

If you're deprecating conditionCheck, which seems reasonable, then replace all internal uses with the new method.

@smowton
Copy link
Contributor

smowton commented Mar 29, 2022

(apologies for the delay, didn't notice you'd done anything here; as a rule I ignore emails telling me about pushed commits and only attend a PR again when I see a comment)

@JLLeitschuh
Copy link
Contributor Author

If you're deprecating conditionCheck, which seems reasonable, then replace all internal uses with the new method.

Last I checked, I had done this, let me know if you spot any cases I missed. 😃

@JLLeitschuh JLLeitschuh requested review from smowton and removed request for a team March 30, 2022 14:18
smowton
smowton previously approved these changes Mar 31, 2022
}

/**
* Holds if `m` is a non-overridable testing framework methopd that checks that its first argument
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Holds if `m` is a non-overridable testing framework methopd that checks that its first argument
* Holds if `m` is a non-overridable testing framework method that checks that its first argument

smowton
smowton previously approved these changes Mar 31, 2022
Copy link
Contributor Author

@JLLeitschuh JLLeitschuh left a comment

Choose a reason for hiding this comment

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

I'm done with these changes. Feel free to merge whenever you all are happy! 😄

Thanks everyone for your help!

@smowton smowton merged commit 9309a65 into github:main Mar 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants