Skip to content

Public indexers are emitted as ordinary test class property metadata #7531

Closed

Description

@thomhurst

Summary

Public indexers on test classes are included in generated property metadata even though its getter accepts only an instance and no index arguments. This emits an invalid named-property access for closed classes and can make overloaded indexers ambiguous during metadata initialization. Test classes should be able to declare indexers without breaking discovery.

Reproduction

Add a test class to a TUnit test project:

public class IndexerTests
{
    public string this[int index] => index.ToString();
    [Test]
    public void Runs() { }
}

Build the project and inspect the generated property metadata getter. Also cover generic classes with indexers and two overloaded indexers.

Expected and actual

Expected: omit indexers from property metadata, or define deliberate supported behavior that supplies index arguments. Actual: both property enumeration paths select all public IPropertySymbol members without checking IsIndexer, and GetPropertyAccessor emits a named access without arguments. ReflectionInfo also resolves by name (and sometimes return type) without index parameter types.

Source: MetadataGenerationHelper.cs. The same enumeration is present on main as checked on 2026-11-03. This predates #7524 and was identified while dispositioning its non-blocking review.

Environment

Source commit 60669d5; confirmed by source inspection, reproduction not run locally.

Please handle indexers consistently across metadata collection modes and add generator regression coverage.

Acceptance criteria

  • Exclude indexers from both generated property-metadata enumeration paths while preserving ordinary public property metadata and its counts.
  • Add generator regression snapshots for non-generic classes, generic classes, and overloaded indexers; generated code must compile and metadata initialization must not throw an ambiguous-property exception.
  • Verify the regression fixtures discover and execute in both source-generated and reflection modes.

Triage clarification

Confirmed by source inspection on main at ed2b2ab2366c6e7d8eaaf5b0d48307340ebc0140: both enumeration paths still include indexers. #7524 changes generic getter generation but does not filter indexers, so it does not supersede this issue. Reflection discovery's broader missing class-property metadata is tracked separately in #7522; fixing that gap is not a prerequisite for filtering generated indexers here. No reproduction was run during triage.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium: edge case, mode divergence, flaky test, or workaround existsbugSomething isn't workingin-progressWork is in progress

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions