Skip to content

Commit 6c5ac68

Browse files
fourlscirras
authored andcommitted
Fix type resolution failures on as casts using procedural types
1 parent 9701637 commit 6c5ac68

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
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
### Fixed
1515

1616
- Name resolution failures on generic routine invocations where later type parameters are constrained by earlier type parameters.
17+
- Type resolution failures on `as` casts where the type is returned from a routine invocation.
1718

1819
## [1.16.0] - 2025-05-09
1920

delphi-frontend/src/main/java/au/com/integradev/delphi/symbol/resolve/ExpressionTypeResolver.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,14 @@ public Type resolve(PrimaryExpressionNode expression) {
121121
}
122122

123123
private static Type classReferenceValueType(Type type) {
124+
if (type.isProcedural()) {
125+
type = ((ProceduralType) type).returnType();
126+
}
127+
124128
if (type.isClassReference()) {
125129
return ((ClassReferenceType) type).classType();
126130
}
131+
127132
return unknownType();
128133
}
129134

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ void testCharTypeResolution() {
517517
@Test
518518
void testCastTypeResolution() {
519519
execute("typeResolution/Casts.pas");
520-
verifyUsages(8, 14, reference(15, 12), reference(16, 16));
520+
verifyUsages(8, 14, reference(22, 12), reference(23, 16), reference(24, 20));
521521
}
522522

523523
@Test

delphi-frontend/src/test/resources/au/com/integradev/delphi/symbol/typeResolution/Casts.pas

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@ TFoo = class(TObject)
88
procedure Bar;
99
end;
1010

11+
TFooClass = class of TFoo;
12+
1113
implementation
1214

15+
function GetClass: TFooClass;
16+
begin
17+
Result := TFoo;
18+
end;
19+
1320
procedure Test(Arg: TObject);
1421
begin
1522
TFoo(Arg).Bar;
1623
(Arg as TFoo).Bar;
24+
(Arg as GetClass).Bar;
1725
end;
1826

1927
end.

0 commit comments

Comments
 (0)