Skip to content

Commit 7bd1b21

Browse files
Cirrasfourls
authored andcommitted
Fix analysis errors around type of types
1 parent 91faadd commit 7bd1b21

File tree

6 files changed

+45
-4
lines changed

6 files changed

+45
-4
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- **API:** `EnumeratorOccurrence::getMoveNext` method.
1515
- **API:** `EnumeratorOccurrence::getCurrent` method.
1616
- **API:** `ForInStatementNode.getEnumeratorOccurrence` method.
17+
- **API:** `TypeOfTypeNode::getTypeReferenceNode` method.
1718

1819
### Changed
1920

@@ -37,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3738
- False positives on enums that are never referenced by name (but have used values) in `UnusedType`.
3839
- Name resolution failures in legacy initialization sections referencing the implementation section.
3940
- Incorrect file position calculation for multiline string tokens.
41+
- Analysis errors around `type of` type declarations.
4042

4143
## [1.15.0] - 2025-04-03
4244

delphi-frontend/src/main/antlr3/au/com/integradev/delphi/antlr/Delphi.g

+1-1
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ simpleProcedureType : procedureTypeHeading -> ^(TkProcedureType<Procedu
646646
procedureTypeHeading : FUNCTION<ProcedureTypeHeadingNodeImpl>^ routineParameters? routineReturnType? ((';')? interfaceDirective)*
647647
| PROCEDURE<ProcedureTypeHeadingNodeImpl>^ routineParameters? ((';')? interfaceDirective)*
648648
;
649-
typeOfType : TYPE<TypeOfTypeNodeImpl>^ OF typeDecl
649+
typeOfType : TYPE<TypeOfTypeNodeImpl>^ OF typeReference
650650
;
651651
strongAliasType : TYPE<StrongAliasTypeNodeImpl>^ typeReferenceOrStringOrFile codePageExpression?
652652
;

delphi-frontend/src/main/java/au/com/integradev/delphi/antlr/ast/node/TypeOfTypeNodeImpl.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
import au.com.integradev.delphi.antlr.ast.visitors.DelphiParserVisitor;
2222
import javax.annotation.Nonnull;
2323
import org.antlr.runtime.Token;
24-
import org.sonar.plugins.communitydelphi.api.ast.TypeNode;
24+
import org.sonar.plugins.communitydelphi.api.ast.TypeDeclarationNode;
2525
import org.sonar.plugins.communitydelphi.api.ast.TypeOfTypeNode;
26+
import org.sonar.plugins.communitydelphi.api.ast.TypeReferenceNode;
2627
import org.sonar.plugins.communitydelphi.api.type.Type;
2728

2829
public final class TypeOfTypeNodeImpl extends TypeNodeImpl implements TypeOfTypeNode {
@@ -35,9 +36,19 @@ public <T> T accept(DelphiParserVisitor<T> visitor, T data) {
3536
return visitor.visit(this, data);
3637
}
3738

39+
@Override
40+
public TypeReferenceNode getTypeReferenceNode() {
41+
return (TypeReferenceNode) getChild(1);
42+
}
43+
3844
@Override
3945
@Nonnull
4046
protected Type createType() {
41-
return ((TypeNode) getChild(0)).getType();
47+
String image = null;
48+
if (parent instanceof TypeDeclarationNode) {
49+
image = ((TypeDeclarationNode) parent).fullyQualifiedName();
50+
}
51+
Type type = getTypeReferenceNode().getType();
52+
return getTypeFactory().classOf(image, type);
4253
}
4354
}

delphi-frontend/src/main/java/org/sonar/plugins/communitydelphi/api/ast/TypeOfTypeNode.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@
1818
*/
1919
package org.sonar.plugins.communitydelphi.api.ast;
2020

21-
public interface TypeOfTypeNode extends TypeNode {}
21+
public interface TypeOfTypeNode extends TypeNode {
22+
TypeReferenceNode getTypeReferenceNode();
23+
}

delphi-frontend/src/test/java/au/com/integradev/delphi/executor/DelphiSymbolTableExecutorTest.java

+6
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,12 @@ void testClassReferenceConstructorTypeResolution() {
421421
verifyUsages(8, 16, reference(22, 11));
422422
}
423423

424+
@Test
425+
void testClassReferenceTypeOf() {
426+
execute("classReferences/TypeOf.pas");
427+
verifyUsages(10, 10, reference(17, 2));
428+
}
429+
424430
@Test
425431
void testSimpleForwardDeclarations() {
426432
execute("forwardDeclarations/Simple.pas");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
unit TypeOf;
2+
3+
interface
4+
5+
type
6+
TIntegerType = type of Integer;
7+
8+
implementation
9+
10+
procedure Foo(T: TIntegerType);
11+
begin
12+
// do nothing
13+
end;
14+
15+
procedure Test;
16+
begin
17+
Foo(Integer);
18+
end;
19+
20+
end.

0 commit comments

Comments
 (0)