Skip to content

Commit bb28773

Browse files
committed
Handle aliases when casting to *TypeImpl classes
This is a little bit of a "gotcha". Now that type aliases are transparent to the aliased type, we need to do a little extra work before internally casting a type to `Impl` for mutable operations. Otherwise, you might try to cast a generated alias implementation to some unrelated type.
1 parent 575b180 commit bb28773

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

delphi-frontend/src/main/java/au/com/integradev/delphi/antlr/ast/visitors/SymbolTableVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,7 +759,7 @@ private Data createTypeScope(TypeDeclarationNode node, Data data) {
759759
Type type = declaration.getType();
760760
typeScope.setType(type);
761761

762-
if (!node.isWeakAlias()
762+
if (!type.isAlias()
763763
&& type.isPointer()
764764
&& data.switchRegistry.isActiveSwitch(SwitchKind.POINTERMATH, node.getTokenIndex())) {
765765
((PointerTypeImpl) type).setAllowsPointerMath();

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import org.sonar.plugins.communitydelphi.api.symbol.scope.DelphiScope;
7575
import org.sonar.plugins.communitydelphi.api.symbol.scope.RoutineScope;
7676
import org.sonar.plugins.communitydelphi.api.type.Type;
77+
import org.sonar.plugins.communitydelphi.api.type.Type.AliasType;
7778
import org.sonar.plugins.communitydelphi.api.type.Type.ProceduralType;
7879
import org.sonar.plugins.communitydelphi.api.type.Type.ScopedType;
7980
import org.sonar.plugins.communitydelphi.api.type.Type.TypeParameterType;
@@ -517,7 +518,12 @@ private static void completeTypeParameterReferences(RoutineImplementationNode ro
517518

518519
TypeParameterType parameterType = (TypeParameterType) parameterDeclaration.getType();
519520
Type argumentType = parameterReference.getType();
520-
if (argumentType.isTypeParameter()) {
521+
522+
while (argumentType.isWeakAlias()) {
523+
argumentType = ((AliasType) argumentType).aliasedType();
524+
}
525+
526+
if (!argumentType.isAlias() && argumentType.isTypeParameter()) {
521527
((TypeParameterTypeImpl) argumentType).setFullType(parameterType);
522528
}
523529
}

0 commit comments

Comments
 (0)