dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
19.06k stars 4.04k forks source link

Field-backed properties: support `field` references in speculative `SemanticModel` #75398

Open cston opened 1 month ago

cston commented 1 month ago

Support field references in speculative SemanticModel for property accessors, including for auto-properties and partial properties.

This may require public API support to indicate that a statement or expression should be parsed in the context of an accessor, so that field is treated as keyword.

See related tests PropertyFieldKeywordTests.SpeculativeSemanticModel_* in earlier feature branch features/semi-auto-props.

See also https://github.com/dotnet/roslyn/pull/75904#discussion_r1841648406.

CyrusNajmabadi commented 21 hours ago

Note: i would not expect field in a spec semantic model to bind to anything, if the initial semantic model didn't have field in the prop. But i also would expect it to not crash.