Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Parsing errors where adjacent `>` and `=` tokens were wrongly interpreted as the `>=` operator.
- False-positives within assignment statements in `IndexLastListElement`.

## [1.13.0] - 2025-02-05

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Optional;
import org.sonar.check.Rule;
import org.sonar.plugins.communitydelphi.api.ast.ArrayAccessorNode;
import org.sonar.plugins.communitydelphi.api.ast.AssignmentStatementNode;
import org.sonar.plugins.communitydelphi.api.ast.BinaryExpressionNode;
import org.sonar.plugins.communitydelphi.api.ast.CommonDelphiNode;
import org.sonar.plugins.communitydelphi.api.ast.DelphiNode;
Expand All @@ -47,6 +48,13 @@ public DelphiCheckContext visit(ArrayAccessorNode arrayTypeNode, DelphiCheckCont
return super.visit(arrayTypeNode, context);
}

@Override
public DelphiCheckContext visit(
AssignmentStatementNode assignmentStatementNode, DelphiCheckContext context) {
// Ignore LHS of assignment statements - TList.Last is a function, so can't be put here
return super.visit(assignmentStatementNode.getValue(), context);
}

private void doVisit(ArrayAccessorNode arrayTypeNode, DelphiCheckContext context) {
List<ExpressionNode> expressions = arrayTypeNode.getExpressions();
if (expressions.size() != 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,22 @@ void testMatchingExpressionShouldAddIssue(String use) {
.appendImpl("end;"))
.verifyIssues();
}

@Test
void testAssignmentShouldNotAddIssue() {
CheckVerifier.newVerifier()
.withCheck(new IndexLastListElementCheck())
.withStandardLibraryUnit(systemGenericsCollections())
.onFile(
new DelphiTestUnitBuilder()
.appendImpl("uses")
.appendImpl(" System.Generics.Collections;")
.appendImpl("procedure Test;")
.appendImpl("var")
.appendImpl(" List: TList<Integer>;")
.appendImpl("begin")
.appendImpl(" List[List.Count - 1] := 5;")
.appendImpl("end;"))
.verifyNoIssues();
}
}
Loading