|
26 | 26 | import javax.annotation.Nonnull;
|
27 | 27 | import org.antlr.runtime.Token;
|
28 | 28 | import org.sonar.plugins.communitydelphi.api.ast.ArrayExpressionNode;
|
| 29 | +import org.sonar.plugins.communitydelphi.api.ast.DelphiNode; |
29 | 30 | import org.sonar.plugins.communitydelphi.api.ast.ExpressionNode;
|
| 31 | +import org.sonar.plugins.communitydelphi.api.ast.TypeDeclarationNode; |
30 | 32 | import org.sonar.plugins.communitydelphi.api.type.Type;
|
| 33 | +import org.sonar.plugins.communitydelphi.api.type.Type.CollectionType; |
31 | 34 | import org.sonar.plugins.communitydelphi.api.type.TypeFactory;
|
| 35 | +import org.sonar.plugins.communitydelphi.api.type.Typed; |
32 | 36 |
|
33 | 37 | public final class ArrayExpressionNodeImpl extends ExpressionNodeImpl
|
34 | 38 | implements ArrayExpressionNode {
|
@@ -65,11 +69,32 @@ public String getImage() {
|
65 | 69 | @Override
|
66 | 70 | @Nonnull
|
67 | 71 | protected Type createType() {
|
| 72 | + int nestingLevel = 0; |
| 73 | + DelphiNode parent = this; |
| 74 | + do { |
| 75 | + ++nestingLevel; |
| 76 | + parent = parent.getParent(); |
| 77 | + } while (parent instanceof ArrayExpressionNode); |
| 78 | + |
68 | 79 | Type elementType = TypeFactory.unknownType();
|
69 |
| - List<ExpressionNode> elements = getElements(); |
70 |
| - if (!elements.isEmpty()) { |
71 |
| - elementType = elements.get(0).getType(); |
| 80 | + if (parent instanceof Typed && !(parent instanceof TypeDeclarationNode)) { |
| 81 | + elementType = ((Typed) parent).getType(); |
| 82 | + for (int i = 0; i < nestingLevel; ++i) { |
| 83 | + if (!(elementType instanceof CollectionType)) { |
| 84 | + elementType = TypeFactory.unknownType(); |
| 85 | + break; |
| 86 | + } |
| 87 | + elementType = ((CollectionType) elementType).elementType(); |
| 88 | + } |
| 89 | + } |
| 90 | + |
| 91 | + if (elementType.isUnknown()) { |
| 92 | + List<ExpressionNode> elements = getElements(); |
| 93 | + if (!elements.isEmpty()) { |
| 94 | + elementType = elements.get(0).getType(); |
| 95 | + } |
72 | 96 | }
|
| 97 | + |
73 | 98 | return ((TypeFactoryImpl) getTypeFactory()).array(null, elementType, Set.of(ArrayOption.FIXED));
|
74 | 99 | }
|
75 | 100 | }
|
0 commit comments