dotnet / dotnet/csharpstandard

Property & indexer access not fully updated for ref get accessors

Open
#1,371 18 comments 0 reactions 1 assignee Claimed by @jskeet View on GitHub
Dominant language
C#
Stars
815
Forks
99
Avg merge
1d 14h
Merged PRs (30d)
16

Description

In §12.2.2 we have:

> - The value of a property access expression is obtained by invoking the get accessor of the property. If the property has no get accessor, a compile-time error occurs. Otherwise, a function member invocation ([§12.6.6](expressions.md#1266-function-member-invocation)) is performed, and the result of the invocation becomes the value of the property access expression.
> - The value of an indexer access expression is obtained by invoking the get accessor of the indexer. If the indexer has no get accessor, a compile-time error occurs. Otherwise, a function member invocation ([§12.6.6](expressions.md#1266-function-member-invocation)) is performed with the argument list associated with the indexer access expression, and the result of the invocation becomes the value of the indexer access expression.

Both of these do not allow for a property or indexer with a ref get accessor – in such a case a compile-time error does not occur, a value is the result, etc.

Are ref get accessors classified as something other than property/indexer accesses somewhere?

Property access comes under *member_reference*, indexer under *element_access*, do these handle ref get and correctly classify the expression (§12.2), indeed does classification handle ref valued expressions correctly?

Then there is setting a property or indexer element (§12.21.2), is ref get handled correctly in these cases?

Above questions are **not** claimed to be exhaustive.

The above observations come from adding support for `Index` and `Range` (#1369, draft at time of writing) which has added text such as (§12.8.12.3 *Indexer access* in #1369):

> - Using the best indexer determined at binding-time:
> - If the indexer access is the target of an assignment, the set accessor or ref get accessor is invoked to assign a new value ([§12.21.2](expressions.md#12212-simple-assignment)).
> - In all other cases, the get accessor or ref get accesor is invoked to obtain the current value ([§12.2.2](expressions.md#1222-values-of-expressions)).

An ancient (2018 ;-)) issue was raised in csharplang regarding ref get properties, transferred here as #295 years ago (2021 ;-)), and has no milestone…

This surely needs to be sorted for v8.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.