Skip to content

Commit

Permalink
Report diagnostic for field regardless of language version
Browse files Browse the repository at this point in the history
  • Loading branch information
cston committed Jun 12, 2024
1 parent f14fb17 commit 9f69b45
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 13 deletions.
7 changes: 6 additions & 1 deletion src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1750,7 +1750,12 @@ internal void ReportFieldOrValueContextualKeywordConflictIfAny(SyntaxNode syntax
case "value" when ContainingMember() is MethodSymbol { MethodKind: MethodKind.PropertySet or MethodKind.EventAdd or MethodKind.EventRemove }:
{
var requiredVersion = MessageID.IDS_FeatureFieldAndValueKeywords.RequiredVersion();
if (Compilation.LanguageVersion < requiredVersion)
// For "field", report the diagnostic regardless of language version because the meaning will
// definitely change to refer to the backing field. For "value", there's less chance the meaning
// will change since the "value" parameter was in scope previously. Moreover, when compiling
// with later language versions, we won't bind both ways to check if the meaning is different.
// So for "value", we only report the diagnostic for earlier language versions.
if (name == "field" || Compilation.LanguageVersion < requiredVersion)
{
diagnostics.Add(ErrorCode.INF_IdentifierConflictWithContextualKeyword, syntax, name, requiredVersion.ToDisplayString());
}
Expand Down
Loading

0 comments on commit 9f69b45

Please sign in to comment.