Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open questions for field and value as contextual keywords #8130

Closed
cston opened this issue May 15, 2024 · 2 comments
Closed

Open questions for field and value as contextual keywords #8130

cston opened this issue May 15, 2024 · 2 comments

Comments

@cston
Copy link
Member

cston commented May 15, 2024

Open questions for field and value as contextual keywords

Open questions for field and value as contextual keywords. Some of these issues were raised at the previous LDM discussion.

1. Allow nameof(field) and nameof(value)?

nameof(value) is useful for error reporting, and has an obvious value of "value".

Should nameof(field) also be supported? If so, what is the expected value of nameof(field)?

if (value is null)
    throw new ArgumentNullException(nameof(value));

Console.WriteLine(nameof(field)); // ok?

2. Should value be a keyword in a property or indexer get? Should field be a keyword in an indexer?

value is the implicit parameter for set and init accessors. Should that keyword be allowed in get accessors where there is no implicit parameter?

field is the backing field for non-indexer properties. Should that keyword be allowed in indexers where there is no obvious backing field?

In both cases, the only use of the keywords may be nameof().

object P { get => nameof(value); }

object this[int i]
{
    get { return _list[i]; }
    set { _list[i] = value ?? nameof(field); }
}

3. Should field and value be considered keywords in lambdas and local functions within property accessors?

It seems obvious that field and value should be allowed in nested functions, to allow closures over those values, but confirming that field and value are keywords in nested functions.

4. Should field and value be keywords in property or accessor signatures?

field and value will be considered keywords within accessor bodies. Should they also be considered keywords outside the accessor bodies in the property and accessor signatures?

class await { }
async Task<await> F() => return default; // ok

class field { }
field P { get; set; } // ok?

5. Should nameof(field) and nameof(value) be allowed in property and accessor signatures?

Related to the previous question, but specifically as values using nameof().

[MyAttribute(nameof(field))] object P { get; set; }

object this[string x, string y = nameof(value)] { get; set; }
@TahirAhmadov
Copy link

My opinion: 1, yes, 2, no and no, 3, yes, 4, no, 5, no.

@333fred
Copy link
Member

333fred commented May 21, 2024

@333fred 333fred closed this as completed May 21, 2024
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

No branches or pull requests

3 participants