Skip to content

Commit 064c9a7

Browse files
fourlscirras
authored andcommitted
Fix null reference in PublicField when encountering anonymous records
1 parent c6dc54d commit 064c9a7

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6565
- The `ReadLn` intrinsic was missing the standard input overload.
6666
- Ideographic space (U+3000) was erroneously accepted as a valid identifier character.
6767
- Duplicate imports in a `requires` clause now log a warning instead of throwing an exception.
68+
- NPE on anonymous records in `PublicField`.
6869

6970
## [1.1.0] - 2024-01-02
7071

delphi-checks/src/main/java/au/com/integradev/delphi/checks/PublicFieldCheck.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import org.sonar.check.Rule;
2626
import org.sonar.plugins.communitydelphi.api.ast.FieldDeclarationNode;
27-
import org.sonar.plugins.communitydelphi.api.ast.TypeDeclarationNode;
27+
import org.sonar.plugins.communitydelphi.api.ast.TypeNode;
2828
import org.sonar.plugins.communitydelphi.api.check.DelphiCheck;
2929
import org.sonar.plugins.communitydelphi.api.check.DelphiCheckContext;
3030
import org.sonarsource.analyzer.commons.annotations.DeprecatedRuleKey;
@@ -43,6 +43,6 @@ public DelphiCheckContext visit(FieldDeclarationNode field, DelphiCheckContext c
4343
}
4444

4545
private static boolean isRecordField(FieldDeclarationNode field) {
46-
return field.getFirstParentOfType(TypeDeclarationNode.class).isRecord();
46+
return field.getFirstParentOfType(TypeNode.class).getType().isRecord();
4747
}
4848
}

delphi-checks/src/test/java/au/com/integradev/delphi/checks/PublicFieldCheckTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,23 @@ void testPublicFieldsInRecordsShouldNotAddIssue() {
7777
.appendDecl(" end;"))
7878
.verifyNoIssues();
7979
}
80+
81+
@Test
82+
void testPublicFieldsInNestedRecordsShouldNotAddIssue() {
83+
CheckVerifier.newVerifier()
84+
.withCheck(new PublicFieldCheck())
85+
.onFile(
86+
new DelphiTestUnitBuilder()
87+
.appendDecl("var")
88+
.appendDecl(" MyRec: record")
89+
.appendDecl(" FPublishedField: Integer;")
90+
.appendDecl(" private")
91+
.appendDecl(" FPrivateField: Integer;")
92+
.appendDecl(" protected")
93+
.appendDecl(" FProtectedField: String;")
94+
.appendDecl(" public")
95+
.appendDecl(" FPublicField: String;")
96+
.appendDecl(" end;"))
97+
.verifyNoIssues();
98+
}
8099
}

0 commit comments

Comments
 (0)