diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
index 19e3505db39f..ad570b1be3c4 100644
--- a/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
+++ b/src/Compilers/CSharp/Portable/Binder/Binder_Expressions.cs
@@ -1750,10 +1750,7 @@ 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)
- {
- diagnostics.Add(ErrorCode.INF_IdentifierConflictWithContextualKeyword, syntax, name, requiredVersion.ToDisplayString());
- }
+ diagnostics.Add(ErrorCode.INF_IdentifierConflictWithContextualKeyword, syntax, name, requiredVersion.ToDisplayString());
}
break;
}
diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx
index a80bb7e8a116..e38f8308170e 100644
--- a/src/Compilers/CSharp/Portable/CSharpResources.resx
+++ b/src/Compilers/CSharp/Portable/CSharpResources.resx
@@ -6866,7 +6866,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
Compiling requires binding the lambda expression many times. Consider declaring the lambda expression with explicit parameter types, or if the containing method call is generic, consider using explicit type arguments.
- '{0}' is a contextual keyword, with a specific meaning, starting in language version {1}. Use '@{0}' to avoid a breaking change when compiling with language version {1} or later.
+ '{0}' is a contextual keyword in property accessors starting in language version {1}. Use '@{0}' instead.
Identifier is a contextual keyword, with a specific meaning, in a later language version.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
index 61a1a5f35d07..858863c5bb97 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf
@@ -2608,8 +2608,8 @@
-
- '{0}' is a contextual keyword, with a specific meaning, starting in language version {1}. Use '@{0}' to avoid a breaking change when compiling with language version {1} or later.
+
+ '{0}' is a contextual keyword in property accessors starting in language version {1}. Use '@{0}' instead.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
index 22d3090b57e4..3081f74cee2d 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf
@@ -2608,8 +2608,8 @@
-
- '{0}' is a contextual keyword, with a specific meaning, starting in language version {1}. Use '@{0}' to avoid a breaking change when compiling with language version {1} or later.
+
+ '{0}' is a contextual keyword in property accessors starting in language version {1}. Use '@{0}' instead.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
index 1a5bd7a3bdc5..52ff38d31a10 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf
@@ -2608,8 +2608,8 @@
-
- '{0}' is a contextual keyword, with a specific meaning, starting in language version {1}. Use '@{0}' to avoid a breaking change when compiling with language version {1} or later.
+
+ '{0}' is a contextual keyword in property accessors starting in language version {1}. Use '@{0}' instead.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
index f51de573ca84..58c4bb0bc700 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf
@@ -2608,8 +2608,8 @@
-
- '{0}' is a contextual keyword, with a specific meaning, starting in language version {1}. Use '@{0}' to avoid a breaking change when compiling with language version {1} or later.
+
+ '{0}' is a contextual keyword in property accessors starting in language version {1}. Use '@{0}' instead.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
index 65613b4fbd28..c6d538e42c0f 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf
@@ -2608,8 +2608,8 @@
-
- '{0}' is a contextual keyword, with a specific meaning, starting in language version {1}. Use '@{0}' to avoid a breaking change when compiling with language version {1} or later.
+
+ '{0}' is a contextual keyword in property accessors starting in language version {1}. Use '@{0}' instead.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
index 1fe44a2bc159..6e0f70dbe292 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf
@@ -2608,8 +2608,8 @@
-
- '{0}' is a contextual keyword, with a specific meaning, starting in language version {1}. Use '@{0}' to avoid a breaking change when compiling with language version {1} or later.
+
+ '{0}' is a contextual keyword in property accessors starting in language version {1}. Use '@{0}' instead.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
index e6a84fba7134..4428122d0599 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf
@@ -2608,8 +2608,8 @@
-
- '{0}' is a contextual keyword, with a specific meaning, starting in language version {1}. Use '@{0}' to avoid a breaking change when compiling with language version {1} or later.
+
+ '{0}' is a contextual keyword in property accessors starting in language version {1}. Use '@{0}' instead.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
index 2c222144ccde..f15e05c0cbea 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf
@@ -2608,8 +2608,8 @@
-
- '{0}' is a contextual keyword, with a specific meaning, starting in language version {1}. Use '@{0}' to avoid a breaking change when compiling with language version {1} or later.
+
+ '{0}' is a contextual keyword in property accessors starting in language version {1}. Use '@{0}' instead.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
index 2dfcafb5266f..dac8436c4383 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf
@@ -2608,8 +2608,8 @@
-
- '{0}' is a contextual keyword, with a specific meaning, starting in language version {1}. Use '@{0}' to avoid a breaking change when compiling with language version {1} or later.
+
+ '{0}' is a contextual keyword in property accessors starting in language version {1}. Use '@{0}' instead.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
index 3930417dae82..b98477186010 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf
@@ -2608,8 +2608,8 @@
-
- '{0}' is a contextual keyword, with a specific meaning, starting in language version {1}. Use '@{0}' to avoid a breaking change when compiling with language version {1} or later.
+
+ '{0}' is a contextual keyword in property accessors starting in language version {1}. Use '@{0}' instead.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
index ad744f2e1a9e..811de3b857c1 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf
@@ -2608,8 +2608,8 @@
-
- '{0}' is a contextual keyword, with a specific meaning, starting in language version {1}. Use '@{0}' to avoid a breaking change when compiling with language version {1} or later.
+
+ '{0}' is a contextual keyword in property accessors starting in language version {1}. Use '@{0}' instead.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf
index 2d9f977417bf..293573c1e4ef 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf
@@ -2608,8 +2608,8 @@
-
- '{0}' is a contextual keyword, with a specific meaning, starting in language version {1}. Use '@{0}' to avoid a breaking change when compiling with language version {1} or later.
+
+ '{0}' is a contextual keyword in property accessors starting in language version {1}. Use '@{0}' instead.
diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
index bcbc5420069e..a88fb77e8fa1 100644
--- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
+++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf
@@ -2608,8 +2608,8 @@
-
- '{0}' is a contextual keyword, with a specific meaning, starting in language version {1}. Use '@{0}' to avoid a breaking change when compiling with language version {1} or later.
+
+ '{0}' is a contextual keyword in property accessors starting in language version {1}. Use '@{0}' instead.
diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs
index 5887c8eb4196..32bd50f9a7b3 100644
--- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs
+++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDeconstructTests.cs
@@ -1906,7 +1906,7 @@ class C
static int field;
static long x { set { System.Console.WriteLine($""setX {value}""); } }
static string y { get; set; }
- static ref int z { get { return ref field; } }
+ static ref int z { get { return ref @field; } }
static void Main()
{
@@ -1941,7 +1941,7 @@ class C
static int field;
static long x { set { System.Console.WriteLine($""setX {value}""); } }
static string y { get; set; }
- static ref int z { get { return ref field; } }
+ static ref int z { get { return ref @field; } }
static void Main()
{
diff --git a/src/Compilers/CSharp/Test/Emit2/Semantics/RecordTests.cs b/src/Compilers/CSharp/Test/Emit2/Semantics/RecordTests.cs
index fc5a188c754b..d2d97b296fbf 100644
--- a/src/Compilers/CSharp/Test/Emit2/Semantics/RecordTests.cs
+++ b/src/Compilers/CSharp/Test/Emit2/Semantics/RecordTests.cs
@@ -5282,7 +5282,7 @@ record C1(int I1)
public int this[int i] => 0;
public int PropertyWithoutGetter { set { } }
public int P2 { get => 43; }
- public ref int P3 { get => ref field; }
+ public ref int P3 { get => ref @field; }
public event System.Action a;
private int field1 = 100;
diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTests.cs
index 8e550a2a565e..c67dbbdde261 100644
--- a/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTests.cs
+++ b/src/Compilers/CSharp/Test/Semantic/Semantics/BindingAsyncTests.cs
@@ -2313,13 +2313,13 @@ public Task Prop
get
{
Meth(1);
- return field;
+ return @field;
}
set
{
Bar();
Meth("""");
- field = value;
+ @field = value;
}
}
diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InheritanceBindingTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InheritanceBindingTests.cs
index bcd93d2fedcf..f00e3f59dddb 100644
--- a/src/Compilers/CSharp/Test/Semantic/Semantics/InheritanceBindingTests.cs
+++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InheritanceBindingTests.cs
@@ -1907,17 +1907,17 @@ class Base
int field = 0;
public virtual int Proprty1 { get { return 0; } }
- public virtual ref int Property2 { get { return ref field; } }
- public virtual ref int Property3 { get { return ref field; } }
+ public virtual ref int Property2 { get { return ref @field; } }
+ public virtual ref int Property3 { get { return ref @field; } }
}
class Derived : Base
{
int field = 0;
- public override ref int Proprty1 { get { return ref field; } }
+ public override ref int Proprty1 { get { return ref @field; } }
public override int Property2 { get { return 0; } }
- public override ref int Property3 { get { return ref field; } }
+ public override ref int Property3 { get { return ref @field; } }
}
";
CreateCompilationWithMscorlib45(text).VerifyDiagnostics(
diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs
index 645bfc7417e1..c4603025d346 100644
--- a/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs
+++ b/src/Compilers/CSharp/Test/Semantic/Semantics/LambdaTests.cs
@@ -4742,7 +4742,7 @@ public void NullableTypeArraySwitchPattern()
class C
{
object? field;
- string Prop => field switch
+ string Prop => @field switch
{
string?[] a => ""a""
};
@@ -4752,9 +4752,9 @@ class C
// (4,13): warning CS0649: Field 'C.field' is never assigned to, and will always have its default value null
// object? field;
Diagnostic(ErrorCode.WRN_UnassignedInternalField, "field").WithArguments("C.field", "null").WithLocation(4, 13),
- // (5,26): warning CS8509: The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '_' is not covered.
- // string Prop => field switch
- Diagnostic(ErrorCode.WRN_SwitchExpressionNotExhaustive, "switch").WithArguments("_").WithLocation(5, 26));
+ // (5,27): warning CS8509: The switch expression does not handle all possible values of its input type (it is not exhaustive). For example, the pattern '_' is not covered.
+ // string Prop => @field switch
+ Diagnostic(ErrorCode.WRN_SwitchExpressionNotExhaustive, "switch").WithArguments("_").WithLocation(5, 27));
}
[Fact, WorkItem(52827, "https://github.com/dotnet/roslyn/issues/52827")]
@@ -7344,7 +7344,7 @@ public void LambdaWithNonConstantDefault()
class C
{
object field;
- public object Field => field;
+ public object Field => @field;
public C(object f) { field = f; }
@@ -7373,7 +7373,7 @@ public void AnonymousMethodWithNonConstantDefault()
class C
{
object field;
- public object Field => field;
+ public object Field => @field;
public C(object f) { field = f; }
diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
index acc45c67ba33..4d3054f38cf5 100644
--- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
+++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs
@@ -22615,7 +22615,7 @@ public void MemberNotNull_NotFound_PrivateInBase()
public class Base
{
private string? field;
- public string? P { get { return field; } set { field = value; } }
+ public string? P { get { return @field; } set { @field = value; } }
}
public class C : Base
{
@@ -156308,7 +156308,7 @@ class C
public string? field = null;
[MemberNotNullWhen(true, ""field"")]
- public System.Nullable Init => field != null;
+ public System.Nullable Init => @field != null;
public void M()
{
@@ -156349,7 +156349,7 @@ class C
public string? field = null;
[MemberNotNullWhen(true, ""field"")]
- public bool Init => field != null;
+ public bool Init => @field != null;
public void M()
{
@@ -156387,7 +156387,7 @@ class C
public string? field = null;
[MemberNotNullWhen(true, ""field"")]
- public System.Nullable Init => field != null;
+ public System.Nullable Init => @field != null;
public void M()
{
diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs
index f037d2a226ec..fa8b87aff98a 100644
--- a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs
+++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs
@@ -19777,17 +19777,17 @@ ref struct S {
public int field;
public ref int refField;
- ref int Prop1 => ref field; // 1
+ ref int Prop1 => ref @field; // 1
[UnscopedRef]
- ref int Prop2 => ref field; // okay
+ ref int Prop2 => ref @field; // okay
S2 Prop3 => new S2 { S = this }; // Okay
- S Prop4 => new S { refField = ref this.field }; // 2
+ S Prop4 => new S { refField = ref this.@field }; // 2
[UnscopedRef]
- S Prop5 => new S { refField = ref this.field }; // okay
+ S Prop5 => new S { refField = ref this.@field }; // okay
S M1() => new S { refField = ref this.field }; // 3
@@ -19803,11 +19803,11 @@ ref struct S {
var comp = CreateCompilation(source, targetFramework: TargetFramework.Net70);
comp.VerifyDiagnostics(
// (11,26): error CS8170: Struct members cannot return 'this' or other instance members by reference
- // ref int Prop1 => ref field; // 1
- Diagnostic(ErrorCode.ERR_RefReturnStructThis, "field").WithLocation(11, 26),
+ // ref int Prop1 => ref @field; // 1
+ Diagnostic(ErrorCode.ERR_RefReturnStructThis, "@field").WithLocation(11, 26),
// (18,24): error CS8170: Struct members cannot return 'this' or other instance members by reference
- // S Prop4 => new S { refField = ref this.field }; // 2
- Diagnostic(ErrorCode.ERR_RefReturnStructThis, "refField = ref this.field").WithLocation(18, 24),
+ // S Prop4 => new S { refField = ref this.@field }; // 2
+ Diagnostic(ErrorCode.ERR_RefReturnStructThis, "refField = ref this.@field").WithLocation(18, 24),
// (23,23): error CS8170: Struct members cannot return 'this' or other instance members by reference
// S M1() => new S { refField = ref this.field }; // 3
Diagnostic(ErrorCode.ERR_RefReturnStructThis, "refField = ref this.field").WithLocation(23, 23),
diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RefLocalsAndReturnsTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RefLocalsAndReturnsTests.cs
index 729993953655..8dc2ac17f214 100644
--- a/src/Compilers/CSharp/Test/Semantic/Semantics/RefLocalsAndReturnsTests.cs
+++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RefLocalsAndReturnsTests.cs
@@ -4341,7 +4341,7 @@ class C
{
int field = 0;
- ref int P { get { return ref field; } }
+ ref int P { get { return ref @field; } }
ref int this[int i] { get { return ref field; } }
ref int M() { return ref field; }
diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs
index 780a3ed6dcbb..6b9d8dbbb42e 100644
--- a/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs
+++ b/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs
@@ -4010,10 +4010,10 @@ static void N(int q)
// (24,17): error CS0136: A local or parameter named 'value' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
// int value = 0; // CS0136
Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "value").WithArguments("value").WithLocation(24, 17),
- // (24,17): info CS9258: 'value' is a contextual keyword, with a specific meaning, starting in language version preview. Use '@value' to avoid a breaking change when compiling with language version preview or later.
+ // (24,17): info CS9258: 'value' is a contextual keyword in property accessors starting in language version preview. Use '@value' instead.
// int value = 0; // CS0136
Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "value = 0").WithArguments("value", "preview").WithLocation(24, 17),
- // (25,15): info CS9258: 'value' is a contextual keyword, with a specific meaning, starting in language version preview. Use '@value' to avoid a breaking change when compiling with language version preview or later.
+ // (25,15): info CS9258: 'value' is a contextual keyword in property accessors starting in language version preview. Use '@value' instead.
// M(value);
Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "value").WithArguments("value", "preview").WithLocation(25, 15),
// (30,35): error CS0136: A local or parameter named 'q' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
@@ -4028,9 +4028,15 @@ static void N(int q)
// (9,17): error CS0136: A local or parameter named 'y' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
// int y = 0; // CS0136
Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "y").WithArguments("y").WithLocation(9, 17),
+ // (24,17): info CS9258: 'value' is a contextual keyword in property accessors starting in language version preview. Use '@value' instead.
+ // int value = 0; // CS0136
+ Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "value = 0").WithArguments("value", "preview").WithLocation(24, 17),
// (24,17): error CS0136: A local or parameter named 'value' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
// int value = 0; // CS0136
- Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "value").WithArguments("value").WithLocation(24, 17));
+ Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "value").WithArguments("value").WithLocation(24, 17),
+ // (25,15): info CS9258: 'value' is a contextual keyword in property accessors starting in language version preview. Use '@value' instead.
+ // M(value);
+ Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "value").WithArguments("value", "preview").WithLocation(25, 15));
}
[Fact]
diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/InterfaceOverriddenOrHiddenMembersTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/InterfaceOverriddenOrHiddenMembersTests.cs
index 69c6ba4f789d..fdcc6b20cc27 100644
--- a/src/Compilers/CSharp/Test/Symbol/Symbols/InterfaceOverriddenOrHiddenMembersTests.cs
+++ b/src/Compilers/CSharp/Test/Symbol/Symbols/InterfaceOverriddenOrHiddenMembersTests.cs
@@ -1194,7 +1194,7 @@ class DerivedClass : BaseInterface
{
protected int field;
public ref readonly int Method1(in int a) { return ref field; }
- public ref readonly int Property1 { get { return ref field; } }
+ public ref readonly int Property1 { get { return ref @field; } }
public ref readonly int this[int a] { get { return ref field; } }
}";
diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/OverriddenOrHiddenMembersTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/OverriddenOrHiddenMembersTests.cs
index 8e5409c01612..43d9407d60ae 100644
--- a/src/Compilers/CSharp/Test/Symbol/Symbols/OverriddenOrHiddenMembersTests.cs
+++ b/src/Compilers/CSharp/Test/Symbol/Symbols/OverriddenOrHiddenMembersTests.cs
@@ -802,7 +802,7 @@ class Base2 : Base
{
A field = default(A);
public override A Property { set { } }
- public override ref A RefProperty { get { return ref field; } }
+ public override ref A RefProperty { get { return ref @field; } }
}
abstract class Base3 : Base2
@@ -4362,14 +4362,14 @@ class BaseClass
{
protected int field;
public virtual ref readonly int Method1(in BaseClass a) { return ref field; }
- public virtual ref readonly int Property1 { get { return ref field; } }
+ public virtual ref readonly int Property1 { get { return ref @field; } }
public virtual ref readonly int this[int a] { get { return ref field; } }
}
class DerivedClass : BaseClass
{
public override ref readonly int Method1(in BaseClass a) { return ref field; }
- public override ref readonly int Property1 { get { return ref field; } }
+ public override ref readonly int Property1 { get { return ref @field; } }
public override ref readonly int this[int a] { get { return ref field; } }
}";
diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/ExpressionBodiedPropertyTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/ExpressionBodiedPropertyTests.cs
index ad857ae71ef0..c026c48a2251 100644
--- a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/ExpressionBodiedPropertyTests.cs
+++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/ExpressionBodiedPropertyTests.cs
@@ -496,7 +496,7 @@ public void RefReturningExpressionBodiedProperty()
class C
{
int field = 0;
- public ref int P => ref field;
+ public ref int P => ref @field;
}");
comp.VerifyDiagnostics();
@@ -519,7 +519,7 @@ public void RefReadonlyReturningExpressionBodiedProperty()
class C
{
int field = 0;
- public ref readonly int P => ref field;
+ public ref readonly int P => ref @field;
}");
comp.VerifyDiagnostics();
diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/PropertyTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/PropertyTests.cs
index 87b125787796..9cb17023809c 100644
--- a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/PropertyTests.cs
+++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/PropertyTests.cs
@@ -2922,14 +2922,14 @@ public void RefPropertyWithGetterAndSetter()
class C
{
int field = 0;
- ref int P { get { return ref field; } set { } }
+ ref int P { get { return ref @field; } set { } }
}
";
CreateCompilationWithMscorlib45(source).VerifyDiagnostics(
- // (5,47): error CS8081: Properties with by-reference returns cannot have set accessors.
- // ref int P { get { return ref field; } set { } }
- Diagnostic(ErrorCode.ERR_RefPropertyCannotHaveSetAccessor, "set").WithLocation(5, 47));
+ // (5,48): error CS8147: Properties which return by reference cannot have set accessors
+ // ref int P { get { return ref @field; } set { } }
+ Diagnostic(ErrorCode.ERR_RefPropertyCannotHaveSetAccessor, "set").WithLocation(5, 48));
}
[Fact, WorkItem(4696, "https://github.com/dotnet/roslyn/issues/4696")]
diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs
index 97aca352abf8..0eae9509c6c3 100644
--- a/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs
+++ b/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs
@@ -2486,12 +2486,24 @@ public byte MyProp
";
CreateCompilation(text).
VerifyDiagnostics(
- Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "a").WithArguments("a"),
- Diagnostic(ErrorCode.WRN_UnreferencedVar, "a").WithArguments("a"),
- Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "x").WithArguments("x"),
- Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "value").WithArguments("value"),
- Diagnostic(ErrorCode.WRN_UnreferencedVar, "value").WithArguments("value")
- );
+ // (7,14): error CS0136: A local or parameter named 'a' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
+ // long a; // 0136
+ Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "a").WithArguments("a").WithLocation(7, 14),
+ // (7,14): warning CS0168: The variable 'a' is declared but never used
+ // long a; // 0136
+ Diagnostic(ErrorCode.WRN_UnreferencedVar, "a").WithArguments("a").WithLocation(7, 14),
+ // (12,14): error CS0136: A local or parameter named 'x' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
+ // long x = 1; // 0136
+ Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "x").WithArguments("x").WithLocation(12, 14),
+ // (20,17): info CS9258: 'value' is a contextual keyword in property accessors starting in language version preview. Use '@value' instead.
+ // int value; // 0136
+ Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "value").WithArguments("value", "preview").WithLocation(20, 17),
+ // (20,17): error CS0136: A local or parameter named 'value' cannot be declared in this scope because that name is used in an enclosing local scope to define a local or parameter
+ // int value; // 0136
+ Diagnostic(ErrorCode.ERR_LocalIllegallyOverrides, "value").WithArguments("value").WithLocation(20, 17),
+ // (20,17): warning CS0168: The variable 'value' is declared but never used
+ // int value; // 0136
+ Diagnostic(ErrorCode.WRN_UnreferencedVar, "value").WithArguments("value").WithLocation(20, 17));
}
[Fact]
diff --git a/src/Compilers/CSharp/Test/Syntax/Syntax/FieldAndValueKeywordTests.cs b/src/Compilers/CSharp/Test/Syntax/Syntax/FieldAndValueKeywordTests.cs
index 5532bd92677d..d480140254fd 100644
--- a/src/Compilers/CSharp/Test/Syntax/Syntax/FieldAndValueKeywordTests.cs
+++ b/src/Compilers/CSharp/Test/Syntax/Syntax/FieldAndValueKeywordTests.cs
@@ -5,7 +5,6 @@
#nullable disable
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
-using Roslyn.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.CSharp.UnitTests
@@ -34,23 +33,23 @@ class D2 : A { object this[int i] { get => {{identifier}}; } }
class D4 : A { object this[int i] { set { {{identifier}} = 0; } } }
""";
var comp = CreateCompilation(source, parseOptions: TestOptions.Regular.WithLanguageVersion(languageVersion));
- if (escapeIdentifier || languageVersion > LanguageVersion.CSharp12)
+ if (escapeIdentifier)
{
comp.VerifyEmitDiagnostics();
}
else
{
comp.VerifyEmitDiagnostics(
- // (4,28): info CS9258: 'field' is a contextual keyword, with a specific meaning, starting in language version preview. Use '@field' to avoid a breaking change when compiling with language version preview or later.
+ // (4,28): info CS9258: 'field' is a contextual keyword in property accessors starting in language version preview. Use '@field' instead.
// class C1 : A { object P => field; }
Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "field").WithArguments("field", "preview").WithLocation(4, 28),
- // (5,34): info CS9258: 'field' is a contextual keyword, with a specific meaning, starting in language version preview. Use '@field' to avoid a breaking change when compiling with language version preview or later.
+ // (5,34): info CS9258: 'field' is a contextual keyword in property accessors starting in language version preview. Use '@field' instead.
// class C2 : A { object P { get => field; } }
Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "field").WithArguments("field", "preview").WithLocation(5, 34),
- // (6,40): info CS9258: 'field' is a contextual keyword, with a specific meaning, starting in language version preview. Use '@field' to avoid a breaking change when compiling with language version preview or later.
+ // (6,40): info CS9258: 'field' is a contextual keyword in property accessors starting in language version preview. Use '@field' instead.
// class C3 : A { object P { get { return field; } } }
Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "field").WithArguments("field", "preview").WithLocation(6, 40),
- // (7,33): info CS9258: 'field' is a contextual keyword, with a specific meaning, starting in language version preview. Use '@field' to avoid a breaking change when compiling with language version preview or later.
+ // (7,33): info CS9258: 'field' is a contextual keyword in property accessors starting in language version preview. Use '@field' instead.
// class C4 : A { object P { set { field = 0; } } }
Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "field").WithArguments("field", "preview").WithLocation(7, 33));
}
@@ -102,17 +101,17 @@ class D2 : A { object this[int i] { get => this.{{identifier}}; } }
class D4 : A { object this[int i] { set { this.{{identifier}} = 0; } } }
""";
var comp = CreateCompilation(source, parseOptions: TestOptions.Regular.WithLanguageVersion(languageVersion));
- if (escapeIdentifier || languageVersion > LanguageVersion.CSharp12)
+ if (escapeIdentifier)
{
comp.VerifyEmitDiagnostics();
}
else
{
comp.VerifyEmitDiagnostics(
- // (6,38): info CS9258: 'value' is a contextual keyword, with a specific meaning, starting in language version preview. Use '@value' to avoid a breaking change when compiling with language version preview or later.
+ // (6,38): info CS9258: 'value' is a contextual keyword in property accessors starting in language version preview. Use '@value' instead.
// class C4 : A { object P { set { this.value = 0; } } }
Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "value").WithArguments("value", "preview").WithLocation(6, 38),
- // (10,48): info CS9258: 'value' is a contextual keyword, with a specific meaning, starting in language version preview. Use '@value' to avoid a breaking change when compiling with language version preview or later.
+ // (10,48): info CS9258: 'value' is a contextual keyword in property accessors starting in language version preview. Use '@value' instead.
// class D4 : A { object this[int i] { set { this.value = 0; } } }
Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "value").WithArguments("value", "preview").WithLocation(10, 48));
}
@@ -191,7 +190,7 @@ object this[int @value]
// (6,19): error CS0229: Ambiguity between 'int value' and 'object value'
// set { _ = value; }
Diagnostic(ErrorCode.ERR_AmbigMember, "value").WithArguments("int value", "object value").WithLocation(6, 19),
- // (6,19): info CS9258: 'value' is a contextual keyword, with a specific meaning, starting in language version preview. Use '@value' to avoid a breaking change when compiling with language version preview or later.
+ // (6,19): info CS9258: 'value' is a contextual keyword in property accessors starting in language version preview. Use '@value' instead.
// set { _ = value; }
Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "value").WithArguments("value", "preview").WithLocation(6, 19),
// (11,21): error CS0316: The parameter name 'value' conflicts with an automatically-generated parameter name
@@ -232,20 +231,13 @@ event EventHandler E3
}
""";
var comp = CreateCompilation(source, parseOptions: TestOptions.Regular.WithLanguageVersion(languageVersion));
- if (languageVersion > LanguageVersion.CSharp12)
- {
- comp.VerifyEmitDiagnostics();
- }
- else
- {
- comp.VerifyEmitDiagnostics(
- // (14,21): info CS9258: 'value' is a contextual keyword, with a specific meaning, starting in language version preview. Use '@value' to avoid a breaking change when compiling with language version preview or later.
- // add { _ = C.value ?? C.@value; }
- Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "value").WithArguments("value", "preview").WithLocation(14, 21),
- // (15,36): info CS9258: 'value' is a contextual keyword, with a specific meaning, starting in language version preview. Use '@value' to avoid a breaking change when compiling with language version preview or later.
- // remove { _ = C.@value ?? C.value; }
- Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "value").WithArguments("value", "preview").WithLocation(15, 36));
- }
+ comp.VerifyEmitDiagnostics(
+ // (14,21): info CS9258: 'value' is a contextual keyword in property accessors starting in language version preview. Use '@value' instead.
+ // add { _ = C.value ?? C.@value; }
+ Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "value").WithArguments("value", "preview").WithLocation(14, 21),
+ // (15,36): info CS9258: 'value' is a contextual keyword in property accessors starting in language version preview. Use '@value' instead.
+ // remove { _ = C.@value ?? C.value; }
+ Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "value").WithArguments("value", "preview").WithLocation(15, 36));
}
[Theory]
@@ -270,17 +262,17 @@ class C : I
}
""";
var comp = CreateCompilation(source, parseOptions: TestOptions.Regular.WithLanguageVersion(languageVersion));
- if (escapeIdentifier || languageVersion > LanguageVersion.CSharp12)
+ if (escapeIdentifier)
{
comp.VerifyEmitDiagnostics();
}
else
{
comp.VerifyEmitDiagnostics(
- // (10,25): info CS9258: 'field' is a contextual keyword, with a specific meaning, starting in language version preview. Use '@field' to avoid a breaking change when compiling with language version preview or later.
+ // (10,25): info CS9258: 'field' is a contextual keyword in property accessors starting in language version preview. Use '@field' instead.
// object I.P { get => field; set { _ = field; } }
Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "field").WithArguments("field", "preview").WithLocation(10, 25),
- // (10,42): info CS9258: 'field' is a contextual keyword, with a specific meaning, starting in language version preview. Use '@field' to avoid a breaking change when compiling with language version preview or later.
+ // (10,42): info CS9258: 'field' is a contextual keyword in property accessors starting in language version preview. Use '@field' instead.
// object I.P { get => field; set { _ = field; } }
Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "field").WithArguments("field", "preview").WithLocation(10, 42));
}
@@ -308,17 +300,17 @@ class C : I
}
""";
var comp = CreateCompilation(source, parseOptions: TestOptions.Regular.WithLanguageVersion(languageVersion));
- if (escapeIdentifier || languageVersion > LanguageVersion.CSharp12)
+ if (escapeIdentifier)
{
comp.VerifyEmitDiagnostics();
}
else
{
comp.VerifyEmitDiagnostics(
- // (10,52): info CS9258: 'value' is a contextual keyword, with a specific meaning, starting in language version preview. Use '@value' to avoid a breaking change when compiling with language version preview or later.
+ // (10,52): info CS9258: 'value' is a contextual keyword in property accessors starting in language version preview. Use '@value' instead.
// object I.P { get => this.value; set { _ = this.value; } }
Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "value").WithArguments("value", "preview").WithLocation(10, 52),
- // (11,62): info CS9258: 'value' is a contextual keyword, with a specific meaning, starting in language version preview. Use '@value' to avoid a breaking change when compiling with language version preview or later.
+ // (11,62): info CS9258: 'value' is a contextual keyword in property accessors starting in language version preview. Use '@value' instead.
// object I.this[int i] { get => this.value; set { _ = this.value; } }
Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "value").WithArguments("value", "preview").WithLocation(11, 62));
}
@@ -327,6 +319,44 @@ class C : I
[Theory]
[CombinatorialData]
public void ExplicitImplementation_03(
+ [CombinatorialValues(LanguageVersion.CSharp12, LanguageVersion.Preview)] LanguageVersion languageVersion,
+ bool escapeIdentifier)
+ {
+ string identifier = escapeIdentifier ? "@field" : "field";
+ string source = $$"""
+ #pragma warning disable 649
+ interface I
+ {
+ object P { get; set; }
+ object this[int i] { get; set; }
+ }
+ class C : I
+ {
+ int field;
+ object I.P { get => this.{{identifier}}; set { _ = this.{{identifier}}; } }
+ object I.this[int i] { get => this.{{identifier}}; set { _ = this.{{identifier}}; } }
+ }
+ """;
+ var comp = CreateCompilation(source, parseOptions: TestOptions.Regular.WithLanguageVersion(languageVersion));
+ if (escapeIdentifier)
+ {
+ comp.VerifyEmitDiagnostics();
+ }
+ else
+ {
+ comp.VerifyEmitDiagnostics(
+ // (10,30): info CS9258: 'field' is a contextual keyword, with a specific meaning, starting in language version preview. Use '@field' to avoid a breaking change when compiling with language version preview or later.
+ // object I.P { get => this.field; set { _ = this.field; } }
+ Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "field").WithArguments("field", "preview").WithLocation(10, 30),
+ // (10,52): info CS9258: 'field' is a contextual keyword, with a specific meaning, starting in language version preview. Use '@field' to avoid a breaking change when compiling with language version preview or later.
+ // object I.P { get => this.field; set { _ = this.field; } }
+ Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "field").WithArguments("field", "preview").WithLocation(10, 52));
+ }
+ }
+
+ [Theory]
+ [CombinatorialData]
+ public void ExplicitImplementation_04(
[CombinatorialValues(LanguageVersion.CSharp12, LanguageVersion.Preview)] LanguageVersion languageVersion,
[CombinatorialValues("field", "value")] string identifier,
bool escapeIdentifier)
@@ -350,17 +380,17 @@ event EventHandler I.E
}
""";
var comp = CreateCompilation(source, parseOptions: TestOptions.Regular.WithLanguageVersion(languageVersion));
- if (escapeIdentifier || identifier == "field" || languageVersion > LanguageVersion.CSharp12)
+ if (escapeIdentifier || identifier == "field")
{
comp.VerifyEmitDiagnostics();
}
else
{
comp.VerifyEmitDiagnostics(
- // (12,24): info CS9258: 'value' is a contextual keyword, with a specific meaning, starting in language version preview. Use '@value' to avoid a breaking change when compiling with language version preview or later.
+ // (12,24): info CS9258: 'value' is a contextual keyword in property accessors starting in language version preview. Use '@value' instead.
// add { _ = this.value; }
Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "value").WithArguments("value", "preview").WithLocation(12, 24),
- // (13,27): info CS9258: 'value' is a contextual keyword, with a specific meaning, starting in language version preview. Use '@value' to avoid a breaking change when compiling with language version preview or later.
+ // (13,27): info CS9258: 'value' is a contextual keyword in property accessors starting in language version preview. Use '@value' instead.
// remove { _ = this.value; }
Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "value").WithArguments("value", "preview").WithLocation(13, 27));
}
@@ -384,20 +414,13 @@ class C
}
""";
var comp = CreateCompilation(source, parseOptions: TestOptions.Regular.WithLanguageVersion(languageVersion));
- if (languageVersion > LanguageVersion.CSharp12)
- {
- comp.VerifyEmitDiagnostics();
- }
- else
- {
- comp.VerifyEmitDiagnostics(
- // (6,34): info CS9258: 'field' is a contextual keyword, with a specific meaning, starting in language version preview. Use '@field' to avoid a breaking change when compiling with language version preview or later.
- // object P1 { get { return new field(); } }
- Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "field").WithArguments("field", "preview").WithLocation(6, 34),
- // (8,31): info CS9258: 'value' is a contextual keyword, with a specific meaning, starting in language version preview. Use '@value' to avoid a breaking change when compiling with language version preview or later.
- // object P3 { set { _ = new value(); } }
- Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "value").WithArguments("value", "preview").WithLocation(8, 31));
- }
+ comp.VerifyEmitDiagnostics(
+ // (6,34): info CS9258: 'field' is a contextual keyword in property accessors starting in language version preview. Use '@field' instead.
+ // object P1 { get { return new field(); } }
+ Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "field").WithArguments("field", "preview").WithLocation(6, 34),
+ // (8,31): info CS9258: 'value' is a contextual keyword in property accessors starting in language version preview. Use '@value' instead.
+ // object P3 { set { _ = new value(); } }
+ Diagnostic(ErrorCode.INF_IdentifierConflictWithContextualKeyword, "value").WithArguments("value", "preview").WithLocation(8, 31));
}
[Theory]
@@ -418,20 +441,13 @@ class C
}
""";
var comp = CreateCompilation(source, parseOptions: TestOptions.Regular.WithLanguageVersion(languageVersion));
- if (languageVersion > LanguageVersion.CSharp12)
- {
- comp.VerifyEmitDiagnostics();
- }
- else
- {
- comp.VerifyEmitDiagnostics(
- // (6,34): info CS9258: 'field' is a contextual keyword, with a specific meaning, starting in language version preview. Use '@field' to avoid a breaking change when compiling with language version preview or later.
- // object P1 { get { return new field