Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Name resolution failures when accessing ancestors of enclosing types from nested type methods.
- Name resolution failures on invocations of methods with generic open array parameters.
- Name resolution failures around `Create` calls on types with `constructor` constraints.
- Name resolution failures on `read` and `write` specifiers of indexed properties.
- Name resolution failures on `read`, `write`, and `stored` specifiers of indexed properties.
- Incorrect file position calculation for multiline string tokens.
- Analysis errors around `type of` type declarations.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import au.com.integradev.delphi.symbol.scope.RoutineScopeImpl;
import au.com.integradev.delphi.type.generic.TypeParameterTypeImpl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -56,6 +57,7 @@
import org.sonar.plugins.communitydelphi.api.ast.PropertyImplementsSpecifierNode;
import org.sonar.plugins.communitydelphi.api.ast.PropertyNode;
import org.sonar.plugins.communitydelphi.api.ast.PropertyReadSpecifierNode;
import org.sonar.plugins.communitydelphi.api.ast.PropertyStoredSpecifierNode;
import org.sonar.plugins.communitydelphi.api.ast.PropertyWriteSpecifierNode;
import org.sonar.plugins.communitydelphi.api.ast.RecordExpressionItemNode;
import org.sonar.plugins.communitydelphi.api.ast.RoutineDeclarationNode;
Expand Down Expand Up @@ -269,6 +271,14 @@ public void resolve(PropertyNode property) {
if (impl != null) {
impl.getTypeReferences().stream().map(TypeReferenceNode::getNameNode).forEach(this::resolve);
}

PropertyStoredSpecifierNode stored = property.getStoredSpecifier();
if (stored != null && stored.getExpression() instanceof PrimaryExpressionNode) {
NameResolver storedResolver = createNameResolver();
storedResolver.readPrimaryExpression((PrimaryExpressionNode) stored.getExpression());
storedResolver.disambiguateParameters(getStorageParameterTypes(property));
storedResolver.addToSymbolTable();
}
}

private List<Type> getGetterParameterTypes(PropertyNode property) {
Expand All @@ -290,6 +300,14 @@ private List<Type> getSetterParameterTypes(PropertyNode property) {
return parameterTypes;
}

private List<Type> getStorageParameterTypes(PropertyNode property) {
if (property.getIndexSpecifier() != null) {
return List.of(typeFactory.getIntrinsic(IntrinsicType.INTEGER));
} else {
return Collections.emptyList();
}
}

public void resolve(RoutineDeclarationNode routine) {
resolveRoutine(routine);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@ void testProperties() {
// Alias getter
verifyUsages(17, 13, reference(22, 33));
// Index getter
verifyUsages(29, 13, reference(32, 41));
verifyUsages(29, 13, reference(33, 41));
// Index setter
verifyUsages(30, 14, reference(32, 58));
verifyUsages(30, 14, reference(33, 58));
// Index storage
verifyUsages(31, 13, reference(33, 76));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ TIndexObj = class(TObject)

function GetMyField(Index: Integer): TObject;
procedure SetMyField(Index: Integer; Value: TObject);
function IsStored(Index: Integer): Boolean;
public
property Prop1: TObject index 0 read GetMyField write SetMyField;
property Prop1: TObject index 0 read GetMyField write SetMyField stored IsStored;
end;

implementation
Expand Down