diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Lambda.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Lambda.cs index c074ed949d970..210e62ea13aa3 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Lambda.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Lambda.cs @@ -141,9 +141,6 @@ internal partial class Binder case SyntaxKind.ReadOnlyKeyword: Debug.Assert(refKind == RefKind.Ref || syntax.HasErrors); - goto case SyntaxKind.InKeyword; - - case SyntaxKind.InKeyword: refKind = RefKind.RefReadOnly; allValue = false; break; diff --git a/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs b/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs index 560bdd621cad8..c7174e9e43f97 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs +++ b/src/Compilers/CSharp/Portable/CSharpResources.Designer.cs @@ -10622,7 +10622,7 @@ internal static string ERR_RefReturnParameter } /// - /// Looks up a localized string similar to ref or in extension methods. + /// Looks up a localized string similar to ref extension methods. /// internal static string IDS_FeatureRefExtensionMethods { get { diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index 25f13c7c4c23b..85ac9d5523a56 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -5199,7 +5199,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ Field-like events are not allowed in readonly structs. - ref or in extension methods + ref extension methods Conversion of a stackalloc expression of type '{0}' to type '{1}' is not possible. diff --git a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs index cadaa2fd02ac1..18e65a00a7254 100644 --- a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs +++ b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs @@ -3751,7 +3751,6 @@ private bool IsPossibleParameter() case SyntaxKind.OpenBracketToken: // attribute case SyntaxKind.RefKeyword: case SyntaxKind.OutKeyword: - case SyntaxKind.InKeyword: case SyntaxKind.ParamsKeyword: case SyntaxKind.ArgListKeyword: case SyntaxKind.OpenParenToken: // tuple @@ -3875,7 +3874,6 @@ private static bool IsParameterModifier(SyntaxKind kind) case SyntaxKind.RefKeyword: case SyntaxKind.OutKeyword: case SyntaxKind.ParamsKeyword: - case SyntaxKind.InKeyword: case SyntaxKind.ReadOnlyKeyword: return true; } @@ -3895,19 +3893,6 @@ private void ParseParameterModifiers(SyntaxListBuilder modifiers) modifier = CheckFeatureAvailability(modifier, MessageID.IDS_FeatureExtensionMethod); break; - case SyntaxKind.InKeyword: - { - var nextKind = this.CurrentToken.Kind; - - // "in this" - if (nextKind == SyntaxKind.ThisKeyword) - { - modifier = CheckFeatureAvailability(modifier, MessageID.IDS_FeatureRefExtensionMethods); - } - - modifier = CheckFeatureAvailability(modifier, MessageID.IDS_FeatureReadonlyReferences); - break; - } case SyntaxKind.RefKeyword: { var nextKind = this.CurrentToken.Kind; @@ -9866,7 +9851,6 @@ private bool ScanExplicitlyTypedLambda(Precedence precedence) } break; case SyntaxKind.OutKeyword: - case SyntaxKind.InKeyword: case SyntaxKind.ParamsKeyword: this.EatToken(); foundParameterModifier = true; @@ -10865,7 +10849,6 @@ private bool IsPossibleLambdaParameter() // recovery purposes and then give an error during semantic analysis. case SyntaxKind.RefKeyword: case SyntaxKind.OutKeyword: - case SyntaxKind.InKeyword: case SyntaxKind.OpenParenToken: // tuple return true; diff --git a/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs b/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs index 685049fa324e0..7a2c9e807d15f 100644 --- a/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs +++ b/src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs @@ -743,7 +743,9 @@ private void AddParameterRefKindIfRequired(RefKind refKind) AddSpace(); break; case RefKind.RefReadOnly: - AddKeyword(SyntaxKind.InKeyword); + AddKeyword(SyntaxKind.RefKeyword); + AddSpace(); + AddKeyword(SyntaxKind.ReadOnlyKeyword); AddSpace(); break; } diff --git a/src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs b/src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs index eb933e2e94736..9072c95ebc7e6 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Source/ParameterHelpers.cs @@ -140,7 +140,6 @@ internal static void EnsureIsReadOnlyAttributeExists(ImmutableArray x + y; + int this[ref readonly int x, ref readonly int y] => x + y; } "; @@ -144,7 +144,7 @@ .maxstack 3 IL_0000: ldc.i4.s 42 IL_0002: stloc.0 IL_0003: ldloca.s V_0 - IL_0005: call ""ref readonly int Program.M(in int)"" + IL_0005: call ""ref readonly int Program.M(ref readonly int)"" IL_000a: ldind.i4 IL_000b: call ""void System.Console.WriteLine(int)"" IL_0010: newobj ""Program..ctor()"" @@ -154,18 +154,18 @@ .maxstack 3 IL_0019: ldc.i4.6 IL_001a: stloc.1 IL_001b: ldloca.s V_1 - IL_001d: call ""int Program.this[in int, in int].get"" + IL_001d: call ""int Program.this[ref readonly int, ref readonly int].get"" IL_0022: call ""void System.Console.WriteLine(int)"" IL_0027: ldc.i4.s 42 IL_0029: stloc.0 IL_002a: ldloca.s V_0 - IL_002c: call ""ref readonly int Program.M(in int)"" + IL_002c: call ""ref readonly int Program.M(ref readonly int)"" IL_0031: ldind.i4 IL_0032: call ""void System.Console.WriteLine(int)"" IL_0037: ldc.i4.s 42 IL_0039: stloc.0 IL_003a: ldloca.s V_0 - IL_003c: call ""ref readonly int Program.M(in int)"" + IL_003c: call ""ref readonly int Program.M(ref readonly int)"" IL_0041: ldind.i4 IL_0042: call ""void System.Console.WriteLine(int)"" IL_0047: ret @@ -174,7 +174,7 @@ .maxstack 3 [Fact] [CompilerTrait(CompilerFeature.PEVerifyCompat)] - public void InParamPassRoField() + public void RefReadOnlyParamPassRoField() { var text = @" class Program @@ -186,7 +186,7 @@ public static void Main() System.Console.WriteLine(M(F)); } - static ref readonly int M(in int x) + static ref readonly int M(ref readonly int x) { return ref x; } @@ -200,14 +200,14 @@ public static void Main() // Code size 17 (0x11) .maxstack 1 IL_0000: ldsflda ""int Program.F"" - IL_0005: call ""ref readonly int Program.M(in int)"" + IL_0005: call ""ref readonly int Program.M(ref readonly int)"" IL_000a: ldind.i4 IL_000b: call ""void System.Console.WriteLine(int)"" IL_0010: ret }"); - comp.VerifyIL("Program.M(in int)", @" + comp.VerifyIL("Program.M(ref readonly int)", @" { // Code size 2 (0x2) .maxstack 1 @@ -225,7 +225,7 @@ .locals init (int V_0) IL_0000: ldsfld ""int Program.F"" IL_0005: stloc.0 IL_0006: ldloca.s V_0 - IL_0008: call ""ref readonly int Program.M(in int)"" + IL_0008: call ""ref readonly int Program.M(ref readonly int)"" IL_000d: ldind.i4 IL_000e: call ""void System.Console.WriteLine(int)"" IL_0013: ret @@ -234,7 +234,7 @@ .locals init (int V_0) } [Fact] - public void InParamPassRoParamReturn() + public void RefReadOnlyParamPassRoParamReturn() { var text = @" class Program @@ -246,12 +246,12 @@ public static void Main() System.Console.WriteLine(M(F)); } - static ref readonly int M(in int x) + static ref readonly int M(ref readonly int x) { return ref M1(x); } - static ref readonly int M1(in int x) + static ref readonly int M1(ref readonly int x) { return ref x; } @@ -260,18 +260,18 @@ public static void Main() var comp = CompileAndVerify(text, parseOptions: TestOptions.Regular, verify: false, expectedOutput: "42"); - comp.VerifyIL("Program.M(in int)", @" + comp.VerifyIL("Program.M(ref readonly int)", @" { // Code size 7 (0x7) .maxstack 1 IL_0000: ldarg.0 - IL_0001: call ""ref readonly int Program.M1(in int)"" + IL_0001: call ""ref readonly int Program.M1(ref readonly int)"" IL_0006: ret }"); } [Fact] - public void InParamBase() + public void RefReadOnlyParamBase() { var text = @" class Program @@ -287,12 +287,12 @@ public static void Main() System.Console.WriteLine(p.M(42)); } - public Program(in string x) + public Program(ref readonly string x) { SI = x; } - public virtual ref readonly int M(in int x) + public virtual ref readonly int M(ref readonly int x) { return ref x; } @@ -300,9 +300,9 @@ public Program(in string x) class P1 : Program { - public P1(in string x) : base(x){} + public P1(ref readonly string x) : base(x){} - public override ref readonly int M(in int x) + public override ref readonly int M(ref readonly int x) { return ref base.M(x); } @@ -312,23 +312,23 @@ class P1 : Program var comp = CompileAndVerify(text, parseOptions: TestOptions.Regular, verify: false, expectedOutput: @"hi 42"); - comp.VerifyIL("P1..ctor(in string)", @" + comp.VerifyIL("P1..ctor(ref readonly string)", @" { // Code size 8 (0x8) .maxstack 2 IL_0000: ldarg.0 IL_0001: ldarg.1 - IL_0002: call ""Program..ctor(in string)"" + IL_0002: call ""Program..ctor(ref readonly string)"" IL_0007: ret }"); - comp.VerifyIL("P1.M(in int)", @" + comp.VerifyIL("P1.M(ref readonly int)", @" { // Code size 8 (0x8) .maxstack 2 IL_0000: ldarg.0 IL_0001: ldarg.1 - IL_0002: call ""ref readonly int Program.M(in int)"" + IL_0002: call ""ref readonly int Program.M(ref readonly int)"" IL_0007: ret }"); } @@ -348,7 +348,7 @@ class Program var comp = CompileAndVerify(text, parseOptions: TestOptions.Regular, verify: false); - comp.VerifyIL("Program.M(in int)", @" + comp.VerifyIL("Program.M(ref readonly int)", @" { // Code size 2 (0x2) .maxstack 1 @@ -357,49 +357,13 @@ .maxstack 1 }"); } - [Fact] - public void BindingInvalidRefInCombination() - { - var text = @" -class Program -{ - // should be a syntax error - // just make sure binder is ok with this - static ref readonly int M(in ref readonly int x) - { - return ref x; - } - - // should be a syntax error - // just make sure binder is ok with this - static ref readonly int M1( ref in readonly int x) - { - return ref x; - } -} -"; - - var comp = CreateCompilationWithMscorlib45(text, new[] { ValueTupleRef, SystemRuntimeFacadeRef }); - comp.VerifyDiagnostics( - // (6,34): error CS8404: The parameter modifier 'ref' cannot be used with 'in' - // static ref readonly int M(in ref readonly int x) - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "ref").WithArguments("ref", "in").WithLocation(6, 34), - // (6,38): error CS8404: The parameter modifier 'readonly' cannot be used with 'in' - // static ref readonly int M(in ref readonly int x) - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "readonly").WithArguments("readonly", "in").WithLocation(6, 38), - // (13,37): error CS8404: The parameter modifier 'in' cannot be used with 'ref' - // static ref readonly int M1( ref in readonly int x) - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "in").WithArguments("in", "ref").WithLocation(13, 37) - ); - } - [Fact] public void ReadonlyParamCannotAssign() { var text = @" class Program { - static void M(in int arg1, in (int Alice, int Bob) arg2) + static void M(ref readonly int arg1, ref readonly (int Alice, int Bob) arg2) { arg1 = 1; arg2.Alice = 2; @@ -415,24 +379,24 @@ static void M(in int arg1, in (int Alice, int Bob) arg2) var comp = CreateCompilationWithMscorlib45(text, new[] { ValueTupleRef, SystemRuntimeFacadeRef }); comp.VerifyDiagnostics( - // (6,9): error CS8408: Cannot assign to variable 'in int' because it is a readonly variable + // (6,9): error CS8408: Cannot assign to variable 'ref readonly int' because it is a readonly variable // arg1 = 1; - Diagnostic(ErrorCode.ERR_AssignReadonlyNotField, "arg1").WithArguments("variable", "in int").WithLocation(6, 9), - // (7,9): error CS8409: Cannot assign to a member of variable 'in (int Alice, int Bob)' because it is a readonly variable + Diagnostic(ErrorCode.ERR_AssignReadonlyNotField, "arg1").WithArguments("variable", "ref readonly int").WithLocation(6, 9), + // (7,9): error CS8409: Cannot assign to a member of variable 'ref readonly (int Alice, int Bob)' because it is a readonly variable // arg2.Alice = 2; - Diagnostic(ErrorCode.ERR_AssignReadonlyNotField2, "arg2.Alice").WithArguments("variable", "in (int Alice, int Bob)").WithLocation(7, 9), - // (9,9): error CS8408: Cannot assign to variable 'in int' because it is a readonly variable + Diagnostic(ErrorCode.ERR_AssignReadonlyNotField2, "arg2.Alice").WithArguments("variable", "ref readonly (int Alice, int Bob)").WithLocation(7, 9), + // (9,9): error CS8408: Cannot assign to variable 'ref readonly int' because it is a readonly variable // arg1 ++; - Diagnostic(ErrorCode.ERR_AssignReadonlyNotField, "arg1").WithArguments("variable", "in int").WithLocation(9, 9), - // (10,9): error CS8409: Cannot assign to a member of variable 'in (int Alice, int Bob)' because it is a readonly variable + Diagnostic(ErrorCode.ERR_AssignReadonlyNotField, "arg1").WithArguments("variable", "ref readonly int").WithLocation(9, 9), + // (10,9): error CS8409: Cannot assign to a member of variable 'ref readonly (int Alice, int Bob)' because it is a readonly variable // arg2.Alice --; - Diagnostic(ErrorCode.ERR_AssignReadonlyNotField2, "arg2.Alice").WithArguments("variable", "in (int Alice, int Bob)").WithLocation(10, 9), - // (12,9): error CS8408: Cannot assign to variable 'in int' because it is a readonly variable + Diagnostic(ErrorCode.ERR_AssignReadonlyNotField2, "arg2.Alice").WithArguments("variable", "ref readonly (int Alice, int Bob)").WithLocation(10, 9), + // (12,9): error CS8408: Cannot assign to variable 'ref readonly int' because it is a readonly variable // arg1 += 1; - Diagnostic(ErrorCode.ERR_AssignReadonlyNotField, "arg1").WithArguments("variable", "in int"), - // (13,9): error CS8409: Cannot assign to a member of variable 'in (int Alice, int Bob)' because it is a readonly variable + Diagnostic(ErrorCode.ERR_AssignReadonlyNotField, "arg1").WithArguments("variable", "ref readonly int"), + // (13,9): error CS8409: Cannot assign to a member of variable 'ref readonly (int Alice, int Bob)' because it is a readonly variable // arg2.Alice -= 2; - Diagnostic(ErrorCode.ERR_AssignReadonlyNotField2, "arg2.Alice").WithArguments("variable", "in (int Alice, int Bob)")); + Diagnostic(ErrorCode.ERR_AssignReadonlyNotField2, "arg2.Alice").WithArguments("variable", "ref readonly (int Alice, int Bob)")); } [Fact] @@ -441,24 +405,24 @@ public void ReadonlyParamCannotRefReturn() var text = @" class Program { - static ref readonly int M1_baseline(in int arg1, in (int Alice, int Bob) arg2) + static ref readonly int M1_baseline(ref readonly int arg1, ref readonly (int Alice, int Bob) arg2) { // valid return ref arg1; } - static ref readonly int M2_baseline(in int arg1, in (int Alice, int Bob) arg2) + static ref readonly int M2_baseline(ref readonly int arg1, ref readonly (int Alice, int Bob) arg2) { // valid return ref arg2.Alice; } - static ref int M1(in int arg1, in (int Alice, int Bob) arg2) + static ref int M1(ref readonly int arg1, ref readonly (int Alice, int Bob) arg2) { return ref arg1; } - static ref int M2(in int arg1, in (int Alice, int Bob) arg2) + static ref int M2(ref readonly int arg1, ref readonly (int Alice, int Bob) arg2) { return ref arg2.Alice; } @@ -467,12 +431,12 @@ class Program var comp = CreateCompilationWithMscorlib45(text, new[] { ValueTupleRef, SystemRuntimeFacadeRef }); comp.VerifyDiagnostics( - // (18,20): error CS8410: Cannot return variable 'in int' by writable reference because it is a readonly variable + // (18,20): error CS8410: Cannot return variable 'ref readonly int' by writable reference because it is a readonly variable // return ref arg1; - Diagnostic(ErrorCode.ERR_RefReturnReadonlyNotField, "arg1").WithArguments("variable", "in int").WithLocation(18, 20), - // (23,20): error CS8411: Members of variable 'in (int Alice, int Bob)' cannot be returned by writable reference because it is a readonly variable + Diagnostic(ErrorCode.ERR_RefReturnReadonlyNotField, "arg1").WithArguments("variable", "ref readonly int").WithLocation(18, 20), + // (23,20): error CS8411: Members of variable 'ref readonly (int Alice, int Bob)' cannot be returned by writable reference because it is a readonly variable // return ref arg2.Alice; - Diagnostic(ErrorCode.ERR_RefReturnReadonlyNotField2, "arg2.Alice").WithArguments("variable", "in (int Alice, int Bob)").WithLocation(23, 20) + Diagnostic(ErrorCode.ERR_RefReturnReadonlyNotField2, "arg2.Alice").WithArguments("variable", "ref readonly (int Alice, int Bob)").WithLocation(23, 20) ); } @@ -482,7 +446,7 @@ public void ReadonlyParamCannotAssignByref() var text = @" class Program { - static void M(in int arg1, in (int Alice, int Bob) arg2) + static void M(ref readonly int arg1, ref readonly (int Alice, int Bob) arg2) { ref var y = ref arg1; ref int a = ref arg2.Alice; @@ -492,12 +456,12 @@ static void M(in int arg1, in (int Alice, int Bob) arg2) var comp = CreateCompilationWithMscorlib45(text, new[] { ValueTupleRef, SystemRuntimeFacadeRef }); comp.VerifyDiagnostics( - // (6,25): error CS8406: Cannot use variable 'in int' as a ref or out value because it is a readonly variable + // (6,25): error CS8406: Cannot use variable 'ref readonly int' as a ref or out value because it is a readonly variable // ref var y = ref arg1; - Diagnostic(ErrorCode.ERR_RefReadonlyNotField, "arg1").WithArguments("variable", "in int"), - // (7,25): error CS8407: Members of variable 'in (int Alice, int Bob)' cannot be used as a ref or out value because it is a readonly variable + Diagnostic(ErrorCode.ERR_RefReadonlyNotField, "arg1").WithArguments("variable", "ref readonly int"), + // (7,25): error CS8407: Members of variable 'ref readonly (int Alice, int Bob)' cannot be used as a ref or out value because it is a readonly variable // ref int a = ref arg2.Alice; - Diagnostic(ErrorCode.ERR_RefReadonlyNotField2, "arg2.Alice").WithArguments("variable", "in (int Alice, int Bob)")); + Diagnostic(ErrorCode.ERR_RefReadonlyNotField2, "arg2.Alice").WithArguments("variable", "ref readonly (int Alice, int Bob)")); } [Fact] @@ -506,7 +470,7 @@ public void ReadonlyParamCannotTakePtr() var text = @" class Program { - unsafe static void M(in int arg1, in (int Alice, int Bob) arg2) + unsafe static void M(ref readonly int arg1, ref readonly (int Alice, int Bob) arg2) { int* a = & arg1; int* b = & arg2.Alice; @@ -545,7 +509,7 @@ public void ReadonlyParamCannotReturnByOrdinaryRef() var text = @" class Program { - static ref int M(in int arg1, in (int Alice, int Bob) arg2) + static ref int M(ref readonly int arg1, ref readonly (int Alice, int Bob) arg2) { bool b = true; @@ -563,12 +527,12 @@ class Program var comp = CreateCompilationWithMscorlib45(text, new[] { ValueTupleRef, SystemRuntimeFacadeRef }); comp.VerifyDiagnostics( - // (10,24): error CS8410: Cannot return variable 'in int' by writable reference because it is a readonly variable + // (10,24): error CS8410: Cannot return variable 'ref readonly int' by writable reference because it is a readonly variable // return ref arg1; - Diagnostic(ErrorCode.ERR_RefReturnReadonlyNotField, "arg1").WithArguments("variable", "in int").WithLocation(10, 24), - // (14,24): error CS8411: Members of variable 'in (int Alice, int Bob)' cannot be returned by writable reference because it is a readonly variable + Diagnostic(ErrorCode.ERR_RefReturnReadonlyNotField, "arg1").WithArguments("variable", "ref readonly int").WithLocation(10, 24), + // (14,24): error CS8411: Members of variable 'ref readonly (int Alice, int Bob)' cannot be returned by writable reference because it is a readonly variable // return ref arg2.Alice; - Diagnostic(ErrorCode.ERR_RefReturnReadonlyNotField2, "arg2.Alice").WithArguments("variable", "in (int Alice, int Bob)").WithLocation(14, 24) + Diagnostic(ErrorCode.ERR_RefReturnReadonlyNotField2, "arg2.Alice").WithArguments("variable", "ref readonly (int Alice, int Bob)").WithLocation(14, 24) ); } @@ -578,7 +542,7 @@ public void ReadonlyParamCanReturnByRefReadonly() var text = @" class Program { - static ref readonly int M(in int arg1, in (int Alice, int Bob) arg2) + static ref readonly int M(ref readonly int arg1, ref readonly (int Alice, int Bob) arg2) { bool b = true; @@ -616,9 +580,9 @@ public void ReadonlyParamCanReturnByRefReadonlyNested() var text = @" class Program { - static ref readonly int M(in int arg1, in (int Alice, int Bob) arg2) + static ref readonly int M(ref readonly int arg1, ref readonly (int Alice, int Bob) arg2) { - ref readonly int M1(in int arg11, in (int Alice, int Bob) arg21) + ref readonly int M1(ref readonly int arg11, ref readonly (int Alice, int Bob) arg21) { bool b = true; @@ -639,7 +603,7 @@ class Program var comp = CompileAndVerify(text, new[] { ValueTupleRef, SystemRuntimeFacadeRef }, parseOptions: TestOptions.Regular, verify: false); - comp.VerifyIL("Program.g__M1|0_0(in int, in (int Alice, int Bob))", @" + comp.VerifyIL("Program.g__M1|0_0(ref readonly int, ref readonly (int Alice, int Bob))", @" { // Code size 12 (0xc) .maxstack 1 @@ -659,9 +623,9 @@ public void ReadonlyParamCannotReturnByRefNested() var text = @" class Program { - static ref readonly int M(in int arg1, in (int Alice, int Bob) arg2) + static ref readonly int M(ref readonly int arg1, ref readonly (int Alice, int Bob) arg2) { - ref int M1(in int arg11, in (int Alice, int Bob) arg21) + ref int M1(ref readonly int arg11, ref readonly (int Alice, int Bob) arg21) { bool b = true; @@ -682,12 +646,12 @@ class Program var comp = CreateCompilationWithMscorlib45(text, new[] { ValueTupleRef, SystemRuntimeFacadeRef }); comp.VerifyDiagnostics( - // (12,28): error CS8410: Cannot return variable 'in int' by writable reference because it is a readonly variable + // (12,28): error CS8410: Cannot return variable 'ref readonly int' by writable reference because it is a readonly variable // return ref arg11; - Diagnostic(ErrorCode.ERR_RefReturnReadonlyNotField, "arg11").WithArguments("variable", "in int").WithLocation(12, 28), - // (16,28): error CS8411: Members of variable 'in (int Alice, int Bob)' cannot be returned by writable reference because it is a readonly variable + Diagnostic(ErrorCode.ERR_RefReturnReadonlyNotField, "arg11").WithArguments("variable", "ref readonly int").WithLocation(12, 28), + // (16,28): error CS8411: Members of variable 'ref readonly (int Alice, int Bob)' cannot be returned by writable reference because it is a readonly variable // return ref arg21.Alice; - Diagnostic(ErrorCode.ERR_RefReturnReadonlyNotField2, "arg21.Alice").WithArguments("variable", "in (int Alice, int Bob)").WithLocation(16, 28) + Diagnostic(ErrorCode.ERR_RefReturnReadonlyNotField2, "arg21.Alice").WithArguments("variable", "ref readonly (int Alice, int Bob)").WithLocation(16, 28) ); } @@ -702,7 +666,7 @@ static void Main() System.Console.WriteLine(M()); } - static int M(in int x = 42) => x; + static int M(ref readonly int x = 42) => x; } "; @@ -717,7 +681,7 @@ .locals init (int V_0) IL_0000: ldc.i4.s 42 IL_0002: stloc.0 IL_0003: ldloca.s V_0 - IL_0005: call ""int Program.M(in int)"" + IL_0005: call ""int Program.M(ref readonly int)"" IL_000a: call ""void System.Console.WriteLine(int)"" IL_000f: ret }"); @@ -735,7 +699,7 @@ static void Main() System.Console.WriteLine(M(arg)); } - static double M(in double x) => x; + static double M(ref readonly double x) => x; } "; @@ -751,7 +715,7 @@ .locals init (double V_0) IL_0002: conv.r8 IL_0003: stloc.0 IL_0004: ldloca.s V_0 - IL_0006: call ""double Program.M(in double)"" + IL_0006: call ""double Program.M(ref readonly double)"" IL_000b: call ""void System.Console.WriteLine(double)"" IL_0010: ret }"); @@ -781,7 +745,7 @@ public static async Task GetT(T val) return val; } - public static void M1(in int arg1, in int arg2, in int arg3) + public static void M1(ref readonly int arg1, ref readonly int arg2, ref readonly int arg3) { System.Console.WriteLine(arg1 + arg2 + arg3); } @@ -817,7 +781,7 @@ public static async Task GetT(T val) return val; } - public static void M1(in int arg1, in int arg2, in int arg3) + public static void M1(ref readonly int arg1, ref readonly int arg2, ref readonly int arg3) { System.Console.WriteLine(arg1 + arg2 + arg3); } @@ -869,7 +833,7 @@ public static async Task GetT(T val) return val; } - public static void M1(in int arg1, in int arg2, in int arg3, in int arg4) + public static void M1(ref readonly int arg1, ref readonly int arg2, ref readonly int arg3, ref readonly int arg4) { System.Console.WriteLine(arg1); System.Console.WriteLine(arg2); @@ -937,7 +901,7 @@ public static async Task GetT(T val) return val; } - public static void M1(in int arg1, in int arg2, in int arg3, in int arg4) + public static void M1(ref readonly int arg1, ref readonly int arg2, ref readonly int arg3, ref readonly int arg4) { System.Console.WriteLine(arg1); System.Console.WriteLine(arg2); @@ -1000,7 +964,7 @@ public static async Task GetT(T val) return val; } - public static void M1(in int arg1, in int arg2, in int arg3, in int arg4) + public static void M1(ref readonly int arg1, ref readonly int arg2, ref readonly int arg3, ref readonly int arg4) { System.Console.WriteLine(arg1); System.Console.WriteLine(arg2); @@ -1057,7 +1021,7 @@ public static async Task GetT(T val) return val; } - public static void M1(in int arg1, in int arg2, in int arg3, in int arg4) + public static void M1(ref readonly int arg1, ref readonly int arg2, ref readonly int arg3, ref readonly int arg4) { System.Console.WriteLine(arg1); System.Console.WriteLine(arg2); @@ -1117,7 +1081,7 @@ public static async Task GetT(T val) static class Ext { - public static void M1(in this int arg1, in int arg2, in int arg3, in int arg4) + public static void M1(ref readonly this int arg1, ref readonly int arg2, ref readonly int arg3, ref readonly int arg4) { System.Console.WriteLine(arg1); System.Console.WriteLine(arg2); @@ -1202,7 +1166,7 @@ public S1(int val) this.f = val; } - public void M1(in int arg2, in int arg3, in int arg4) + public void M1(ref readonly int arg2, ref readonly int arg3, ref readonly int arg4) { System.Console.WriteLine(this.f); System.Console.WriteLine(arg2); @@ -1283,7 +1247,7 @@ public S1(int val) this.f = val; } - public void M1(in S1 arg2, in S1 arg3, in S1 arg4) + public void M1(ref readonly S1 arg2, ref readonly S1 arg3, ref readonly S1 arg4) { System.Console.WriteLine(this.f); System.Console.WriteLine(arg2.f); @@ -1355,7 +1319,7 @@ .maxstack 4 IL_006c: ldsflda ""S1 Program.s2"" IL_0071: ldloca.s V_1 IL_0073: ldsflda ""S1 Program.s4"" - IL_0078: call ""void S1.M1(in S1, in S1, in S1)"" + IL_0078: call ""void S1.M1(ref readonly S1, ref readonly S1, ref readonly S1)"" IL_007d: leave.s IL_0096 } catch System.Exception @@ -1451,7 +1415,7 @@ .maxstack 4 IL_007a: ldsfld ""S1 Program.s4"" IL_007f: stloc.s V_5 IL_0081: ldloca.s V_5 - IL_0083: call ""void S1.M1(in S1, in S1, in S1)"" + IL_0083: call ""void S1.M1(ref readonly S1, ref readonly S1, ref readonly S1)"" IL_0088: leave.s IL_00a3 } catch System.Exception diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenRefReadonlyReturnTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenRefReadonlyReturnTests.cs index bac7066d2c563..b751b9f0eb7fd 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenRefReadonlyReturnTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenRefReadonlyReturnTests.cs @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Copyright (c) Microsoft Open Technologies, Inc. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; @@ -588,7 +588,7 @@ class Program return ref this[local]; } - ref readonly int this[in int x] => ref x; + ref readonly int this[ref readonly int x] => ref x; } "; @@ -598,9 +598,9 @@ class Program // (8,25): error CS8168: Cannot return local 'local' by reference because it is not a ref local // return ref this[local]; Diagnostic(ErrorCode.ERR_RefReturnLocal, "local").WithArguments("local").WithLocation(8, 25), - // (8,20): error CS8521: Cannot use a result of 'Program.this[in int]' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope + // (8,20): error CS8521: Cannot use a result of 'Program.this[ref readonly int]' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope // return ref this[local]; - Diagnostic(ErrorCode.ERR_EscapeCall, "this[local]").WithArguments("Program.this[in int]", "x").WithLocation(8, 20) + Diagnostic(ErrorCode.ERR_EscapeCall, "this[local]").WithArguments("Program.this[ref readonly int]", "x").WithLocation(8, 20) ); } @@ -615,7 +615,7 @@ class Program return ref this[42]; } - ref readonly int this[in int x] => ref x; + ref readonly int this[ref readonly int x] => ref x; } "; @@ -625,9 +625,9 @@ class Program // (6,25): error CS8156: An expression cannot be used in this context because it may not be returned by reference // return ref this[42]; Diagnostic(ErrorCode.ERR_RefReturnLvalueExpected, "42").WithLocation(6, 25), - // (6,20): error CS8521: Cannot use a result of 'Program.this[in int]' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope + // (6,20): error CS8521: Cannot use a result of 'Program.this[ref readonly int]' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope // return ref this[42]; - Diagnostic(ErrorCode.ERR_EscapeCall, "this[42]").WithArguments("Program.this[in int]", "x").WithLocation(6, 20) + Diagnostic(ErrorCode.ERR_EscapeCall, "this[42]").WithArguments("Program.this[ref readonly int]", "x").WithLocation(6, 20) ); } @@ -645,7 +645,7 @@ struct S1 return ref this; } - ref readonly int this[in int i] => ref x; + ref readonly int this[ref readonly int i] => ref x; } "; @@ -656,8 +656,8 @@ struct S1 // return ref this; Diagnostic(ErrorCode.ERR_RefReturnStructThis, "this").WithArguments("this").WithLocation(8, 20), // (11,44): error CS8170: Struct members cannot return 'this' or other instance members by reference - // ref readonly int this[in int i] => ref x; - Diagnostic(ErrorCode.ERR_RefReturnStructThis, "x").WithArguments("this").WithLocation(11, 44) + // ref readonly int this[ref readonly int i] => ref x; + Diagnostic(ErrorCode.ERR_RefReturnStructThis, "x").WithArguments("this").WithLocation(11, 54) ); } @@ -695,7 +695,7 @@ class Program return ref M(42); } - ref readonly int M(in int x) => ref x; + ref readonly int M(ref readonly int x) => ref x; } "; @@ -705,9 +705,9 @@ class Program // (6,22): error CS8156: An expression cannot be used in this context because it may not be returned by reference // return ref M(42); Diagnostic(ErrorCode.ERR_RefReturnLvalueExpected, "42").WithLocation(6, 22), - // (6,20): error CS8521: Cannot use a result of 'Program.M(in int)' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope + // (6,20): error CS8521: Cannot use a result of 'Program.M(ref readonly int)' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope // return ref M(42); - Diagnostic(ErrorCode.ERR_EscapeCall, "M(42)").WithArguments("Program.M(in int)", "x").WithLocation(6, 20) + Diagnostic(ErrorCode.ERR_EscapeCall, "M(42)").WithArguments("Program.M(ref readonly int)", "x").WithLocation(6, 20) ); } @@ -722,16 +722,16 @@ class Program return ref M(); } - ref readonly int M(in int x = 42) => ref x; + ref readonly int M(ref readonly int x = 42) => ref x; } "; var comp = CreateCompilationWithMscorlib45(text, new[] { ValueTupleRef, SystemRuntimeFacadeRef }); comp.VerifyDiagnostics( - // (6,20): error CS8521: Cannot use a result of 'Program.M(in int)' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope + // (6,20): error CS8521: Cannot use a result of 'Program.M(ref readonly int)' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope // return ref M(); - Diagnostic(ErrorCode.ERR_EscapeCall, "M()").WithArguments("Program.M(in int)", "x").WithLocation(6, 20) + Diagnostic(ErrorCode.ERR_EscapeCall, "M()").WithArguments("Program.M(ref readonly int)", "x").WithLocation(6, 20) ); } @@ -747,7 +747,7 @@ class Program return ref M(b); } - ref readonly int M(in int x) => ref x; + ref readonly int M(ref readonly int x) => ref x; } "; @@ -757,9 +757,9 @@ class Program // (7,22): error CS8156: An expression cannot be used in this context because it may not be returned by reference // return ref M(b); Diagnostic(ErrorCode.ERR_RefReturnLvalueExpected, "b").WithLocation(7, 22), - // (7,20): error CS8521: Cannot use a result of 'Program.M(in int)' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope + // (7,20): error CS8521: Cannot use a result of 'Program.M(ref readonly int)' in this context because it may expose variables referenced by parameter 'x' outside of their declaration scope // return ref M(b); - Diagnostic(ErrorCode.ERR_EscapeCall, "M(b)").WithArguments("Program.M(in int)", "x").WithLocation(7, 20) + Diagnostic(ErrorCode.ERR_EscapeCall, "M(b)").WithArguments("Program.M(ref readonly int)", "x").WithLocation(7, 20) ); } } diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenRefReturnTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenRefReturnTests.cs index 53b0da440e037..7b1ad181d2796 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenRefReturnTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenRefReturnTests.cs @@ -3009,7 +3009,7 @@ public static dynamic F(ref dynamic d) return temp1; } - public static ref dynamic F1(in int arg1, ref dynamic d, in int arg2) + public static ref dynamic F1(ref readonly int arg1, ref dynamic d, ref readonly int arg2) { if (arg1 == arg2) throw null; diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs index 9ad91cd5fd8c7..215e8d8c40ef8 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenStructsAndEnum.cs @@ -2030,7 +2030,7 @@ .maxstack 3 IL_0010: stloc.2 IL_0011: ldloca.s V_2 IL_0013: ldloc.0 - IL_0014: call ""ref readonly S S.RefMethod(in S, in S)"" + IL_0014: call ""ref readonly S S.RefMethod(ref readonly S, ref readonly S)"" IL_0019: ldc.i4.0 IL_001a: call ""S S.I(int)"" IL_001f: stloc.s V_4 @@ -2041,8 +2041,8 @@ .maxstack 3 IL_002a: stloc.s V_5 IL_002c: ldloca.s V_5 IL_002e: ldloc.3 - IL_002f: call ""ref readonly S S.RefMethod(in S, in S)"" - IL_0034: call ""bool S.GreaterThan(in S)"" + IL_002f: call ""ref readonly S S.RefMethod(ref readonly S, ref readonly S)"" + IL_0034: call ""bool S.GreaterThan(ref readonly S)"" IL_0039: call ""void System.Console.WriteLine(bool)"" IL_003e: ret } @@ -2147,7 +2147,7 @@ .maxstack 2 IL_0007: ldc.i4.3 IL_0008: call ""ref S S.I(int)"" IL_000d: ldloc.0 - IL_000e: call ""ref readonly S S.RefMethodRO(in S, in S)"" + IL_000e: call ""ref readonly S S.RefMethodRO(ref readonly S, ref readonly S)"" IL_0013: stloc.1 IL_0014: leave.s IL_002e } @@ -2161,7 +2161,7 @@ .maxstack 2 IL_0020: ldc.i4.3 IL_0021: call ""ref S S.I(int)"" IL_0026: ldloc.0 - IL_0027: call ""ref readonly S S.RefMethodRO(in S, in S)"" + IL_0027: call ""ref readonly S S.RefMethodRO(ref readonly S, ref readonly S)"" IL_002c: pop IL_002d: endfinally } diff --git a/src/Compilers/CSharp/Test/Emit/Emit/InAttributeModifierTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/InAttributeModifierTests.cs index a1f834f571cd1..cd12ec6702f3d 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/InAttributeModifierTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/InAttributeModifierTests.cs @@ -619,9 +619,9 @@ public static void Main() }"; CreateStandardCompilation(code, references: new[] { reference }).VerifyDiagnostics( - // (8,13): error CS0570: 'TestRef.M(in ?)' is not supported by the language + // (8,13): error CS0570: 'TestRef.M(ref readonly ?)' is not supported by the language // obj.M(value); - Diagnostic(ErrorCode.ERR_BindToBogus, "M").WithArguments("TestRef.M(in ?)").WithLocation(8, 13)); + Diagnostic(ErrorCode.ERR_BindToBogus, "M").WithArguments("TestRef.M(ref readonly ?)").WithLocation(8, 13)); } [Fact] @@ -805,9 +805,9 @@ public static void Main() }"; CreateStandardCompilation(code, references: new[] { reference }).VerifyDiagnostics( - // (8,9): error CS1546: Property, indexer, or event 'TestRef.this[in ?]' is not supported by the language; try directly calling accessor method 'TestRef.set_Item(in ?, ?)' + // (8,9): error CS1546: Property, indexer, or event 'TestRef.this[ref readonly ?]' is not supported by the language; try directly calling accessor method 'TestRef.set_Item(ref readonly ?, ?)' // obj[value] = 0; - Diagnostic(ErrorCode.ERR_BindToBogusProp1, "obj[value]").WithArguments("TestRef.this[in ?]", "TestRef.set_Item(in ?, ?)").WithLocation(8, 9)); + Diagnostic(ErrorCode.ERR_BindToBogusProp1, "obj[value]").WithArguments("TestRef.this[ref readonly ?]", "TestRef.set_Item(ref readonly ?, ?)").WithLocation(8, 9)); code = @" public class Test @@ -821,9 +821,9 @@ public static void Main() }"; CreateStandardCompilation(code, references: new[] { reference }).VerifyDiagnostics( - // (8,13): error CS0570: 'TestRef.set_Item(in ?, ?)' is not supported by the language + // (8,13): error CS0570: 'TestRef.set_Item(ref readonly ?, ?)' is not supported by the language // obj.set_Item(value, 0); - Diagnostic(ErrorCode.ERR_BindToBogus, "set_Item").WithArguments("TestRef.set_Item(in ?, ?)").WithLocation(8, 13)); + Diagnostic(ErrorCode.ERR_BindToBogus, "set_Item").WithArguments("TestRef.set_Item(ref readonly ?, ?)").WithLocation(8, 13)); } [Fact] @@ -956,12 +956,12 @@ private static void Process(D func) }"; CreateStandardCompilation(code, references: new[] { reference }).VerifyDiagnostics( - // (6,17): error CS0570: 'D.Invoke(in ?)' is not supported by the language + // (6,17): error CS0570: 'D.Invoke(ref readonly ?)' is not supported by the language // Process((ref readonly int p) => System.Console.WriteLine(p)); - Diagnostic(ErrorCode.ERR_BindToBogus, "(ref readonly int p) => System.Console.WriteLine(p)").WithArguments("D.Invoke(in ?)").WithLocation(6, 17), - // (12,9): error CS0570: 'D.Invoke(in ?)' is not supported by the language + Diagnostic(ErrorCode.ERR_BindToBogus, "(ref readonly int p) => System.Console.WriteLine(p)").WithArguments("D.Invoke(ref readonly ?)").WithLocation(6, 17), + // (12,9): error CS0570: 'D.Invoke(ref readonly ?)' is not supported by the language // func(value); - Diagnostic(ErrorCode.ERR_BindToBogus, "func(value)").WithArguments("D.Invoke(in ?)").WithLocation(12, 9)); + Diagnostic(ErrorCode.ERR_BindToBogus, "func(value)").WithArguments("D.Invoke(ref readonly ?)").WithLocation(12, 9)); } [Fact] @@ -2603,7 +2603,7 @@ public static void Main() Assert.Empty(implicitParameter.RefCustomModifiers); var explicitImplementation = type.GetMethod("Parent.M"); - Assert.Equal("void Parent.M(in modreq(System.Runtime.InteropServices.InAttribute) System.Int32 p)", explicitImplementation.ExplicitInterfaceImplementations.Single().ToTestDisplayString()); + Assert.Equal("void Parent.M(ref readonly modreq(System.Runtime.InteropServices.InAttribute) System.Int32 p)", explicitImplementation.ExplicitInterfaceImplementations.Single().ToTestDisplayString()); var explicitParameter = explicitImplementation.Parameters.Single(); Assert.Empty(explicitParameter.CustomModifiers); @@ -3303,7 +3303,7 @@ public static void Main() Assert.Empty(implicitParameter.RefCustomModifiers); var explicitImplementation = type.GetMethod("Parent.set_Item"); - Assert.Equal("void Parent.this[in modreq(System.Runtime.InteropServices.InAttribute) System.Int32 p].set", explicitImplementation.ExplicitInterfaceImplementations.Single().ToTestDisplayString()); + Assert.Equal("void Parent.this[ref readonly modreq(System.Runtime.InteropServices.InAttribute) System.Int32 p].set", explicitImplementation.ExplicitInterfaceImplementations.Single().ToTestDisplayString()); var explicitParameter = explicitImplementation.Parameters.First(); Assert.Empty(explicitParameter.CustomModifiers); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs index 1e90a1960341f..5fae13d8fffbb 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/OverloadResolutionTests.cs @@ -9376,9 +9376,9 @@ public static void Main() }"; CreateStandardCompilation(code).VerifyDiagnostics( - // (11,16): error CS1503: Argument 1: cannot convert from 'System.Exception' to 'in int' + // (11,16): error CS1503: Argument 1: cannot convert from 'System.Exception' to 'ref readonly int' // Method(x); - Diagnostic(ErrorCode.ERR_BadArgType, "x").WithArguments("1", "System.Exception", "in int").WithLocation(11, 16) + Diagnostic(ErrorCode.ERR_BadArgType, "x").WithArguments("1", "System.Exception", "ref readonly int").WithLocation(11, 16) ); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RefEscapingTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RefEscapingTests.cs index 140a22f07fea6..1c3bcc07f0a54 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RefEscapingTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RefEscapingTests.cs @@ -225,7 +225,7 @@ static void Main() return ref (new int[1])[0]; } - static S1 MayWrap(in int arg) + static S1 MayWrap(ref readonly int arg) { return default; } @@ -278,7 +278,7 @@ static void Main() return ref (new int[1])[0]; } - static S1 MayWrap(in int arg = 123) + static S1 MayWrap(ref readonly int arg = 123) { return default; } @@ -295,9 +295,9 @@ static S1 MayWrap(in int arg = 123) } "; CreateStandardCompilation(text).VerifyDiagnostics( - // (21,30): error CS8521: Cannot use a result of 'Program.MayWrap(in int)' in this context because it may expose variables referenced by parameter 'arg' outside of their declaration scope + // (21,30): error CS8521: Cannot use a result of 'Program.MayWrap(ref readonly int)' in this context because it may expose variables referenced by parameter 'arg' outside of their declaration scope // return ref Test1(MayWrap()); - Diagnostic(ErrorCode.ERR_EscapeCall, "MayWrap()").WithArguments("Program.MayWrap(in int)", "arg").WithLocation(21, 30), + Diagnostic(ErrorCode.ERR_EscapeCall, "MayWrap()").WithArguments("Program.MayWrap(ref readonly int)", "arg").WithLocation(21, 30), // (21,24): error CS8521: Cannot use a result of 'Program.Test1(Program.S1)' in this context because it may expose variables referenced by parameter 'arg' outside of their declaration scope // return ref Test1(MayWrap()); Diagnostic(ErrorCode.ERR_EscapeCall, "Test1(MayWrap())").WithArguments("Program.Test1(Program.S1)", "arg").WithLocation(21, 24) @@ -751,7 +751,7 @@ void Test1() int dummy3 = this[inner, rOuter]; } - int this[in int arg1, in S1 arg2] + int this[ref readonly int arg1, ref readonly S1 arg2] { get { @@ -761,7 +761,7 @@ void Test1() } } - int this[in S1 arg1, in S1 arg2] + int this[ref readonly S1 arg1, ref readonly S1 arg2] { get { @@ -817,7 +817,7 @@ void Test1() int dummy4 = rOuter[inner]; } - static S1 MayWrap(in int arg) + static S1 MayWrap(ref readonly int arg) { return default; } @@ -826,7 +826,7 @@ static S1 MayWrap(in int arg) { public int field; - public int this[in int arg1] + public int this[ref readonly int arg1] { get { @@ -836,7 +836,7 @@ static S1 MayWrap(in int arg) } } - public int this[in S1 arg1] + public int this[ref readonly S1 arg1] { get { @@ -856,21 +856,21 @@ static S1 MayWrap(in int arg) // (23,29): error CS8520: Cannot use local 'rInner' in this context because it may expose referenced variables outside of their declaration scope // int dummy3 = rOuter[rInner]; Diagnostic(ErrorCode.ERR_EscapeLocal, "rInner").WithArguments("rInner").WithLocation(23, 29), - // (23,22): error CS8524: This combination of arguments to 'Program.S1.this[in Program.S1]' is disallowed because it may expose variables referenced by parameter 'arg1' outside of their declaration scope + // (23,22): error CS8524: This combination of arguments to 'Program.S1.this[ref readonly Program.S1]' is disallowed because it may expose variables referenced by parameter 'arg1' outside of their declaration scope // int dummy3 = rOuter[rInner]; - Diagnostic(ErrorCode.ERR_CallArgMixing, "rOuter[rInner]").WithArguments("Program.S1.this[in Program.S1]", "arg1").WithLocation(23, 22), + Diagnostic(ErrorCode.ERR_CallArgMixing, "rOuter[rInner]").WithArguments("Program.S1.this[ref readonly Program.S1]", "arg1").WithLocation(23, 22), // (26,29): error CS8168: Cannot return local 'inner' by reference because it is not a ref local // int dummy4 = rOuter[inner]; Diagnostic(ErrorCode.ERR_RefReturnLocal, "inner").WithArguments("inner").WithLocation(26, 29), - // (26,22): error CS8524: This combination of arguments to 'Program.S1.this[in int]' is disallowed because it may expose variables referenced by parameter 'arg1' outside of their declaration scope + // (26,22): error CS8524: This combination of arguments to 'Program.S1.this[ref readonly int]' is disallowed because it may expose variables referenced by parameter 'arg1' outside of their declaration scope // int dummy4 = rOuter[inner]; - Diagnostic(ErrorCode.ERR_CallArgMixing, "rOuter[inner]").WithArguments("Program.S1.this[in int]", "arg1").WithLocation(26, 22), + Diagnostic(ErrorCode.ERR_CallArgMixing, "rOuter[inner]").WithArguments("Program.S1.this[ref readonly int]", "arg1").WithLocation(26, 22), // (53,32): error CS8167: Cannot return by reference a member of parameter 'arg1' because it is not a ref or out parameter // this = MayWrap(arg1.field); Diagnostic(ErrorCode.ERR_RefReturnParameter2, "arg1").WithArguments("arg1").WithLocation(53, 32), - // (53,24): error CS8521: Cannot use a result of 'Program.MayWrap(in int)' in this context because it may expose variables referenced by parameter 'arg' outside of their declaration scope + // (53,24): error CS8521: Cannot use a result of 'Program.MayWrap(ref readonly int)' in this context because it may expose variables referenced by parameter 'arg' outside of their declaration scope // this = MayWrap(arg1.field); - Diagnostic(ErrorCode.ERR_EscapeCall, "MayWrap(arg1.field)").WithArguments("Program.MayWrap(in int)", "arg").WithLocation(53, 24) + Diagnostic(ErrorCode.ERR_EscapeCall, "MayWrap(arg1.field)").WithArguments("Program.MayWrap(ref readonly int)", "arg").WithLocation(53, 24) ); } @@ -1030,12 +1030,12 @@ void Test1() MayAssign(ref rInner); } - static void MayAssign(ref S1 arg1, in int arg2 = 42) + static void MayAssign(ref S1 arg1, ref readonly int arg2 = 42) { arg1 = MayWrap(arg2); } - static S1 MayWrap(in int arg) + static S1 MayWrap(ref readonly int arg) { return default; } @@ -1046,9 +1046,9 @@ static S1 MayWrap(in int arg) } "; CreateStandardCompilation(text).VerifyDiagnostics( - // (16,13): error CS8524: This combination of arguments to 'Program.MayAssign(ref Program.S1, in int)' is disallowed because it may expose variables referenced by parameter 'arg2' outside of their declaration scope + // (16,13): error CS8524: This combination of arguments to 'Program.MayAssign(ref Program.S1, ref readonly int)' is disallowed because it may expose variables referenced by parameter 'arg2' outside of their declaration scope // MayAssign(ref rOuter); - Diagnostic(ErrorCode.ERR_CallArgMixing, "MayAssign(ref rOuter)").WithArguments("Program.MayAssign(ref Program.S1, in int)", "arg2").WithLocation(16, 13) + Diagnostic(ErrorCode.ERR_CallArgMixing, "MayAssign(ref rOuter)").WithArguments("Program.MayAssign(ref Program.S1, ref readonly int)", "arg2").WithLocation(16, 13) ); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RefExtensionMethodsTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RefExtensionMethodsTests.cs index 38c1d769f8379..a58567552d3cf 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RefExtensionMethodsTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RefExtensionMethodsTests.cs @@ -1294,9 +1294,9 @@ public static void Main() }"; CreateCompilationWithMscorlibAndSystemCore(code).VerifyDiagnostics( - // (6,9): error CS8408: Cannot assign to variable 'in int' because it is a readonly variable + // (6,9): error CS8408: Cannot assign to variable 'ref readonly int' because it is a readonly variable // p++; - Diagnostic(ErrorCode.ERR_AssignReadonlyNotField, "p").WithArguments("variable", "in int").WithLocation(6, 9)); + Diagnostic(ErrorCode.ERR_AssignReadonlyNotField, "p").WithArguments("variable", "ref readonly int").WithLocation(6, 9)); } [Fact] @@ -1388,7 +1388,7 @@ .maxstack 1 IL_0000: ldc.i4.0 IL_0001: stloc.0 IL_0002: ldloca.s V_0 - IL_0004: call ""void Extensions.Print(in int)"" + IL_0004: call ""void Extensions.Print(ref readonly int)"" IL_0009: ret }"); @@ -1456,9 +1456,9 @@ public static void Main() }"; CreateCompilationWithMscorlibAndSystemCore(code).VerifyDiagnostics( - // (14,9): error CS1929: 'int' does not contain a definition for 'Print' and the best extension method overload 'Extensions.Print(in long)' requires a receiver of type 'in long' + // (14,9): error CS1929: 'int' does not contain a definition for 'Print' and the best extension method overload 'Extensions.Print(ref readonly long)' requires a receiver of type 'ref readonly long' // intValue.Print(); // Should be an error - Diagnostic(ErrorCode.ERR_BadInstanceArgType, "intValue").WithArguments("int", "Print", "Extensions.Print(in long)", "in long").WithLocation(14, 9)); + Diagnostic(ErrorCode.ERR_BadInstanceArgType, "intValue").WithArguments("int", "Print", "Extensions.Print(ref readonly long)", "ref readonly long").WithLocation(14, 9)); } [Fact] @@ -1522,9 +1522,9 @@ public static void Main() }"; CreateCompilationWithMscorlibAndSystemCore(code, references: new[] { ValueTupleRef, SystemRuntimeFacadeRef }).VerifyDiagnostics( - // (16,9): error CS1929: '(int intValue1, int intValue2)' does not contain a definition for 'Print' and the best extension method overload 'Extensions.Print(in (long, long))' requires a receiver of type 'in (long, long)' + // (16,9): error CS1929: '(int intValue1, int intValue2)' does not contain a definition for 'Print' and the best extension method overload 'Extensions.Print(ref readonly (long, long))' requires a receiver of type 'ref readonly (long, long)' // intTuple.Print(); // Should be an error - Diagnostic(ErrorCode.ERR_BadInstanceArgType, "intTuple").WithArguments("(int intValue1, int intValue2)", "Print", "Extensions.Print(in (long, long))", "in (long, long)").WithLocation(16, 9)); + Diagnostic(ErrorCode.ERR_BadInstanceArgType, "intTuple").WithArguments("(int intValue1, int intValue2)", "Print", "Extensions.Print(ref readonly (long, long))", "ref readonly (long, long)").WithLocation(16, 9)); } [Fact] @@ -1587,12 +1587,12 @@ public static void Main() }"; CreateCompilationWithMscorlibAndSystemCore(code).VerifyDiagnostics( - // (13,9): error CS1929: 'int' does not contain a definition for 'Print' and the best extension method overload 'Extensions.Print(in int?)' requires a receiver of type 'in int?' + // (13,9): error CS1929: 'int' does not contain a definition for 'Print' and the best extension method overload 'Extensions.Print(ref readonly int?)' requires a receiver of type 'ref readonly int?' // 0.Print(); // Should be an error - Diagnostic(ErrorCode.ERR_BadInstanceArgType, "0").WithArguments("int", "Print", "Extensions.Print(in int?)", "in int?").WithLocation(13, 9), - // (16,9): error CS1929: 'int' does not contain a definition for 'Print' and the best extension method overload 'Extensions.Print(in int?)' requires a receiver of type 'in int?' + Diagnostic(ErrorCode.ERR_BadInstanceArgType, "0").WithArguments("int", "Print", "Extensions.Print(ref readonly int?)", "ref readonly int?").WithLocation(13, 9), + // (16,9): error CS1929: 'int' does not contain a definition for 'Print' and the best extension method overload 'Extensions.Print(ref readonly int?)' requires a receiver of type 'ref readonly int?' // intValue.Print(); // Should be an error - Diagnostic(ErrorCode.ERR_BadInstanceArgType, "intValue").WithArguments("int", "Print", "Extensions.Print(in int?)", "in int?").WithLocation(16, 9)); + Diagnostic(ErrorCode.ERR_BadInstanceArgType, "intValue").WithArguments("int", "Print", "Extensions.Print(ref readonly int?)", "ref readonly int?").WithLocation(16, 9)); } [Fact] @@ -1859,9 +1859,9 @@ public static void Main() }"; CreateCompilationWithMscorlibAndSystemCore(code).VerifyDiagnostics( - // (20,11): error CS0121: The call is ambiguous between the following methods or properties: 'Ext1.Print(ref int)' and 'Ext2.Print(in int)' + // (20,11): error CS0121: The call is ambiguous between the following methods or properties: 'Ext1.Print(ref int)' and 'Ext2.Print(ref readonly int)' // 0.Print(); // Error - Diagnostic(ErrorCode.ERR_AmbigCall, "Print").WithArguments("Ext1.Print(ref int)", "Ext2.Print(in int)").WithLocation(20, 11)); + Diagnostic(ErrorCode.ERR_AmbigCall, "Print").WithArguments("Ext1.Print(ref int)", "Ext2.Print(ref readonly int)").WithLocation(20, 11)); } [Fact] @@ -1895,9 +1895,9 @@ public static void Main() }"; CreateCompilationWithMscorlibAndSystemCore(code).VerifyDiagnostics( - // (21,15): error CS0121: The call is ambiguous between the following methods or properties: 'Ext1.Print(ref int)' and 'Ext2.Print(in int)' + // (21,15): error CS0121: The call is ambiguous between the following methods or properties: 'Ext1.Print(ref int)' and 'Ext2.Print(ref readonly int)' // value.Print(); // Error - Diagnostic(ErrorCode.ERR_AmbigCall, "Print").WithArguments("Ext1.Print(ref int)", "Ext2.Print(in int)").WithLocation(21, 15)); + Diagnostic(ErrorCode.ERR_AmbigCall, "Print").WithArguments("Ext1.Print(ref int)", "Ext2.Print(ref readonly int)").WithLocation(21, 15)); } [Fact] @@ -1917,9 +1917,9 @@ public static void Ref(ref int p) }"; CreateCompilationWithMscorlibAndSystemCore(code).VerifyDiagnostics( - // (6,17): error CS8406: Cannot use variable 'in int' as a ref or out value because it is a readonly variable + // (6,17): error CS8406: Cannot use variable 'ref readonly int' as a ref or out value because it is a readonly variable // Ref(ref p); // Should be an error - Diagnostic(ErrorCode.ERR_RefReadonlyNotField, "p").WithArguments("variable", "in int").WithLocation(6, 17)); + Diagnostic(ErrorCode.ERR_RefReadonlyNotField, "p").WithArguments("variable", "ref readonly int").WithLocation(6, 17)); } [Fact] @@ -1981,12 +1981,12 @@ public static void Main() }"; CreateCompilationWithMscorlibAndSystemCore(code, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp7_1)).VerifyDiagnostics( - // (4,30): error CS8302: Feature 'ref or in extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. + // (4,30): error CS8302: Feature 'ref extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. // public static void Print(ref this int p) - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "ref").WithArguments("ref or in extension methods", "7.2").WithLocation(4, 30), - // (14,9): error CS8302: Feature 'ref or in extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "ref").WithArguments("ref extension methods", "7.2").WithLocation(4, 30), + // (14,9): error CS8302: Feature 'ref extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. // p.Print(); - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "p").WithArguments("ref or in extension methods", "7.2").WithLocation(14, 9) + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "p").WithArguments("ref extension methods", "7.2").WithLocation(14, 9) ); CompileAndVerify(code, additionalRefs: new[] { SystemCoreRef }, expectedOutput: "5"); @@ -2018,17 +2018,17 @@ public static void Main() text: code, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp7_1), references: new[] { reference.ToMetadataReference() }).VerifyDiagnostics( - // (7,9): error CS8302: Feature 'ref or in extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. + // (7,9): error CS8302: Feature 'ref extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. // p.Print(); - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "p").WithArguments("ref or in extension methods", "7.2").WithLocation(7, 9)); + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "p").WithArguments("ref extension methods", "7.2").WithLocation(7, 9)); CreateCompilationWithMscorlibAndSystemCore( text: code, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp7_1), references: new[] { reference.EmitToImageReference() }).VerifyDiagnostics( - // (7,9): error CS8302: Feature 'ref or in extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. + // (7,9): error CS8302: Feature 'ref extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. // p.Print(); - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "p").WithArguments("ref or in extension methods", "7.2").WithLocation(7, 9)); + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "p").WithArguments("ref extension methods", "7.2").WithLocation(7, 9)); CompileAndVerify(code, additionalRefs: new[] { SystemCoreRef, reference.ToMetadataReference() }, expectedOutput: "5"); CompileAndVerify(code, additionalRefs: new[] { SystemCoreRef, reference.EmitToImageReference() }, expectedOutput: "5"); @@ -2058,12 +2058,12 @@ public static void Main() // (4,30): error CS8302: Feature 'readonly references' is not available in C# 7.1. Please use language version 7.2 or greater. // public static void Print(ref readonly this int p) Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "ref").WithArguments("readonly references", "7.2").WithLocation(4, 30), - // (4,30): error CS8302: Feature 'ref or in extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. + // (4,30): error CS8302: Feature 'ref extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. // public static void Print(ref readonly this int p) - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "ref").WithArguments("ref or in extension methods", "7.2").WithLocation(4, 30), - // (14,9): error CS8302: Feature 'ref or in extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "ref").WithArguments("ref extension methods", "7.2").WithLocation(4, 30), + // (14,9): error CS8302: Feature 'ref extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. // p.Print(); - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "p").WithArguments("ref or in extension methods", "7.2").WithLocation(14, 9) + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "p").WithArguments("ref extension methods", "7.2").WithLocation(14, 9) ); CompileAndVerify(code, additionalRefs: new[] { SystemCoreRef }, expectedOutput: "5"); @@ -2095,17 +2095,17 @@ public static void Main() text: code, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp7_1), references: new[] { reference.ToMetadataReference() }).VerifyDiagnostics( - // (7,9): error CS8302: Feature 'ref or in extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. + // (7,9): error CS8302: Feature 'ref extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. // p.Print(); - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "p").WithArguments("ref or in extension methods", "7.2").WithLocation(7, 9)); + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "p").WithArguments("ref extension methods", "7.2").WithLocation(7, 9)); CreateCompilationWithMscorlibAndSystemCore( text: code, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp7_1), references: new[] { reference.EmitToImageReference() }).VerifyDiagnostics( - // (7,9): error CS8302: Feature 'ref or in extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. + // (7,9): error CS8302: Feature 'ref extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. // p.Print(); - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "p").WithArguments("ref or in extension methods", "7.2").WithLocation(7, 9)); + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "p").WithArguments("ref extension methods", "7.2").WithLocation(7, 9)); CompileAndVerify(code, additionalRefs: new[] { SystemCoreRef, reference.ToMetadataReference() }, expectedOutput: "5"); CompileAndVerify(code, additionalRefs: new[] { SystemCoreRef, reference.EmitToImageReference() }, expectedOutput: "5"); @@ -2117,7 +2117,7 @@ public void UsingRefExtensionMethodsBeforeVersion7_2ProducesDiagnostics_InSyntax var code = @" public static class Ext { - public static void Print(in this int p) + public static void Print(ref readonly this int p) { System.Console.WriteLine(p); } @@ -2132,15 +2132,15 @@ public static void Main() }"; CreateCompilationWithMscorlibAndSystemCore(code, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp7_1)).VerifyDiagnostics( - // (4,30): error CS8302: Feature 'ref or in extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. - // public static void Print(in this int p) - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "in").WithArguments("ref or in extension methods", "7.2").WithLocation(4, 30), + // (4,30): error CS8302: Feature 'ref extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. + // public static void Print(ref readonly this int p) + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "ref").WithArguments("ref extension methods", "7.2").WithLocation(4, 30), // (4,30): error CS8302: Feature 'readonly references' is not available in C# 7.1. Please use language version 7.2 or greater. - // public static void Print(in this int p) - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "in").WithArguments("readonly references", "7.2").WithLocation(4, 30), - // (14,9): error CS8302: Feature 'ref or in extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. + // public static void Print(ref readonly this int p) + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "ref").WithArguments("readonly references", "7.2").WithLocation(4, 30), + // (14,9): error CS8302: Feature 'ref extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. // p.Print(); - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "p").WithArguments("ref or in extension methods", "7.2").WithLocation(14, 9) + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "p").WithArguments("ref extension methods", "7.2").WithLocation(14, 9) ); CompileAndVerify(code, additionalRefs: new[] { SystemCoreRef }, expectedOutput: "5"); @@ -2152,7 +2152,7 @@ public void UsingRefExtensionMethodsBeforeVersion7_2ProducesDiagnostics_InSyntax var reference = CreateCompilationWithMscorlibAndSystemCore(@" public static class Ext { - public static void Print(in this int p) + public static void Print(ref readonly this int p) { System.Console.WriteLine(p); } @@ -2172,17 +2172,17 @@ public static void Main() text: code, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp7_1), references: new[] { reference.ToMetadataReference() }).VerifyDiagnostics( - // (7,9): error CS8302: Feature 'ref or in extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. + // (7,9): error CS8302: Feature 'ref extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. // p.Print(); - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "p").WithArguments("ref or in extension methods", "7.2").WithLocation(7, 9)); + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "p").WithArguments("ref extension methods", "7.2").WithLocation(7, 9)); CreateCompilationWithMscorlibAndSystemCore( text: code, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp7_1), references: new[] { reference.EmitToImageReference() }).VerifyDiagnostics( - // (7,9): error CS8302: Feature 'ref or in extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. + // (7,9): error CS8302: Feature 'ref extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. // p.Print(); - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "p").WithArguments("ref or in extension methods", "7.2").WithLocation(7, 9)); + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "p").WithArguments("ref extension methods", "7.2").WithLocation(7, 9)); CompileAndVerify(code, additionalRefs: new[] { SystemCoreRef, reference.ToMetadataReference() }, expectedOutput: "5"); CompileAndVerify(code, additionalRefs: new[] { SystemCoreRef, reference.EmitToImageReference() }, expectedOutput: "5"); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/SpanStackSafetyTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/SpanStackSafetyTests.cs index e21c1fa407628..058a6ff5bc2cd 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/SpanStackSafetyTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/SpanStackSafetyTests.cs @@ -191,12 +191,12 @@ static void M2(out SpanLike ss) } // OK - static void M3(in Span ss) + static void M3(ref readonly Span ss) { } // OK - static void M3l(in SpanLike ss) + static void M3l(ref readonly SpanLike ss) { } diff --git a/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs b/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs index 00e134c8ab872..13ea57425387c 100644 --- a/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs @@ -5496,10 +5496,10 @@ public void RefReadonlyReturn() @"public delegate ref readonly int D(); public class C { - public ref readonly int F(in int i) => ref i; + public ref readonly int F(ref readonly int i) => ref i; int _p; public ref readonly int P => ref _p; - public ref readonly int this[in int i] => ref _p; + public ref readonly int this[ref readonly int i] => ref _p; }"; var compA = CreateStandardCompilation(sourceA); compA.VerifyDiagnostics(); @@ -5565,7 +5565,7 @@ private static void RefReadonlyReturnInternal(Compilation comp) // Method without IncludeRef. Verify( SymbolDisplay.ToDisplayParts(method, formatWithoutRef), - "int F(in int)", + "int F(ref readonly int)", SymbolDisplayPartKind.Keyword, SymbolDisplayPartKind.Space, SymbolDisplayPartKind.MethodName, @@ -5573,6 +5573,8 @@ private static void RefReadonlyReturnInternal(Compilation comp) SymbolDisplayPartKind.Keyword, SymbolDisplayPartKind.Space, SymbolDisplayPartKind.Keyword, + SymbolDisplayPartKind.Space, + SymbolDisplayPartKind.Keyword, SymbolDisplayPartKind.Punctuation); // Property without IncludeRef. @@ -5593,7 +5595,7 @@ private static void RefReadonlyReturnInternal(Compilation comp) // Indexer without IncludeRef. Verify( SymbolDisplay.ToDisplayParts(indexer, formatWithoutRef), - "int this[in int] { get; }", + "int this[ref readonly int] { get; }", SymbolDisplayPartKind.Keyword, SymbolDisplayPartKind.Space, SymbolDisplayPartKind.Keyword, @@ -5601,6 +5603,8 @@ private static void RefReadonlyReturnInternal(Compilation comp) SymbolDisplayPartKind.Keyword, SymbolDisplayPartKind.Space, SymbolDisplayPartKind.Keyword, + SymbolDisplayPartKind.Space, + SymbolDisplayPartKind.Keyword, SymbolDisplayPartKind.Punctuation, SymbolDisplayPartKind.Space, SymbolDisplayPartKind.Punctuation, @@ -5623,7 +5627,7 @@ private static void RefReadonlyReturnInternal(Compilation comp) // Method with IncludeRef. Verify( SymbolDisplay.ToDisplayParts(method, formatWithRef), - "ref readonly int F(in int)", + "ref readonly int F(ref readonly int)", SymbolDisplayPartKind.Keyword, SymbolDisplayPartKind.Space, SymbolDisplayPartKind.Keyword, @@ -5635,6 +5639,8 @@ private static void RefReadonlyReturnInternal(Compilation comp) SymbolDisplayPartKind.Keyword, SymbolDisplayPartKind.Space, SymbolDisplayPartKind.Keyword, + SymbolDisplayPartKind.Space, + SymbolDisplayPartKind.Keyword, SymbolDisplayPartKind.Punctuation); // Property with IncludeRef. @@ -5659,7 +5665,7 @@ private static void RefReadonlyReturnInternal(Compilation comp) // Indexer with IncludeRef. Verify( SymbolDisplay.ToDisplayParts(indexer, formatWithRef), - "ref readonly int this[in int] { get; }", + "ref readonly int this[ref readonly int] { get; }", SymbolDisplayPartKind.Keyword, SymbolDisplayPartKind.Space, SymbolDisplayPartKind.Keyword, @@ -5671,6 +5677,8 @@ private static void RefReadonlyReturnInternal(Compilation comp) SymbolDisplayPartKind.Keyword, SymbolDisplayPartKind.Space, SymbolDisplayPartKind.Keyword, + SymbolDisplayPartKind.Space, + SymbolDisplayPartKind.Keyword, SymbolDisplayPartKind.Punctuation, SymbolDisplayPartKind.Space, SymbolDisplayPartKind.Punctuation, @@ -5697,12 +5705,14 @@ private static void RefReadonlyReturnInternal(Compilation comp) // Method without IncludeType, with IncludeRef. Verify( SymbolDisplay.ToDisplayParts(method, formatWithoutTypeWithRef), - "F(in int)", + "F(ref readonly int)", SymbolDisplayPartKind.MethodName, SymbolDisplayPartKind.Punctuation, SymbolDisplayPartKind.Keyword, SymbolDisplayPartKind.Space, SymbolDisplayPartKind.Keyword, + SymbolDisplayPartKind.Space, + SymbolDisplayPartKind.Keyword, SymbolDisplayPartKind.Punctuation); } @@ -5880,7 +5890,7 @@ class C { void M() { - async unsafe Task Local(in int* x, out char? c) + async unsafe Task Local(ref readonly int* x, out char? c) { } } @@ -5896,7 +5906,7 @@ async unsafe Task Local(in int* x, out char? c) semanticModel.GetDeclaredSymbol(local)); Verify(localSymbol.ToDisplayParts(SymbolDisplayFormat.TestFormat), - "System.Threading.Tasks.Task Local(in System.Int32* x, out System.Char? c)", + "System.Threading.Tasks.Task Local(ref readonly System.Int32* x, out System.Char? c)", SymbolDisplayPartKind.NamespaceName, // System SymbolDisplayPartKind.Punctuation, // . SymbolDisplayPartKind.NamespaceName, // Threading @@ -5912,7 +5922,9 @@ async unsafe Task Local(in int* x, out char? c) SymbolDisplayPartKind.Space, SymbolDisplayPartKind.MethodName, // Local SymbolDisplayPartKind.Punctuation, // ( - SymbolDisplayPartKind.Keyword, // in + SymbolDisplayPartKind.Keyword, // ref + SymbolDisplayPartKind.Space, + SymbolDisplayPartKind.Keyword, // readonly SymbolDisplayPartKind.Space, SymbolDisplayPartKind.NamespaceName, // System SymbolDisplayPartKind.Punctuation, // . diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/InterfaceOverriddenOrHiddenMembersTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/InterfaceOverriddenOrHiddenMembersTests.cs index cb5fdfe81e9cb..4fe51c9406247 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/InterfaceOverriddenOrHiddenMembersTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/InterfaceOverriddenOrHiddenMembersTests.cs @@ -835,9 +835,9 @@ interface B : A }"; var comp = CreateStandardCompilation(code).VerifyDiagnostics( - // (8,10): warning CS0108: 'B.M(in int)' hides inherited member 'A.M(in int)'. Use the new keyword if hiding was intended. + // (8,10): warning CS0108: 'B.M(ref readonly int)' hides inherited member 'A.M(ref readonly int)'. Use the new keyword if hiding was intended. // void M(ref readonly int x); - Diagnostic(ErrorCode.WRN_NewRequired, "M").WithArguments("B.M(in int)", "A.M(in int)").WithLocation(8, 10)); + Diagnostic(ErrorCode.WRN_NewRequired, "M").WithArguments("B.M(ref readonly int)", "A.M(ref readonly int)").WithLocation(8, 10)); var aMethod = comp.GetMember("A.M"); var bMethod = comp.GetMember("B.M"); @@ -1169,9 +1169,9 @@ class B : A }"; var comp = CreateStandardCompilation(code).VerifyDiagnostics( - // (6,11): error CS0535: 'B' does not implement interface member 'A.M(in int)' + // (6,11): error CS0535: 'B' does not implement interface member 'A.M(ref readonly int)' // class B : A - Diagnostic(ErrorCode.ERR_UnimplementedInterfaceMember, "A").WithArguments("B", "A.M(in int)").WithLocation(6, 11)); + Diagnostic(ErrorCode.ERR_UnimplementedInterfaceMember, "A").WithArguments("B", "A.M(ref readonly int)").WithLocation(6, 11)); } [Fact] @@ -1214,9 +1214,9 @@ class ChildClass : BaseInterface }"; var comp = CreateStandardCompilation(text).VerifyDiagnostics( - // (7,20): error CS0535: 'ChildClass' does not implement interface member 'BaseInterface.Method2(in int)' + // (7,20): error CS0535: 'ChildClass' does not implement interface member 'BaseInterface.Method2(ref readonly int)' // class ChildClass : BaseInterface - Diagnostic(ErrorCode.ERR_UnimplementedInterfaceMember, "BaseInterface").WithArguments("ChildClass", "BaseInterface.Method2(in int)").WithLocation(7, 20), + Diagnostic(ErrorCode.ERR_UnimplementedInterfaceMember, "BaseInterface").WithArguments("ChildClass", "BaseInterface.Method2(ref readonly int)").WithLocation(7, 20), // (7,20): error CS0535: 'ChildClass' does not implement interface member 'BaseInterface.Method1(ref int)' // class ChildClass : BaseInterface Diagnostic(ErrorCode.ERR_UnimplementedInterfaceMember, "BaseInterface").WithArguments("ChildClass", "BaseInterface.Method1(ref int)").WithLocation(7, 20)); @@ -1348,9 +1348,9 @@ class B : A }"; var comp = CreateStandardCompilation(code).VerifyDiagnostics( - // (6,11): error CS0535: 'B' does not implement interface member 'A.this[in int]' + // (6,11): error CS0535: 'B' does not implement interface member 'A.this[ref readonly int]' // class B : A - Diagnostic(ErrorCode.ERR_UnimplementedInterfaceMember, "A").WithArguments("B", "A.this[in int]").WithLocation(6, 11)); + Diagnostic(ErrorCode.ERR_UnimplementedInterfaceMember, "A").WithArguments("B", "A.this[ref readonly int]").WithLocation(6, 11)); } [Fact] diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/OverriddenOrHiddenMembersTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/OverriddenOrHiddenMembersTests.cs index d777fd34cf7da..8523a80172f37 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/OverriddenOrHiddenMembersTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/OverriddenOrHiddenMembersTests.cs @@ -4000,9 +4000,9 @@ class B : A }"; var comp = CreateStandardCompilation(code).VerifyDiagnostics( - // (8,17): warning CS0108: 'B.M(in int)' hides inherited member 'A.M(in int)'. Use the new keyword if hiding was intended. + // (8,17): warning CS0108: 'B.M(ref readonly int)' hides inherited member 'A.M(ref readonly int)'. Use the new keyword if hiding was intended. // public void M(ref readonly int x) { } - Diagnostic(ErrorCode.WRN_NewRequired, "M").WithArguments("B.M(in int)", "A.M(in int)").WithLocation(8, 17)); + Diagnostic(ErrorCode.WRN_NewRequired, "M").WithArguments("B.M(ref readonly int)", "A.M(ref readonly int)").WithLocation(8, 17)); var aMethod = comp.GetMember("A.M"); var bMethod = comp.GetMember("B.M"); @@ -4451,9 +4451,9 @@ class ChildClass : BaseClass // (10,26): error CS0115: 'ChildClass.Method2(ref int)': no suitable method found to override // public override void Method2(ref int x) { } Diagnostic(ErrorCode.ERR_OverrideNotExpected, "Method2").WithArguments("ChildClass.Method2(ref int)").WithLocation(10, 26), - // (9,26): error CS0115: 'ChildClass.Method1(in int)': no suitable method found to override + // (9,26): error CS0115: 'ChildClass.Method1(ref readonly int)': no suitable method found to override // public override void Method1(ref readonly int x) { } - Diagnostic(ErrorCode.ERR_OverrideNotExpected, "Method1").WithArguments("ChildClass.Method1(in int)").WithLocation(9, 26)); + Diagnostic(ErrorCode.ERR_OverrideNotExpected, "Method1").WithArguments("ChildClass.Method1(ref readonly int)").WithLocation(9, 26)); } [Fact] @@ -4585,9 +4585,9 @@ class B : A // (8,25): error CS0115: 'B.this[int]': no suitable method found to override // public override int this[int p] { get { return p; } } Diagnostic(ErrorCode.ERR_OverrideNotExpected, "this").WithArguments("B.this[int]").WithLocation(8, 25), - // (6,7): error CS0534: 'B' does not implement inherited abstract member 'A.this[in int].get' + // (6,7): error CS0534: 'B' does not implement inherited abstract member 'A.this[ref readonly int].get' // class B : A - Diagnostic(ErrorCode.ERR_UnimplementedAbstractMethod, "B").WithArguments("B", "A.this[in int].get").WithLocation(6, 7)); + Diagnostic(ErrorCode.ERR_UnimplementedAbstractMethod, "B").WithArguments("B", "A.this[ref readonly int].get").WithLocation(6, 7)); } [Fact] @@ -4605,12 +4605,12 @@ class B : A }"; var comp = CreateStandardCompilation(code).VerifyDiagnostics( - // (8,25): error CS0115: 'B.this[in int]': no suitable method found to override + // (8,25): error CS0115: 'B.this[ref readonly int]': no suitable method found to override // public override int this[ref readonly int p] { get { return p; } } - Diagnostic(ErrorCode.ERR_OverrideNotExpected, "this").WithArguments("B.this[in int]").WithLocation(8, 25), + Diagnostic(ErrorCode.ERR_OverrideNotExpected, "this").WithArguments("B.this[ref readonly int]").WithLocation(8, 25), // (6,7): error CS0534: 'B' does not implement inherited abstract member 'A.this[int].get' // class B : A Diagnostic(ErrorCode.ERR_UnimplementedAbstractMethod, "B").WithArguments("B", "A.this[int].get").WithLocation(6, 7)); } } -} \ No newline at end of file +} diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/DelegateTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/DelegateTests.cs index 7165f8228f507..1707c95f4a5e8 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/DelegateTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/DelegateTests.cs @@ -737,25 +737,6 @@ public void RefReturningDelegate() [Fact] [CompilerTrait(CompilerFeature.ReadOnlyReferences)] public void RefReadonlyReturningDelegate() - { - var source = @"delegate ref readonly int D(in int arg);"; - - var comp = CreateCompilationWithMscorlib45(source); - comp.VerifyDiagnostics(); - - var global = comp.GlobalNamespace; - var d = global.GetMembers("D")[0] as NamedTypeSymbol; - Assert.False(d.DelegateInvokeMethod.ReturnsByRef); - Assert.True(d.DelegateInvokeMethod.ReturnsByRefReadonly); - Assert.Equal(RefKind.RefReadOnly, d.DelegateInvokeMethod.RefKind); - Assert.Equal(RefKind.RefReadOnly, ((MethodSymbol)d.GetMembers("EndInvoke").Single()).RefKind); - - Assert.Equal(RefKind.RefReadOnly, d.DelegateInvokeMethod.Parameters[0].RefKind); - } - - [Fact] - [CompilerTrait(CompilerFeature.ReadOnlyReferences)] - public void RefReadonlyReturningDelegate1() { var source = @"delegate ref readonly int D(ref readonly int arg);"; @@ -778,42 +759,6 @@ public void RefReadonlysInlambda() { var source = @" class C -{ - public delegate ref readonly T DD(in T arg); - - public static void Main() - { - DD d1 = (in int a) => ref a; - - DD d2 = delegate(in int a){return ref a;}; - } -}"; - var tree = SyntaxFactory.ParseSyntaxTree(source, options: TestOptions.Regular); - var compilation = CreateCompilationWithMscorlib45(new SyntaxTree[] { tree }).VerifyDiagnostics(); - - var model = compilation.GetSemanticModel(tree); - - ExpressionSyntax lambdaSyntax = tree.GetCompilationUnitRoot().DescendantNodes().OfType().Single(); - var lambda = (LambdaSymbol)model.GetSymbolInfo(lambdaSyntax).Symbol; - - Assert.False(lambda.ReturnsByRef); - Assert.True(lambda.ReturnsByRefReadonly); - Assert.Equal(lambda.Parameters[0].RefKind, RefKind.RefReadOnly); - - lambdaSyntax = tree.GetCompilationUnitRoot().DescendantNodes().OfType().Single(); - lambda = (LambdaSymbol)model.GetSymbolInfo(lambdaSyntax).Symbol; - - Assert.False(lambda.ReturnsByRef); - Assert.True(lambda.ReturnsByRefReadonly); - Assert.Equal(lambda.Parameters[0].RefKind, RefKind.RefReadOnly); - } - - [Fact] - [CompilerTrait(CompilerFeature.ReadOnlyReferences)] - public void RefReadonlysInlambda1() - { - var source = @" -class C { public delegate ref readonly T DD(ref readonly T arg); diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/ExpressionBodiedPropertyTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/ExpressionBodiedPropertyTests.cs index 6ec7a5bf091b7..9a99242b183a9 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/ExpressionBodiedPropertyTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/ExpressionBodiedPropertyTests.cs @@ -541,7 +541,7 @@ public void RefReadonlyReturningExpressionBodiedIndexer() class C { int field = 0; - public ref readonly int this[in int arg] => ref field; + public ref readonly int this[ref readonly int arg] => ref field; }"); comp.VerifyDiagnostics(); diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs index ab527a9e8b3da..d0c2136432c1d 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs @@ -3148,18 +3148,18 @@ public static class GenExtensions where X : struct [Fact] [CompilerTrait(CompilerFeature.ReadOnlyReferences)] - public void InParametersWouldErrorOutInEarlierCSharpVersions() + public void RefReadOnlyParametersWouldErrorOutInEarlierCSharpVersions() { var code = @" public class Test { - public void DoSomething(in int x) { } + public void DoSomething(ref readonly int x) { } }"; ParseAndValidate(code, new CSharpParseOptions(LanguageVersion.CSharp7), // (4,29): error CS8107: Feature 'readonly references' is not available in C# 7. Please use language version 7.2 or greater. - // public void DoSomething(in int x) { } - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "in").WithArguments("readonly references", "7.2").WithLocation(4, 29) + // public void DoSomething(ref readonly int x) { } + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "ref").WithArguments("readonly references", "7.2").WithLocation(4, 29) ); } @@ -3240,108 +3240,6 @@ public static class GenExtensions Diagnostic(ErrorCode.ERR_BadExtensionAgg, "GenExtensions").WithLocation(12, 21)); } - [Fact] - [CompilerTrait(CompilerFeature.ReadOnlyReferences)] - public void BadInWithThis() - { - var test = @" -public static class Extensions -{ - //No type parameters - public static void Test(this in int i) {} -} -"; - - CreateCompilationWithMscorlibAndSystemCore(test).GetDeclarationDiagnostics().Verify( - // (5,34): error CS8416: The parameter modifier 'in' cannot be used after the modifier 'this' - // public static void Test(this in int i) {} - Diagnostic(ErrorCode.ERR_BadParameterModifiersOrder, "in").WithArguments("in", "this").WithLocation(5, 34)); - } - - [Fact] - [CompilerTrait(CompilerFeature.ReadOnlyReferences)] - public void BadRefWithInParameterModifiers() - { - var test = @" -public class TestType -{ - // No type parameters - public void Method1(ref in int i) { } - public void Method2(in ref int i) { } - - // Single type parameters - public void Method3(ref in int i) { } - public void Method4(in ref int i) { } - - // Multiple type parameters - public void Method5(ref in int i) { } - public void Method6(in ref int i) { } -} -"; - - CreateCompilationWithMscorlibAndSystemCore(test).GetDeclarationDiagnostics().Verify( - // (5,29): error CS8404: The parameter modifier 'in' cannot be used with 'ref' - // public void Method1(ref in int i) { } - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "in").WithArguments("in", "ref").WithLocation(5, 29), - // (6,28): error CS8404: The parameter modifier 'ref' cannot be used with 'in' - // public void Method2(in ref int i) { } - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "ref").WithArguments("ref", "in").WithLocation(6, 28), - // (9,32): error CS8404: The parameter modifier 'in' cannot be used with 'ref' - // public void Method3(ref in int i) { } - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "in").WithArguments("in", "ref").WithLocation(9, 32), - // (10,31): error CS8404: The parameter modifier 'ref' cannot be used with 'in' - // public void Method4(in ref int i) { } - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "ref").WithArguments("ref", "in").WithLocation(10, 31), - // (13,38): error CS8404: The parameter modifier 'in' cannot be used with 'ref' - // public void Method5(ref in int i) { } - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "in").WithArguments("in", "ref").WithLocation(13, 38), - // (14,38): error CS8404: The parameter modifier 'ref' cannot be used with 'in' - // public void Method6(in ref int i) { } - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "ref").WithArguments("ref", "in").WithLocation(14, 38)); - } - - [Fact] - [CompilerTrait(CompilerFeature.ReadOnlyReferences)] - public void BadOutWithInParameterModifiers() - { - var test = @" -public class TestType -{ - // No type parameters - public static void Method1(out in int i) { } - public static void Method2(in out int i) { } - - // Single type parameters - public static void Method3(out in int i) { } - public static void Method4(in out int i) { } - - // Multiple type parameters - public static void Method5(out in int i) { } - public static void Method6(in out int i) { } -} -"; - - CreateCompilationWithMscorlibAndSystemCore(test).GetDeclarationDiagnostics().Verify( - // (5,36): error CS8404: The parameter modifier 'in' cannot be used with 'out' - // public static void Method1(out in int i) { } - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "in").WithArguments("in", "out").WithLocation(5, 36), - // (6,35): error CS8404: The parameter modifier 'out' cannot be used with 'in' - // public static void Method2(in out int i) { } - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "out").WithArguments("out", "in").WithLocation(6, 35), - // (9,39): error CS8404: The parameter modifier 'in' cannot be used with 'out' - // public static void Method3(out in int i) { } - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "in").WithArguments("in", "out").WithLocation(9, 39), - // (10,38): error CS8404: The parameter modifier 'out' cannot be used with 'in' - // public static void Method4(in out int i) { } - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "out").WithArguments("out", "in").WithLocation(10, 38), - // (13,45): error CS8404: The parameter modifier 'in' cannot be used with 'out' - // public static void Method5(out in int i) { } - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "in").WithArguments("in", "out").WithLocation(13, 45), - // (14,44): error CS8404: The parameter modifier 'out' cannot be used with 'in' - // public static void Method6(in out int i) { } - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "out").WithArguments("out", "in").WithLocation(14, 44)); - } - [WorkItem(863402, "DevDiv/Personal")] [Fact] public void CS1104ERR_BadParamModThis() @@ -3526,32 +3424,28 @@ public static class TestType { public static void Test1(ref ref int i) {} public static void Test2(out out int i) {} - public static void Test3(in in int i) {} - public static void Test4(this this int i) {} - public static void Test5(params params int[] i) {} - public static void Test6(ref readonly ref readonly int[] i) {} + public static void Test3(this this int i) {} + public static void Test4(params params int[] i) {} + public static void Test5(ref readonly ref readonly int[] i) {} } "; CreateCompilationWithMscorlibAndSystemCore(test).GetDeclarationDiagnostics().Verify( - // (9,43): error CS1107: A parameter can only have one 'ref' modifier - // public static void Test6(ref readonly ref readonly int[] i) {} - Diagnostic(ErrorCode.ERR_DupParamMod, "ref").WithArguments("ref").WithLocation(9, 43), - // (9,47): error CS1107: A parameter can only have one 'readonly' modifier + // (8,43): error CS1107: A parameter can only have one 'ref' modifier + // public static void Test5(ref readonly ref readonly int[] i) {} + Diagnostic(ErrorCode.ERR_DupParamMod, "ref").WithArguments("ref").WithLocation(8, 43), + // (8,47): error CS1107: A parameter can only have one 'readonly' modifier // public static void Test6(ref readonly ref readonly int[] i) {} - Diagnostic(ErrorCode.ERR_DupParamMod, "readonly").WithArguments("readonly").WithLocation(9, 47), + Diagnostic(ErrorCode.ERR_DupParamMod, "readonly").WithArguments("readonly").WithLocation(8, 47), // (5,34): error CS1107: A parameter can only have one 'out' modifier // public static void Test2(out out int i) {} Diagnostic(ErrorCode.ERR_DupParamMod, "out").WithArguments("out").WithLocation(5, 34), - // (6,33): error CS1107: A parameter can only have one 'in' modifier - // public static void Test3(in in int i) {} - Diagnostic(ErrorCode.ERR_DupParamMod, "in").WithArguments("in").WithLocation(6, 33), - // (7,35): error CS1107: A parameter can only have one 'this' modifier - // public static void Test4(this this int i) {} - Diagnostic(ErrorCode.ERR_DupParamMod, "this").WithArguments("this").WithLocation(7, 35), - // (8,37): error CS1107: A parameter can only have one 'params' modifier - // public static void Test5(params params int[] i) {} - Diagnostic(ErrorCode.ERR_DupParamMod, "params").WithArguments("params").WithLocation(8, 37), + // (6,35): error CS1107: A parameter can only have one 'this' modifier + // public static void Test3(this this int i) {} + Diagnostic(ErrorCode.ERR_DupParamMod, "this").WithArguments("this").WithLocation(6, 35), + // (7,37): error CS1107: A parameter can only have one 'params' modifier + // public static void Test4(params params int[] i) {} + Diagnostic(ErrorCode.ERR_DupParamMod, "params").WithArguments("params").WithLocation(7, 37), // (4,34): error CS1107: A parameter can only have one 'ref' modifier // public static void Test1(ref ref int i) {} Diagnostic(ErrorCode.ERR_DupParamMod, "ref").WithArguments("ref").WithLocation(4, 34)); @@ -3599,57 +3493,6 @@ public class TestType Diagnostic(ErrorCode.ERR_DupParamMod, "ref").WithArguments("ref").WithLocation(14, 41)); } - [Fact] - [CompilerTrait(CompilerFeature.ReadOnlyReferences)] - public void BadRefReadOnlyWithInParameterModifiers() - { - var test = @" -public class TestType -{ -// No type parameters -public static void Method1(ref readonly in int i) { } -public static void Method2(in ref readonly int i) { } - -// Single type parameters -public static void Method3(ref readonly in int i) { } -public static void Method4(in ref readonly int i) { } - -// Multiple type parameters -public static void Method5(ref readonly in int i) { } -public static void Method6(in ref readonly int i) { } -} -"; - - CreateCompilationWithMscorlibAndSystemCore(test).GetDeclarationDiagnostics().Verify( - // (5,41): error CS8404: The parameter modifier 'in' cannot be used with 'ref' - // public static void Method1(ref readonly in int i) { } - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "in").WithArguments("in", "ref").WithLocation(5, 41), - // (6,31): error CS8404: The parameter modifier 'ref' cannot be used with 'in' - // public static void Method2(in ref readonly int i) { } - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "ref").WithArguments("ref", "in").WithLocation(6, 31), - // (6,35): error CS8404: The parameter modifier 'readonly' cannot be used with 'in' - // public static void Method2(in ref readonly int i) { } - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "readonly").WithArguments("readonly", "in").WithLocation(6, 35), - // (9,44): error CS8404: The parameter modifier 'in' cannot be used with 'ref' - // public static void Method3(ref readonly in int i) { } - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "in").WithArguments("in", "ref").WithLocation(9, 44), - // (10,34): error CS8404: The parameter modifier 'ref' cannot be used with 'in' - // public static void Method4(in ref readonly int i) { } - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "ref").WithArguments("ref", "in").WithLocation(10, 34), - // (10,38): error CS8404: The parameter modifier 'readonly' cannot be used with 'in' - // public static void Method4(in ref readonly int i) { } - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "readonly").WithArguments("readonly", "in").WithLocation(10, 38), - // (13,50): error CS8404: The parameter modifier 'in' cannot be used with 'ref' - // public static void Method5(ref readonly in int i) { } - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "in").WithArguments("in", "ref").WithLocation(13, 50), - // (14,40): error CS8404: The parameter modifier 'ref' cannot be used with 'in' - // public static void Method6(in ref readonly int i) { } - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "ref").WithArguments("ref", "in").WithLocation(14, 40), - // (14,44): error CS8404: The parameter modifier 'readonly' cannot be used with 'in' - // public static void Method6(in ref readonly int i) { } - Diagnostic(ErrorCode.ERR_BadParameterModifiers, "readonly").WithArguments("readonly", "in").WithLocation(14, 44)); - } - [Fact] [CompilerTrait(CompilerFeature.ReadOnlyReferences)] public void BadRefReadOnlyWithThisParameterModifiers() @@ -3794,70 +3637,6 @@ public class TestType Diagnostic(ErrorCode.ERR_BadParameterModifiers, "readonly").WithArguments("readonly", "out").WithLocation(14, 45)); } - [Fact] - [CompilerTrait(CompilerFeature.ReadOnlyReferences)] - public void InParametersAreParsedCorrectly() - { - var test = @" -public class Test -{ - public delegate int Delegate(in int a); - - public void Method(in int b) - { - void localFunc(in int c) { } - - Delegate lambda = (in int d) => d; - - Delegate anonymousDelegate = delegate (in int e) { return e; }; - } - - public int this [in int f] - { - get { return f; } - } - - public static bool operator ! (in Test g) - { - return false; - } -} -"; - - var tree = ParseTree(test, TestOptions.Regular); - tree.GetDiagnostics().Verify(); - - var methodDeclaration = (MethodDeclarationSyntax)tree.GetRoot().DescendantNodes().Single(node => node is MethodDeclarationSyntax); - verifyModifier(methodDeclaration.ParameterList.Parameters); - - var delegateDeclaration = (DelegateDeclarationSyntax)tree.GetRoot().DescendantNodes().Single(node => node is DelegateDeclarationSyntax); - verifyModifier(delegateDeclaration.ParameterList.Parameters); - - var localFunctionStatement = (LocalFunctionStatementSyntax)tree.GetRoot().DescendantNodes().Single(node => node is LocalFunctionStatementSyntax); - verifyModifier(localFunctionStatement.ParameterList.Parameters); - - var lambdaExpression = (ParenthesizedLambdaExpressionSyntax)tree.GetRoot().DescendantNodes().Single(node => node is ParenthesizedLambdaExpressionSyntax); - verifyModifier(lambdaExpression.ParameterList.Parameters); - - var anonymousMethodExpression = (AnonymousMethodExpressionSyntax)tree.GetRoot().DescendantNodes().Single(node => node is AnonymousMethodExpressionSyntax); - verifyModifier(anonymousMethodExpression.ParameterList.Parameters); - - var indexerDeclaration = (IndexerDeclarationSyntax)tree.GetRoot().DescendantNodes().Single(node => node is IndexerDeclarationSyntax); - verifyModifier(indexerDeclaration.ParameterList.Parameters); - - var operatorDeclaration = (OperatorDeclarationSyntax)tree.GetRoot().DescendantNodes().Single(node => node is OperatorDeclarationSyntax); - verifyModifier(operatorDeclaration.ParameterList.Parameters); - - void verifyModifier(SeparatedSyntaxList list) - { - var parameter = list.Single(); - Assert.Equal(1, parameter.Modifiers.Count); - - var modifier = parameter.Modifiers.First(); - Assert.Equal(SyntaxKind.InKeyword, modifier.Kind()); - } - } - [Fact] [CompilerTrait(CompilerFeature.ReadOnlyReferences)] public void RefReadonlyParametersAreParsedCorrectly() @@ -5142,15 +4921,11 @@ public static void ParamsWithRef(params ref int[] a) public static void ParamsWithOut(params out int[] a) { } - public static void ParamsWithIn(params in int[] a) - { - } public static int Main() { int i = 10; ParamsWithRef(ref i); ParamsWithOut(out i); - ParamsWithOut(i); return 1; } } @@ -5162,10 +4937,7 @@ public static int Main() Diagnostic(ErrorCode.ERR_ParamsCantBeWithModifier, "ref").WithArguments("ref").WithLocation(4, 45), // (7,45): error CS1611: The params parameter cannot be declared as out // public static void ParamsWithOut(params out int[] a) - Diagnostic(ErrorCode.ERR_ParamsCantBeWithModifier, "out").WithArguments("out").WithLocation(7, 45), - // (10,44): error CS1611: The params parameter cannot be declared as in - // public static void ParamsWithIn(params in int[] a) - Diagnostic(ErrorCode.ERR_ParamsCantBeWithModifier, "in").WithArguments("in").WithLocation(10, 44)); + Diagnostic(ErrorCode.ERR_ParamsCantBeWithModifier, "out").WithArguments("out").WithLocation(7, 45)); } [Fact] @@ -5845,42 +5617,9 @@ public static void Main() // (4,30): error CS8302: Feature 'readonly references' is not available in C# 7.1. Please use language version 7.2 or greater. // public static void Print(ref readonly this int p) Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "ref").WithArguments("readonly references", "7.2").WithLocation(4, 30), - // (4,30): error CS8302: Feature 'ref or in extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. + // (4,30): error CS8302: Feature 'ref extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. // public static void Print(ref readonly this int p) - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "ref").WithArguments("ref or in extension methods", "7.2").WithLocation(4, 30) - ); - - CompileAndVerify(code, additionalRefs: new[] { SystemCoreRef }, expectedOutput: "5"); - } - - [Fact] - public void RefExtensionMethodsNotSupportedBefore7_2_InSyntax() - { - var code = @" -public static class Extensions -{ - public static void Print(in this int p) - { - System.Console.WriteLine(p); - } -} -public static class Program -{ - public static void Main() - { - int p = 5; - p.Print(); - } -}"; - - CreateCompilationWithMscorlibAndSystemCore(code, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp7_1)).GetParseDiagnostics().Verify( - // (4,30): error CS8302: Feature 'ref or in extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. - // public static void Print(in this int p) - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "in").WithArguments("ref or in extension methods", "7.2").WithLocation(4, 30), - - // (4,30): error CS8302: Feature 'readonly references' is not available in C# 7.1. Please use language version 7.2 or greater. - // public static void Print(in this int p) - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "in").WithArguments("readonly references", "7.2").WithLocation(4, 30) + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "ref").WithArguments("ref extension methods", "7.2").WithLocation(4, 30) ); CompileAndVerify(code, additionalRefs: new[] { SystemCoreRef }, expectedOutput: "5"); @@ -5907,9 +5646,9 @@ public static void Main() }"; CreateCompilationWithMscorlibAndSystemCore(code, parseOptions: CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp7_1)).GetParseDiagnostics().Verify( - // (4,30): error CS8302: Feature 'ref or in extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. + // (4,30): error CS8302: Feature 'ref extension methods' is not available in C# 7.1. Please use language version 7.2 or greater. // public static void Print(ref this int p) - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "ref").WithArguments("ref or in extension methods", "7.2").WithLocation(4, 30) + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7_1, "ref").WithArguments("ref extension methods", "7.2").WithLocation(4, 30) ); CompileAndVerify(code, additionalRefs: new[] { SystemCoreRef }, expectedOutput: "5"); diff --git a/src/EditorFeatures/CSharpTest2/Recommendations/InKeywordRecommenderTests.cs b/src/EditorFeatures/CSharpTest2/Recommendations/InKeywordRecommenderTests.cs index 89cd55279c877..2fe23cf807294 100644 --- a/src/EditorFeatures/CSharpTest2/Recommendations/InKeywordRecommenderTests.cs +++ b/src/EditorFeatures/CSharpTest2/Recommendations/InKeywordRecommenderTests.cs @@ -301,126 +301,5 @@ void M() { var q = from Int32 $$"); } - - [Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.ReadOnlyReferences)] - [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] - public async Task TestInAsParameterModifierInMethods() - { - await VerifyKeywordAsync(@" -class Program -{ - public static void Test($$ p) { } -}"); - } - - [Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.ReadOnlyReferences)] - [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] - public async Task TestInAsParameterModifierInSecondParameter() - { - await VerifyKeywordAsync(@" -class Program -{ - public static void Test(int p1, $$ p2) { } -}"); - } - - [Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.ReadOnlyReferences)] - [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] - public async Task TestInAsParameterModifierInDelegates() - { - await VerifyKeywordAsync(@" -public delegate int Delegate($$ int p);"); - } - - [Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.ReadOnlyReferences)] - [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] - public async Task TestInAsParameterModifierInLocalFunctions() - { - await VerifyKeywordAsync(@" -class Program -{ - public static void Test() - { - void localFunc($$ int p) { } - } -}"); - } - - [Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.ReadOnlyReferences)] - [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] - public async Task TestInAsParameterModifierInLambdaExpressions() - { - await VerifyKeywordAsync(@" -public delegate int Delegate(ref readonly int p); - -class Program -{ - public static void Test() - { - Delegate lambda = ($$ int p) => p; - } -}"); - } - - [Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.ReadOnlyReferences)] - [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] - public async Task TestInAsParameterModifierInAnonymousMethods() - { - await VerifyKeywordAsync(@" -public delegate int Delegate(ref readonly int p); - -class Program -{ - public static void Test() - { - Delegate anonymousDelegate = delegate ($$ int p) { return p; }; - } -}"); - } - - [Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.ReadOnlyReferences)] - [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] - public async Task TestInAsModifierInMethodReturnTypes() - { - await VerifyKeywordAsync(@" -class Program -{ - public $$ int Test() - { - return ref x; - } -}"); - } - - [Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.ReadOnlyReferences)] - [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] - public async Task TestInAsModifierInGlobalMemberDeclaration() - { - await VerifyKeywordAsync(SourceCodeKind.Script, @" -public $$ "); - } - - [Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.ReadOnlyReferences)] - [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] - public async Task TestInAsModifierInDelegateReturnType() - { - await VerifyKeywordAsync(@" -public delegate $$ int Delegate(); - -class Program -{ -}"); - } - - [Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.ReadOnlyReferences)] - [WpfFact, Trait(Traits.Feature, Traits.Features.Completion)] - public async Task TestInAsModifierInMemberDeclaration() - { - await VerifyKeywordAsync(@" -class Program -{ - public $$ int Test { get; set; } -}"); - } } } diff --git a/src/EditorFeatures/CSharpTest2/Recommendations/ThisKeywordRecommenderTests.cs b/src/EditorFeatures/CSharpTest2/Recommendations/ThisKeywordRecommenderTests.cs index 0014b692e94da..24f583679b733 100644 --- a/src/EditorFeatures/CSharpTest2/Recommendations/ThisKeywordRecommenderTests.cs +++ b/src/EditorFeatures/CSharpTest2/Recommendations/ThisKeywordRecommenderTests.cs @@ -663,21 +663,6 @@ public static class Extensions }"); } - [Fact] - public async Task TestExtensionMethods_FirstParameter_AfterInKeyword_InClass() - { - await VerifyKeywordAsync(@" -public static class Extensions -{ - public static void Extension(in $$"); - - await VerifyKeywordAsync(@" -public static class Extensions -{ - public static void Extension(in $$ object obj, int x) { } -}"); - } - [Fact] public async Task TestExtensionMethods_SecondParameter_AfterRefKeyword_InClass() { @@ -708,21 +693,6 @@ public static class Extensions }"); } - [Fact] - public async Task TestExtensionMethods_SecondParameter_AfterInKeyword_InClass() - { - await VerifyAbsenceAsync(@" -public static class Extensions -{ - public static void Extension(int x, in $$"); - - await VerifyAbsenceAsync(@" -public static class Extensions -{ - public static void Extension(int x, in $$ object obj) { } -}"); - } - [Fact] public async Task TestExtensionMethods_FirstParameter_AfterRefKeyword_OutsideClass() { @@ -739,14 +709,6 @@ public async Task TestExtensionMethods_FirstParameter_AfterRefReadOnlyKeywords_O await VerifyAbsenceAsync("public static void Extension(ref readonly $$ object obj, int x) { }"); } - [Fact] - public async Task TestExtensionMethods_FirstParameter_AfterInKeyword_OutsideClass() - { - await VerifyAbsenceAsync("public static void Extension(in $$"); - - await VerifyAbsenceAsync("public static void Extension(in $$ object obj, int x) { }"); - } - [Fact] public async Task TestExtensionMethods_FirstParameter_AfterRefKeyword_NonStaticClass() { @@ -777,21 +739,6 @@ public class Extensions }"); } - [Fact] - public async Task TestExtensionMethods_FirstParameter_AfterInKeyword_NonStaticClass() - { - await VerifyAbsenceAsync(@" -public class Extensions -{ - public static void Extension(in $$"); - - await VerifyAbsenceAsync(@" -public class Extensions -{ - public static void Extension(in $$ object obj, int x) { } -}"); - } - [Fact] public async Task TestExtensionMethods_FirstParameter_AfterRefKeyword_NonStaticMethod() { @@ -819,21 +766,6 @@ public static class Extensions public static class Extensions { public void Extension(ref readonly $$ object obj, int x) { } -}"); - } - - [Fact] - public async Task TestExtensionMethods_FirstParameter_AfterInKeyword_NonStaticMethod() - { - await VerifyAbsenceAsync(@" -public static class Extensions -{ - public void Extension(in $$"); - - await VerifyAbsenceAsync(@" -public static class Extensions -{ - public void Extension(in $$ object obj, int x) { } }"); } } diff --git a/src/Features/CSharp/Portable/Completion/KeywordRecommenders/InKeywordRecommender.cs b/src/Features/CSharp/Portable/Completion/KeywordRecommenders/InKeywordRecommender.cs index 94d011a0be444..2dc8cbf48eefd 100644 --- a/src/Features/CSharp/Portable/Completion/KeywordRecommenders/InKeywordRecommender.cs +++ b/src/Features/CSharp/Portable/Completion/KeywordRecommenders/InKeywordRecommender.cs @@ -17,63 +17,13 @@ public InKeywordRecommender() { } - /// - /// Same as with in specific exclusions - /// - private static readonly ISet InMemberModifiers = new HashSet(SyntaxFacts.EqualityComparer) - { - SyntaxKind.AbstractKeyword, - // SyntaxKind.AsyncKeyword, // async methods cannot be in - SyntaxKind.ExternKeyword, - SyntaxKind.InternalKeyword, - SyntaxKind.NewKeyword, - SyntaxKind.OverrideKeyword, - SyntaxKind.PublicKeyword, - SyntaxKind.PrivateKeyword, - SyntaxKind.ProtectedKeyword, - // SyntaxKind.ReadOnlyKeyword, // fields cannot be in - SyntaxKind.SealedKeyword, - SyntaxKind.StaticKeyword, - SyntaxKind.UnsafeKeyword, - SyntaxKind.VirtualKeyword, - // SyntaxKind.VolatileKeyword, // fields cannot be in - }; - - /// - /// Same as with in specific exclusions - /// - private static readonly ISet InGlobalMemberModifiers = new HashSet(SyntaxFacts.EqualityComparer) - { - // SyntaxKind.AsyncKeyword, // async methods cannot be in - SyntaxKind.ExternKeyword, - SyntaxKind.InternalKeyword, - SyntaxKind.NewKeyword, - SyntaxKind.OverrideKeyword, - SyntaxKind.PublicKeyword, - SyntaxKind.PrivateKeyword, - // SyntaxKind.ReadOnlyKeyword, // fields cannot be in - SyntaxKind.StaticKeyword, - SyntaxKind.UnsafeKeyword, - // SyntaxKind.VolatileKeyword, // fields cannot be in - }; - protected override bool IsValidContext(int position, CSharpSyntaxContext context, CancellationToken cancellationToken) { return IsValidContextInForEachClause(context) || IsValidContextInFromClause(context, cancellationToken) || IsValidContextInJoinClause(context, cancellationToken) || - context.TargetToken.IsTypeParameterVarianceContext() || - context.SyntaxTree.IsParameterModifierContext(position, context.LeftToken, cancellationToken) || - context.SyntaxTree.IsAnonymousMethodParameterModifierContext(position, context.LeftToken, cancellationToken) || - context.SyntaxTree.IsPossibleLambdaParameterModifierContext(position, context.LeftToken, cancellationToken) || - context.IsDelegateReturnTypeContext || - context.SyntaxTree.IsGlobalMemberDeclarationContext(position, InGlobalMemberModifiers, cancellationToken) || - context.IsMemberDeclarationContext( - validModifiers: InMemberModifiers, - validTypeDeclarations: SyntaxKindSet.ClassInterfaceStructTypeDeclarations, - canBePartial: false, - cancellationToken: cancellationToken); + context.TargetToken.IsTypeParameterVarianceContext(); } private bool IsValidContextInForEachClause(CSharpSyntaxContext context) diff --git a/src/Workspaces/CSharp/Portable/Extensions/ContextQuery/SyntaxTreeExtensions.cs b/src/Workspaces/CSharp/Portable/Extensions/ContextQuery/SyntaxTreeExtensions.cs index 3e064a03791a7..2b32b3703720b 100644 --- a/src/Workspaces/CSharp/Portable/Extensions/ContextQuery/SyntaxTreeExtensions.cs +++ b/src/Workspaces/CSharp/Portable/Extensions/ContextQuery/SyntaxTreeExtensions.cs @@ -1025,7 +1025,7 @@ public static bool IsDefaultExpressionContext(this SyntaxTree syntaxTree, int po } if (isThisKeyword && - (token.IsKind(SyntaxKind.RefKeyword) || token.IsKind(SyntaxKind.ReadOnlyKeyword) || token.IsKind(SyntaxKind.InKeyword)) && + (token.IsKind(SyntaxKind.RefKeyword) || token.IsKind(SyntaxKind.ReadOnlyKeyword)) && token.Parent.GetParent().IsDelegateOrConstructorOrLocalFunctionOrMethodParameterList()) { var parameter = token.GetAncestor();