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

112 missing validations on if, while & do-while #230

Merged
merged 3 commits into from
Sep 20, 2023

Conversation

kjonescertinia
Copy link
Contributor

This added checking the expressions on these statements return Boolean values. For once that rule appears to be universal and there are no assignability concerns.

As part of this I have simplified the way we add Issues a little so you don't need to provide the path separately from the range. I think this previously used to be an issue due to the apexlink/pkgforce split if I am recalling correctly. Have have also included some minor IntelliJ warning fixes that got flagged due to the Issue change.

There is a bug the apex-parser on do-while in that it allows single statements but Apex only supports blocks, just to make it different from if & while. I will create a seperate tickets for correcting this.

@@ -152,6 +152,15 @@ object LocalVariableDeclarationStatement {
final case class IfStatement(expression: Expression, statements: Seq[Statement]) extends Statement {
override def verify(context: BlockVerifyContext): Unit = {
val expr = expression.verify(context)
if (expr.isDefined && expr.typeName != TypeNames.Boolean) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should be checking expr.isStatic here as well, I will correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed this via a helper method on Statement as there are some similar cases coming for throw/catch validations.

test("Single statement") {
// TODO: This should fail a block is required, apex-parser is over general
happyTypeDeclaration("public class Dummy {{ do System.debug(''); while (true); }}")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

bomb has been planted

@kjonescertinia kjonescertinia merged commit 9c25197 into main Sep 20, 2023
@kjonescertinia kjonescertinia deleted the 112-missing-validations-on-ifwhile branch September 20, 2023 16:39
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.

2 participants