Skip to content

Extension indexers: implicit indexers in list-patterns#82757

Open
jcouv wants to merge 3 commits intodotnet:features/extensionsfrom
jcouv:indexers_11
Open

Extension indexers: implicit indexers in list-patterns#82757
jcouv wants to merge 3 commits intodotnet:features/extensionsfrom
jcouv:indexers_11

Conversation

@jcouv
Copy link
Member

@jcouv jcouv commented Mar 13, 2026

Test plan #81505

Microsoft Reviewers: Open in CodeFlow

@jcouv jcouv marked this pull request as ready for review March 14, 2026 18:06
@jcouv jcouv requested a review from a team as a code owner March 14, 2026 18:06
AnalyzedArguments? actualExtensionLengthOrCountArguments = null;
foreach (var scope in new ExtensionScopes(this))
{
foundApplicable = TryBindExtensionLengthOrCountInScope(node, receiverPlaceholder, scope.Binder, scope,
Copy link
Member

@jjonescz jjonescz Mar 16, 2026

Choose a reason for hiding this comment

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

Should we use this instead of scope.Binder here? #Pending

@jcouv jcouv requested review from AlekseyTs and jjonescz March 16, 2026 16:00
BindingDiagnosticBag diagnostics)
{
Debug.Assert(receiverPlaceholder.Type is not null);
if (receiverPlaceholder.Type.IsSZArray())
Copy link
Contributor

@AlekseyTs AlekseyTs Mar 16, 2026

Choose a reason for hiding this comment

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

receiverPlaceholder.Type.IsSZArray()

Is this ever true for non-list-pattern scenarios? #Pending

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. There are three callers for TryBindNonExtensionLengthOrCount: 1. element access, 2. list-patterns, 3. spreads in collection expressions.
For indexer access, we cannot reach this because array access is treated separately (routed to BindArrayAccess).
But other scenarios can.

I'll add a targeted test (MissingMember_ArrayLength)

if (receiverPlaceholder.Type.IsSZArray())
{
bool foundApplicable = TryGetSpecialTypeMember(Compilation, SpecialMember.System_Array__Length, syntax, diagnostics, out PropertySymbol lengthProperty);
if (lengthProperty is not null)
Copy link
Contributor

@AlekseyTs AlekseyTs Mar 16, 2026

Choose a reason for hiding this comment

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

lengthProperty is not null

Can we assert that this value is equal to foundApplicable? #Pending

{
var reinferenceResult = ReInferMethodAndVisitArguments(
e,
receiverOpt: new BoundExpressionWithNullability(e.Syntax, expression, NullableAnnotation.NotAnnotated, inputType),
Copy link
Contributor

Choose a reason for hiding this comment

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

new BoundExpressionWithNullability(e.Syntax, expression, NullableAnnotation.NotAnnotated, inputType)

I know that we do this in many places, but I am curious why do we create BoundExpressionWithNullability? Are we going to visit this node during ReInferMethodAndVisitArguments? Or is there something else special about this node?

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.

3 participants