Skip to content

C#: Property- and Indexer call targets for partial overrides.#21881

Open
michaelnebel wants to merge 5 commits into
github:mainfrom
michaelnebel:csharp/propertycalls
Open

C#: Property- and Indexer call targets for partial overrides.#21881
michaelnebel wants to merge 5 commits into
github:mainfrom
michaelnebel:csharp/propertycalls

Conversation

@michaelnebel

@michaelnebel michaelnebel commented May 21, 2026

Copy link
Copy Markdown
Contributor

It appears that call targets for properties and indexers are missing, when only the getter or setter is overridden.
Assume we have

public class BaseClass
{
    public virtual int Value
    {
        get { return field; }
        set { field = value; }
    }
}

public class DerivedClass1 : BaseClass
{
    public override int Value
    {
        get { return 20; }
    }
}

For the example below, we extract an access to the property Value from DerivedClass1. However, only the getter is overridden, which means that the setter being called is the one from BaseClass.

var d1 = new DerivedClass1();
d1.Value = 11;

Furthermore, the function pointer calls are removed from the set of calls where we are interested in reporting missing call targets (as the class of function pointer calls explicitly overrides the getTarget predicate with none()).

@github-actions github-actions Bot added the C# label May 21, 2026
@michaelnebel michaelnebel changed the title C#: Property call targets. C#: Property/Indexer call targets for partial overrides. May 22, 2026
@michaelnebel michaelnebel changed the title C#: Property/Indexer call targets for partial overrides. C#: Property- and Indexer call targets for partial overrides. May 22, 2026
@michaelnebel michaelnebel force-pushed the csharp/propertycalls branch from 7f38b80 to b36175b Compare May 28, 2026 11:47
@michaelnebel michaelnebel force-pushed the csharp/propertycalls branch from b36175b to 0a0867a Compare June 12, 2026 08:08
@michaelnebel michaelnebel requested a review from hvitved June 12, 2026 08:22
@michaelnebel michaelnebel marked this pull request as ready for review June 12, 2026 08:22
@michaelnebel michaelnebel requested a review from a team as a code owner June 12, 2026 08:22
Copilot AI review requested due to automatic review settings June 12, 2026 08:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves C# call target resolution for property and indexer accesses when only one accessor (getter or setter) is overridden, and adjusts call-target quality telemetry to exclude delegate-like calls (including function pointer calls) from “missing target” reporting.

Changes:

  • Add property/indexer accessor “read/write target” resolution that follows override chains to find the effective getter/setter.
  • Update call-target telemetry filtering to exclude DelegateLikeCall rather than only DelegateCall.
  • Extend C# library tests (source + expected outputs) and add a change note covering the behavior change.
Show a summary per file
File Description
csharp/ql/test/library-tests/properties/Properties19.expected Updates expected call-target results to include correct getter/setter targets for partially overridden properties.
csharp/ql/test/library-tests/properties/Properties17.expected Updates expected field list to include the synthesized Value.field.
csharp/ql/test/library-tests/properties/properties.cs Adds a new test scenario covering partial property overrides (getter-only override) and observed call targets.
csharp/ql/test/library-tests/properties/PrintAst.expected Updates AST expectations for the newly added test classes and property calls.
csharp/ql/src/Telemetry/DatabaseQuality.qll Excludes DelegateLikeCall from missing-call-target telemetry classification.
csharp/ql/lib/semmle/code/csharp/Property.qll Adds accessor target resolution helpers for read/write contexts across override chains.
csharp/ql/lib/semmle/code/csharp/exprs/Call.qll Routes PropertyCall/IndexerCall target resolution through the new property/indexer read/write target logic.
csharp/ql/lib/change-notes/2026-05-22-property-indexer-partial-override.md Documents the analysis improvement as a minor analysis change.

Copilot's findings

  • Files reviewed: 8/8 changed files
  • Comments generated: 0

@michaelnebel

Copy link
Copy Markdown
Contributor Author

DCA looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants