Skip to content

binding: fix the get accessor check in the indexer lookup - #22

Merged
rameel merged 1 commit into
mainfrom
binding/write-only-indexer
Nov 18, 2026
Merged

rameel merged 1 commit into
mainfrom
binding/write-only-indexer

Conversation

@rameel

@rameel rameel commented Nov 18, 2026

Copy link
Copy Markdown
Owner

The indexer lookup was meant to skip properties without a get accessor, but its check mi?.GetParameters().Length != 0 is true when the accessor is null, because null is not equal to 0. As a result, indexing a value whose type declared a write-only property failed with Object reference not set to an instance of an object, even when the type had a readable indexer. For example, items[1] failed this way when the type of items also had a property such as string Name { set; }. A type with only a write-only indexer failed the same way instead of reporting Cannot apply indexing with [] to an expression of type '…'.

This PR compares the parameter count with > 0, which is false for a missing accessor, both when collecting the indexer candidates and when listing them for an ambiguous match.

The indexer lookup was meant to skip properties without a get
accessor, but its check 'mi?.GetParameters().Length != 0' is true
when the accessor is null, because null is not equal to 0. As a
result, indexing a value whose type declared a write-only property
failed with "Object reference not set to an instance of an object",
even when the type had a readable indexer. A type with only a
write-only indexer failed the same way instead of reporting that
indexing cannot be applied to it.

Compare the parameter count with '> 0', which is false for a missing
accessor, both when collecting the indexer candidates and when
listing them for an ambiguous match.
@rameel
rameel merged commit a6002f2 into main Nov 18, 2026
1 check passed
@rameel
rameel deleted the binding/write-only-indexer branch November 18, 2026 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant