From bc1a02e6db4b85e6ddb88790c1d3b8a2e0b55680 Mon Sep 17 00:00:00 2001 From: Marc Zwart Date: Sun, 16 Oct 2022 21:46:04 +0200 Subject: [PATCH 1/8] update message (cherry picked from commit 14896d51fec783a6f1ae3980393cc314dd257237) --- src/Compilers/CSharp/Portable/CSharpResources.resx | 2 +- src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf | 4 ++-- src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf | 4 ++-- 14 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index 437c5f40ed588..6b6e3cf3e7368 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -985,7 +985,7 @@ Cannot call an abstract base member: '{0}' - A property or indexer may not be passed as an out or ref parameter + An indexer or auto-implemented property may not be used as an out or ref value Cannot take the address of, get the size of, or declare a pointer to a managed type ('{0}') diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index 0325103290afd..a692a79431c46 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -5262,8 +5262,8 @@ - A property or indexer may not be passed as an out or ref parameter - Vlastnost nebo indexer nejde předat jako parametr ref nebo out. + An indexer or auto-implemented property may not be used as an out or ref value + Vlastnost nebo indexer nejde předat jako parametr ref nebo out. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index 835992c950b8b..328d3fc782493 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -5262,8 +5262,8 @@ - A property or indexer may not be passed as an out or ref parameter - Eine Eigenschaft oder ein Indexer kann nicht als out- oder ref-Parameter übergeben werden. + An indexer or auto-implemented property may not be used as an out or ref value + Eine Eigenschaft oder ein Indexer kann nicht als out- oder ref-Parameter übergeben werden. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index 7a22606c7e460..ab83978774d39 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -5262,8 +5262,8 @@ - A property or indexer may not be passed as an out or ref parameter - Una propiedad o un indizador no se puede pasar como parámetro out o ref + An indexer or auto-implemented property may not be used as an out or ref value + Una propiedad o un indizador no se puede pasar como parámetro out o ref diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index 287e9d2e806dc..3ac371a2b7f9b 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -5262,8 +5262,8 @@ - A property or indexer may not be passed as an out or ref parameter - Impossible de passer une propriété ou un indexeur en tant que paramètre de sortie (out) ni de référence (ref) + An indexer or auto-implemented property may not be used as an out or ref value + Impossible de passer une propriété ou un indexeur en tant que paramètre de sortie (out) ni de référence (ref) diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index 6eae94bc95785..a2f3306fa0558 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -5262,8 +5262,8 @@ - A property or indexer may not be passed as an out or ref parameter - Una proprietà o un indicizzatore non può essere passato come parametro out o ref + An indexer or auto-implemented property may not be used as an out or ref value + Una proprietà o un indicizzatore non può essere passato come parametro out o ref diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index 088708827157e..a2ce6ce0d6ecf 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -5262,8 +5262,8 @@ - A property or indexer may not be passed as an out or ref parameter - プロパティまたはインデクサーを out か ref のパラメーターとして渡すことはできません + An indexer or auto-implemented property may not be used as an out or ref value + プロパティまたはインデクサーを out か ref のパラメーターとして渡すことはできません diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index 0174178491374..aa46907899eab 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -5261,8 +5261,8 @@ - A property or indexer may not be passed as an out or ref parameter - 속성 또는 인덱서는 out 또는 ref 매개 변수로 전달할 수 없습니다. + An indexer or auto-implemented property may not be used as an out or ref value + 속성 또는 인덱서는 out 또는 ref 매개 변수로 전달할 수 없습니다. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index 16003fc6f22fd..c050a1f373987 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -5262,8 +5262,8 @@ - A property or indexer may not be passed as an out or ref parameter - Nie można przekazać właściwości lub indeksatora jako parametru „out” lub „ref”. + An indexer or auto-implemented property may not be used as an out or ref value + Nie można przekazać właściwości lub indeksatora jako parametru „out” lub „ref”. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index b411dcd16ac19..8273d78cffa82 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -5262,8 +5262,8 @@ - A property or indexer may not be passed as an out or ref parameter - Talvez uma propriedade ou um indexador não possa ser passado como um parâmetro out ou ref + An indexer or auto-implemented property may not be used as an out or ref value + Talvez uma propriedade ou um indexador não possa ser passado como um parâmetro out ou ref diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index f626ff3a63f1f..987b20c30e6b4 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -5262,8 +5262,8 @@ - A property or indexer may not be passed as an out or ref parameter - Свойство или индексатор не могут передаваться как параметр out или ref. + An indexer or auto-implemented property may not be used as an out or ref value + Свойство или индексатор не могут передаваться как параметр out или ref. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index 4f16e74373a4d..eb798f20ca872 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -5262,8 +5262,8 @@ - A property or indexer may not be passed as an out or ref parameter - Bir özellik veya dizin erişimcisi, out veya ref parametresi olarak geçilemez + An indexer or auto-implemented property may not be used as an out or ref value + Bir özellik veya dizin erişimcisi, out veya ref parametresi olarak geçilemez diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index 17853b03b80f3..b2cb51cf0f2cf 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -5267,8 +5267,8 @@ - A property or indexer may not be passed as an out or ref parameter - 属性或索引器不能作为 out 或 ref 参数传递 + An indexer or auto-implemented property may not be used as an out or ref value + 属性或索引器不能作为 out 或 ref 参数传递 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index 134bcee658b99..3d6c2913fb46a 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -5262,8 +5262,8 @@ - A property or indexer may not be passed as an out or ref parameter - 屬性或索引子不可以 out 或 ref 參數形式傳遞 + An indexer or auto-implemented property may not be used as an out or ref value + 屬性或索引子不可以 out 或 ref 參數形式傳遞 From 0965b856e304c9263af55ca338618d8b40b6a66b Mon Sep 17 00:00:00 2001 From: Marc Zwart Date: Sun, 16 Oct 2022 21:47:02 +0200 Subject: [PATCH 2/8] add test demonstrating legal and illegal combinations of ref/out and properties in which the new message still makes sense --- .../Test/Semantic/Semantics/RefFieldTests.cs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs index 49769a27a6a84..78dfcac1dccce 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs @@ -8828,6 +8828,51 @@ static void Main() Diagnostic(ErrorCode.ERR_RefLocalOrParamExpected, "s.P2").WithLocation(22, 9)); } + /// + /// Ref auto-properties are not supported. + /// + [Fact] + public void RefAndOutProperties() + { + var source = +@" +ref string S = ref C.S; //CS0206 +var c = new C(); +var str = C.M(ref c.N); //ref prop +var str2 = C.M(ref c.N2); //CS0206 +var str3 = C.M2(out c.N); //ref prop +var str4 = C.M2(out c.N2); //CS0206 +ref struct C +{ + public static string S { get; set; } + private ref int n; + public ref int N => ref n; + public int N2 { get; set; } + public static string M(ref int number) + { + return number.ToString(); + } + public static string M2(out int number) + { + number = 42; + return number.ToString(); + } +} +"; + var comp = CreateCompilation(source, targetFramework: TargetFramework.Net70); + comp.VerifyEmitDiagnostics( + // (2,20): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // ref string S = ref C.S; //CS0206 + Diagnostic(ErrorCode.ERR_RefProperty, "C.S").WithLocation(2, 20), + // (5,20): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // var str2 = C.M(ref c.N2); + Diagnostic(ErrorCode.ERR_RefProperty, "c.N2").WithLocation(5, 20), + // (7,21): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // var str4 = C.M2(out c.N2); + Diagnostic(ErrorCode.ERR_RefProperty, "c.N2").WithLocation(7, 21) + ); + } + [Fact] public void RefAccessor_Value() { From 9b4cd1c10ad88e9630cddfc13eb041d4dcb3cb0c Mon Sep 17 00:00:00 2001 From: Marc Zwart Date: Sun, 16 Oct 2022 21:47:37 +0200 Subject: [PATCH 3/8] update comments in tests to reflect message change (cherry picked from commit 725728a3c391c9a247b858bfeeb9f312aeb3e1ba) --- .../Test/Semantic/Semantics/ArglistTests.cs | 2 +- .../Semantic/Semantics/InitOnlyMemberTests.cs | 2 +- .../Semantics/NullableReferenceTypesTests.cs | 2 +- .../Semantics/RefLocalsAndReturnsTests.cs | 4 ++-- .../Semantic/Semantics/SemanticErrorTests.cs | 20 +++++++++---------- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/ArglistTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/ArglistTests.cs index 18bb030c0cefb..926c5fdb5eea1 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/ArglistTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/ArglistTests.cs @@ -229,7 +229,7 @@ static void Main() // (9,40): error CS1510: A ref or out value must be an assignable variable // TypedReference tr3 = __makeref(123); // CS1510 Diagnostic(ErrorCode.ERR_RefLvalueExpected, "123").WithLocation(9, 40), - // (10,40): error CS0206: A property or indexer may not be passed as an out or ref parameter + // (10,40): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value // TypedReference tr4 = __makeref(P); // CS0206 Diagnostic(ErrorCode.ERR_RefProperty, "P").WithLocation(10, 40), // (11,40): error CS0199: A static readonly field cannot be used as a ref or out value (except in a static constructor) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs index f01c983054cbd..e7b7912c86eb3 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs @@ -1278,7 +1278,7 @@ void M() "; var comp = CreateCompilation(new[] { source, IsExternalInitTypeDefinition }, parseOptions: TestOptions.Regular9); comp.VerifyEmitDiagnostics( - // (8,16): error CS0206: A property or indexer may not be passed as an out or ref parameter + // (8,16): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value // M2(out Property); // 1 Diagnostic(ErrorCode.ERR_RefProperty, "Property").WithLocation(8, 16) ); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index 55637c47ebe54..737a07f99c429 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -33580,7 +33580,7 @@ public void M() // (12,9): warning CS8602: Dereference of a possibly null reference. // field.ToString(); // 4 Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "field").WithLocation(12, 9), - // (14,15): error CS0206: A property or indexer may not be passed as an out or ref parameter + // (14,15): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value // M(ref Property); // 5 Diagnostic(ErrorCode.ERR_RefProperty, "Property").WithLocation(14, 15), // (15,20): warning CS8625: Cannot convert null literal to non-nullable reference type. diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RefLocalsAndReturnsTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RefLocalsAndReturnsTests.cs index 50681c9578a6a..c5f64ef62aa22 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RefLocalsAndReturnsTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RefLocalsAndReturnsTests.cs @@ -3178,7 +3178,7 @@ static void M() "; CreateCompilationWithMscorlib46(text).VerifyDiagnostics( - // (8,26): error CS0206: A property or indexer may not be passed as an out or ref parameter + // (8,26): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value // ref int rl = ref P; Diagnostic(ErrorCode.ERR_RefProperty, "P").WithLocation(8, 26)); } @@ -3199,7 +3199,7 @@ void M() "; CreateCompilationWithMscorlib46(text).VerifyDiagnostics( - // (8,26): error CS0206: A property or indexer may not be passed as an out or ref parameter + // (8,26): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value // ref int rl = ref this[0]; Diagnostic(ErrorCode.ERR_RefProperty, "this[0]").WithLocation(8, 26)); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs index 957d2f7d11fc5..7062a7a02502b 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs @@ -8042,10 +8042,10 @@ void M() } "; CreateCompilation(text).VerifyDiagnostics( - // (14,15): error CS0206: A property or indexer may not be passed as an out or ref parameter + // (14,15): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value // M(ref P); // CS0206 Diagnostic(ErrorCode.ERR_RefProperty, "P").WithLocation(14, 15), - // (15,15): error CS0206: A property or indexer may not be passed as an out or ref parameter + // (15,15): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value // M(out this.Q); // CS0206 Diagnostic(ErrorCode.ERR_RefProperty, "this.Q").WithLocation(15, 15)); } @@ -8072,10 +8072,10 @@ void M() } "; CreateCompilation(text).VerifyDiagnostics( - // (13,15): error CS0206: A property or indexer may not be passed as an out or ref parameter + // (13,15): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value // R(ref this[0]); // CS0206 Diagnostic(ErrorCode.ERR_RefProperty, "this[0]").WithLocation(13, 15), - // (14,15): error CS0206: A property or indexer may not be passed as an out or ref parameter + // (14,15): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value // O(out this[0]); // CS0206 Diagnostic(ErrorCode.ERR_RefProperty, "this[0]").WithLocation(14, 15)); } @@ -22856,13 +22856,13 @@ static void Test(Func Baz) // (17,47): error CS1510: A ref or out argument must be an assignable variable // var z5 = new Func(ref Goo(x => x)); Diagnostic(ErrorCode.ERR_RefLvalueExpected, "Goo(x => x)").WithLocation(17, 47), - // (18,43): error CS0206: A property or indexer may not be passed as an out or ref parameter + // (18,43): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value // var z6 = new Func(ref BarP); Diagnostic(ErrorCode.ERR_RefProperty, "ref BarP").WithLocation(18, 43), // (19,47): error CS1510: A ref or out argument must be an assignable variable // var z7 = new Func(ref new Func(x => x)); Diagnostic(ErrorCode.ERR_RefLvalueExpected, "new Func(x => x)").WithLocation(19, 47), - // (20,43): error CS0206: A property or indexer may not be passed as an out or ref parameter + // (20,43): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value // var z8 = new Func(ref Program.BarP); Diagnostic(ErrorCode.ERR_RefProperty, "ref Program.BarP").WithLocation(20, 43), // (21,47): error CS1510: A ref or out argument must be an assignable variable @@ -22889,13 +22889,13 @@ static void Test(Func Baz) // (17,47): error CS1510: A ref or out argument must be an assignable variable // var z5 = new Func(ref Goo(x => x)); Diagnostic(ErrorCode.ERR_RefLvalueExpected, "Goo(x => x)").WithLocation(17, 47), - // (18,47): error CS0206: A property or indexer may not be passed as an out or ref parameter + // (18,47): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value // var z6 = new Func(ref BarP); Diagnostic(ErrorCode.ERR_RefProperty, "BarP").WithLocation(18, 47), // (19,47): error CS1510: A ref or out argument must be an assignable variable // var z7 = new Func(ref new Func(x => x)); Diagnostic(ErrorCode.ERR_RefLvalueExpected, "new Func(x => x)").WithLocation(19, 47), - // (20,47): error CS0206: A property or indexer may not be passed as an out or ref parameter + // (20,47): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value // var z8 = new Func(ref Program.BarP); Diagnostic(ErrorCode.ERR_RefProperty, "Program.BarP").WithLocation(20, 47), // (21,47): error CS1510: A ref or out argument must be an assignable variable @@ -23007,7 +23007,7 @@ static void Test(Func Baz) // (10,46): error CS0149: Method name expected // var c = new Func(ref Baz, ref Baz.Invoke); Diagnostic(ErrorCode.ERR_MethodNameExpected, "Baz, ref Baz.Invoke").WithLocation(10, 46), - // (11,42): error CS0206: A property or indexer may not be passed as an out or ref parameter + // (11,42): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value // var d = new Func(ref BarP, BarP.Invoke); Diagnostic(ErrorCode.ERR_RefProperty, "ref BarP").WithLocation(11, 42), // (11,46): error CS0149: Method name expected @@ -23016,7 +23016,7 @@ static void Test(Func Baz) // (12,42): error CS0149: Method name expected // var e = new Func(BarP, ref BarP.Invoke); Diagnostic(ErrorCode.ERR_MethodNameExpected, "BarP, ref BarP.Invoke").WithLocation(12, 42), - // (13,42): error CS0206: A property or indexer may not be passed as an out or ref parameter + // (13,42): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value // var f = new Func(ref BarP, ref BarP.Invoke); Diagnostic(ErrorCode.ERR_RefProperty, "ref BarP").WithLocation(13, 42), // (13,46): error CS0149: Method name expected From ddc0364f35eec3e4639de8194cf7a1960e9a9b02 Mon Sep 17 00:00:00 2001 From: Marc Zwart Date: Sun, 16 Oct 2022 21:54:05 +0200 Subject: [PATCH 4/8] remove wrong comment and link work item to test --- src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs index 78dfcac1dccce..be2ff2764efa2 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs @@ -8828,10 +8828,8 @@ static void Main() Diagnostic(ErrorCode.ERR_RefLocalOrParamExpected, "s.P2").WithLocation(22, 9)); } - /// - /// Ref auto-properties are not supported. - /// [Fact] + [WorkItem(60807, "https://github.com/dotnet/roslyn/issues/60807")] public void RefAndOutProperties() { var source = From 0fa195a2d8b2d3ed588c1f8671c2f838492f895f Mon Sep 17 00:00:00 2001 From: Marc Zwart Date: Sun, 16 Oct 2022 22:34:55 +0200 Subject: [PATCH 5/8] extend test case with indexers and ref indexers --- .../Test/Semantic/Semantics/RefFieldTests.cs | 75 ++++++++++++------- 1 file changed, 48 insertions(+), 27 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs index be2ff2764efa2..eae1bc0e046bb 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs @@ -8830,44 +8830,65 @@ static void Main() [Fact] [WorkItem(60807, "https://github.com/dotnet/roslyn/issues/60807")] - public void RefAndOutProperties() + public void RefAndOut_PropertiesAndIndexers_As_ValuesAndParameters() { var source = @" -ref string S = ref C.S; //CS0206 var c = new C(); -var str = C.M(ref c.N); //ref prop -var str2 = C.M(ref c.N2); //CS0206 -var str3 = C.M2(out c.N); //ref prop -var str4 = C.M2(out c.N2); //CS0206 -ref struct C +var r = new R(); +//expressions +ref int n = ref c.N; //CS0206 +ref var l = ref c[0]; //CS0206 +ref var l2 = ref r[0];//OK +_ = M(ref c.N); //CS0206 +_ = M(ref r.N); //OK +_ = M(ref c[0]); //CS0206 +_ = M(ref r[0]); //OK +_ = M2(out c.N); //CS0206 +_ = M2(out r.N); //OK +_ = M2(out c[0]); //CS0206 +_ = M2(out r[0]); //OK +//defenitions +static string M(ref int number) { return """"; } +static string M2(out int number) { number = 42; return """"; } +class C +{ + public int N { get; set; } + private int[] arr = new int[100]; + public int this[int i] => arr[i]; +} +ref struct R { - public static string S { get; set; } + public I2() { arr = new int[1]; n = 1; } private ref int n; public ref int N => ref n; - public int N2 { get; set; } - public static string M(ref int number) - { - return number.ToString(); - } - public static string M2(out int number) - { - number = 42; - return number.ToString(); - } + private ref int[] arr; + public ref int this[int i] => ref arr[i]; } "; var comp = CreateCompilation(source, targetFramework: TargetFramework.Net70); comp.VerifyEmitDiagnostics( - // (2,20): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value - // ref string S = ref C.S; //CS0206 - Diagnostic(ErrorCode.ERR_RefProperty, "C.S").WithLocation(2, 20), - // (5,20): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value - // var str2 = C.M(ref c.N2); - Diagnostic(ErrorCode.ERR_RefProperty, "c.N2").WithLocation(5, 20), - // (7,21): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value - // var str4 = C.M2(out c.N2); - Diagnostic(ErrorCode.ERR_RefProperty, "c.N2").WithLocation(7, 21) + // (5,17): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // ref int n = ref c.N; //CS0206 + Diagnostic(ErrorCode.ERR_RefProperty, "c.N").WithLocation(5, 17), + // (6,17): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // ref var l = ref c[0]; //CS0206 + Diagnostic(ErrorCode.ERR_RefProperty, "c[0]").WithLocation(6, 17), + // (8,11): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // _ = M(ref c.N); //CS0206 + Diagnostic(ErrorCode.ERR_RefProperty, "c.N").WithLocation(8, 11), + // (10,11): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // _ = M(ref c[0]); //CS0206 + Diagnostic(ErrorCode.ERR_RefProperty, "c[0]").WithLocation(10, 11), + // (12,12): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // _ = M2(out c.N); //CS0206 + Diagnostic(ErrorCode.ERR_RefProperty, "c.N").WithLocation(12, 12), + // (14,12): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // _ = M2(out c[0]); //CS0206 + Diagnostic(ErrorCode.ERR_RefProperty, "c[0]").WithLocation(14, 12), + // (27,12): error CS1520: Method must have a return type + // public I2() { arr = new int[1]; n = 1; } + Diagnostic(ErrorCode.ERR_MemberNeedsType, "I2").WithLocation(27, 12) ); } From 544cfb12b5300b6ed03c48768ad7da63f3bb70d1 Mon Sep 17 00:00:00 2001 From: Marc Zwart Date: Sun, 16 Oct 2022 23:01:40 +0200 Subject: [PATCH 6/8] clean up --- .../CSharp/Test/Semantic/Semantics/RefFieldTests.cs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs index eae1bc0e046bb..74dd34b9585e3 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs @@ -8859,10 +8859,10 @@ class C } ref struct R { - public I2() { arr = new int[1]; n = 1; } + public R(){} private ref int n; public ref int N => ref n; - private ref int[] arr; + private ref int[] arr = new int[1]; public ref int this[int i] => ref arr[i]; } "; @@ -8885,10 +8885,7 @@ ref struct R Diagnostic(ErrorCode.ERR_RefProperty, "c.N").WithLocation(12, 12), // (14,12): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value // _ = M2(out c[0]); //CS0206 - Diagnostic(ErrorCode.ERR_RefProperty, "c[0]").WithLocation(14, 12), - // (27,12): error CS1520: Method must have a return type - // public I2() { arr = new int[1]; n = 1; } - Diagnostic(ErrorCode.ERR_MemberNeedsType, "I2").WithLocation(27, 12) + Diagnostic(ErrorCode.ERR_RefProperty, "c[0]").WithLocation(14, 12) ); } From d1d818b1d117eb54d256cd1ba3f33562548b337b Mon Sep 17 00:00:00 2001 From: Marc Zwart Date: Mon, 17 Oct 2022 16:37:14 +0200 Subject: [PATCH 7/8] Update message as discussed in #60807 --- .../CSharp/Portable/CSharpResources.resx | 2 +- .../Portable/xlf/CSharpResources.cs.xlf | 2 +- .../Portable/xlf/CSharpResources.de.xlf | 2 +- .../Portable/xlf/CSharpResources.es.xlf | 2 +- .../Portable/xlf/CSharpResources.fr.xlf | 2 +- .../Portable/xlf/CSharpResources.it.xlf | 2 +- .../Portable/xlf/CSharpResources.ja.xlf | 2 +- .../Portable/xlf/CSharpResources.ko.xlf | 2 +- .../Portable/xlf/CSharpResources.pl.xlf | 2 +- .../Portable/xlf/CSharpResources.pt-BR.xlf | 2 +- .../Portable/xlf/CSharpResources.ru.xlf | 2 +- .../Portable/xlf/CSharpResources.tr.xlf | 2 +- .../Portable/xlf/CSharpResources.zh-Hans.xlf | 2 +- .../Portable/xlf/CSharpResources.zh-Hant.xlf | 2 +- .../Test/Semantic/Semantics/ArglistTests.cs | 2 +- .../Semantic/Semantics/InitOnlyMemberTests.cs | 2 +- .../Semantics/NullableReferenceTypesTests.cs | 2 +- .../Test/Semantic/Semantics/RefFieldTests.cs | 12 +++++------ .../Semantics/RefLocalsAndReturnsTests.cs | 4 ++-- .../Semantic/Semantics/SemanticErrorTests.cs | 20 +++++++++---------- 20 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/Compilers/CSharp/Portable/CSharpResources.resx b/src/Compilers/CSharp/Portable/CSharpResources.resx index 6b6e3cf3e7368..616853f44bc14 100644 --- a/src/Compilers/CSharp/Portable/CSharpResources.resx +++ b/src/Compilers/CSharp/Portable/CSharpResources.resx @@ -985,7 +985,7 @@ Cannot call an abstract base member: '{0}' - An indexer or auto-implemented property may not be used as an out or ref value + A non ref-returning property or indexer may not be used as an out or ref value Cannot take the address of, get the size of, or declare a pointer to a managed type ('{0}') diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf index a692a79431c46..b2086c4938317 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.cs.xlf @@ -5262,7 +5262,7 @@ - An indexer or auto-implemented property may not be used as an out or ref value + A non ref-returning property or indexer may not be used as an out or ref value Vlastnost nebo indexer nejde předat jako parametr ref nebo out. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf index 328d3fc782493..7b5c7556dc23d 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.de.xlf @@ -5262,7 +5262,7 @@ - An indexer or auto-implemented property may not be used as an out or ref value + A non ref-returning property or indexer may not be used as an out or ref value Eine Eigenschaft oder ein Indexer kann nicht als out- oder ref-Parameter übergeben werden. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf index ab83978774d39..6612728e2812a 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.es.xlf @@ -5262,7 +5262,7 @@ - An indexer or auto-implemented property may not be used as an out or ref value + A non ref-returning property or indexer may not be used as an out or ref value Una propiedad o un indizador no se puede pasar como parámetro out o ref diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf index 3ac371a2b7f9b..0264bd40fe1e7 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.fr.xlf @@ -5262,7 +5262,7 @@ - An indexer or auto-implemented property may not be used as an out or ref value + A non ref-returning property or indexer may not be used as an out or ref value Impossible de passer une propriété ou un indexeur en tant que paramètre de sortie (out) ni de référence (ref) diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf index a2f3306fa0558..f5813fd2a1641 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.it.xlf @@ -5262,7 +5262,7 @@ - An indexer or auto-implemented property may not be used as an out or ref value + A non ref-returning property or indexer may not be used as an out or ref value Una proprietà o un indicizzatore non può essere passato come parametro out o ref diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf index a2ce6ce0d6ecf..470eae4d9027c 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ja.xlf @@ -5262,7 +5262,7 @@ - An indexer or auto-implemented property may not be used as an out or ref value + A non ref-returning property or indexer may not be used as an out or ref value プロパティまたはインデクサーを out か ref のパラメーターとして渡すことはできません diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf index aa46907899eab..d92f1f46c2024 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ko.xlf @@ -5261,7 +5261,7 @@ - An indexer or auto-implemented property may not be used as an out or ref value + A non ref-returning property or indexer may not be used as an out or ref value 속성 또는 인덱서는 out 또는 ref 매개 변수로 전달할 수 없습니다. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf index c050a1f373987..24090dd9237e8 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pl.xlf @@ -5262,7 +5262,7 @@ - An indexer or auto-implemented property may not be used as an out or ref value + A non ref-returning property or indexer may not be used as an out or ref value Nie można przekazać właściwości lub indeksatora jako parametru „out” lub „ref”. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf index 8273d78cffa82..ba54938a62f00 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.pt-BR.xlf @@ -5262,7 +5262,7 @@ - An indexer or auto-implemented property may not be used as an out or ref value + A non ref-returning property or indexer may not be used as an out or ref value Talvez uma propriedade ou um indexador não possa ser passado como um parâmetro out ou ref diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf index 987b20c30e6b4..7f034d5294183 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.ru.xlf @@ -5262,7 +5262,7 @@ - An indexer or auto-implemented property may not be used as an out or ref value + A non ref-returning property or indexer may not be used as an out or ref value Свойство или индексатор не могут передаваться как параметр out или ref. diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf index eb798f20ca872..68078b1ceab59 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.tr.xlf @@ -5262,7 +5262,7 @@ - An indexer or auto-implemented property may not be used as an out or ref value + A non ref-returning property or indexer may not be used as an out or ref value Bir özellik veya dizin erişimcisi, out veya ref parametresi olarak geçilemez diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf index b2cb51cf0f2cf..519c96f1b7830 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hans.xlf @@ -5267,7 +5267,7 @@ - An indexer or auto-implemented property may not be used as an out or ref value + A non ref-returning property or indexer may not be used as an out or ref value 属性或索引器不能作为 out 或 ref 参数传递 diff --git a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf index 3d6c2913fb46a..457d6c2bf9e6e 100644 --- a/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf +++ b/src/Compilers/CSharp/Portable/xlf/CSharpResources.zh-Hant.xlf @@ -5262,7 +5262,7 @@ - An indexer or auto-implemented property may not be used as an out or ref value + A non ref-returning property or indexer may not be used as an out or ref value 屬性或索引子不可以 out 或 ref 參數形式傳遞 diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/ArglistTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/ArglistTests.cs index 926c5fdb5eea1..34f43bd675692 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/ArglistTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/ArglistTests.cs @@ -229,7 +229,7 @@ static void Main() // (9,40): error CS1510: A ref or out value must be an assignable variable // TypedReference tr3 = __makeref(123); // CS1510 Diagnostic(ErrorCode.ERR_RefLvalueExpected, "123").WithLocation(9, 40), - // (10,40): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // (10,40): error CS0206: A non ref-returning property or indexer may not be used as an out or ref value // TypedReference tr4 = __makeref(P); // CS0206 Diagnostic(ErrorCode.ERR_RefProperty, "P").WithLocation(10, 40), // (11,40): error CS0199: A static readonly field cannot be used as a ref or out value (except in a static constructor) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs index e7b7912c86eb3..4d98b24572d33 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InitOnlyMemberTests.cs @@ -1278,7 +1278,7 @@ void M() "; var comp = CreateCompilation(new[] { source, IsExternalInitTypeDefinition }, parseOptions: TestOptions.Regular9); comp.VerifyEmitDiagnostics( - // (8,16): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // (8,16): error CS0206: A non ref-returning property or indexer may not be used as an out or ref value // M2(out Property); // 1 Diagnostic(ErrorCode.ERR_RefProperty, "Property").WithLocation(8, 16) ); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index 737a07f99c429..0c77cd6d45ae0 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -33580,7 +33580,7 @@ public void M() // (12,9): warning CS8602: Dereference of a possibly null reference. // field.ToString(); // 4 Diagnostic(ErrorCode.WRN_NullReferenceReceiver, "field").WithLocation(12, 9), - // (14,15): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // (14,15): error CS0206: A non ref-returning property or indexer may not be used as an out or ref value // M(ref Property); // 5 Diagnostic(ErrorCode.ERR_RefProperty, "Property").WithLocation(14, 15), // (15,20): warning CS8625: Cannot convert null literal to non-nullable reference type. diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs index 74dd34b9585e3..811bdab5d176e 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs @@ -8868,22 +8868,22 @@ public R(){} "; var comp = CreateCompilation(source, targetFramework: TargetFramework.Net70); comp.VerifyEmitDiagnostics( - // (5,17): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // (5,17): error CS0206: A non ref-returning property or indexer may not be used as an out or ref value // ref int n = ref c.N; //CS0206 Diagnostic(ErrorCode.ERR_RefProperty, "c.N").WithLocation(5, 17), - // (6,17): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // (6,17): error CS0206: A non ref-returning property or indexer may not be used as an out or ref value // ref var l = ref c[0]; //CS0206 Diagnostic(ErrorCode.ERR_RefProperty, "c[0]").WithLocation(6, 17), - // (8,11): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // (8,11): error CS0206: A non ref-returning property or indexer may not be used as an out or ref value // _ = M(ref c.N); //CS0206 Diagnostic(ErrorCode.ERR_RefProperty, "c.N").WithLocation(8, 11), - // (10,11): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // (10,11): error CS0206: A non ref-returning property or indexer may not be used as an out or ref value // _ = M(ref c[0]); //CS0206 Diagnostic(ErrorCode.ERR_RefProperty, "c[0]").WithLocation(10, 11), - // (12,12): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // (12,12): error CS0206: A non ref-returning property or indexer may not be used as an out or ref value // _ = M2(out c.N); //CS0206 Diagnostic(ErrorCode.ERR_RefProperty, "c.N").WithLocation(12, 12), - // (14,12): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // (14,12): error CS0206: A non ref-returning property or indexer may not be used as an out or ref value // _ = M2(out c[0]); //CS0206 Diagnostic(ErrorCode.ERR_RefProperty, "c[0]").WithLocation(14, 12) ); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RefLocalsAndReturnsTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RefLocalsAndReturnsTests.cs index c5f64ef62aa22..cc76a1e83d1d0 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RefLocalsAndReturnsTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RefLocalsAndReturnsTests.cs @@ -3178,7 +3178,7 @@ static void M() "; CreateCompilationWithMscorlib46(text).VerifyDiagnostics( - // (8,26): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // (8,26): error CS0206: A non ref-returning property or indexer may not be used as an out or ref value // ref int rl = ref P; Diagnostic(ErrorCode.ERR_RefProperty, "P").WithLocation(8, 26)); } @@ -3199,7 +3199,7 @@ void M() "; CreateCompilationWithMscorlib46(text).VerifyDiagnostics( - // (8,26): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // (8,26): error CS0206: A non ref-returning property or indexer may not be used as an out or ref value // ref int rl = ref this[0]; Diagnostic(ErrorCode.ERR_RefProperty, "this[0]").WithLocation(8, 26)); } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs index 7062a7a02502b..20e2ff666817e 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs @@ -8042,10 +8042,10 @@ void M() } "; CreateCompilation(text).VerifyDiagnostics( - // (14,15): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // (14,15): error CS0206: A non ref-returning property or indexer may not be used as an out or ref value // M(ref P); // CS0206 Diagnostic(ErrorCode.ERR_RefProperty, "P").WithLocation(14, 15), - // (15,15): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // (15,15): error CS0206: A non ref-returning property or indexer may not be used as an out or ref value // M(out this.Q); // CS0206 Diagnostic(ErrorCode.ERR_RefProperty, "this.Q").WithLocation(15, 15)); } @@ -8072,10 +8072,10 @@ void M() } "; CreateCompilation(text).VerifyDiagnostics( - // (13,15): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // (13,15): error CS0206: A non ref-returning property or indexer may not be used as an out or ref value // R(ref this[0]); // CS0206 Diagnostic(ErrorCode.ERR_RefProperty, "this[0]").WithLocation(13, 15), - // (14,15): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // (14,15): error CS0206: A non ref-returning property or indexer may not be used as an out or ref value // O(out this[0]); // CS0206 Diagnostic(ErrorCode.ERR_RefProperty, "this[0]").WithLocation(14, 15)); } @@ -22856,13 +22856,13 @@ static void Test(Func Baz) // (17,47): error CS1510: A ref or out argument must be an assignable variable // var z5 = new Func(ref Goo(x => x)); Diagnostic(ErrorCode.ERR_RefLvalueExpected, "Goo(x => x)").WithLocation(17, 47), - // (18,43): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // (18,43): error CS0206: A non ref-returning property or indexer may not be used as an out or ref value // var z6 = new Func(ref BarP); Diagnostic(ErrorCode.ERR_RefProperty, "ref BarP").WithLocation(18, 43), // (19,47): error CS1510: A ref or out argument must be an assignable variable // var z7 = new Func(ref new Func(x => x)); Diagnostic(ErrorCode.ERR_RefLvalueExpected, "new Func(x => x)").WithLocation(19, 47), - // (20,43): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // (20,43): error CS0206: A non ref-returning property or indexer may not be used as an out or ref value // var z8 = new Func(ref Program.BarP); Diagnostic(ErrorCode.ERR_RefProperty, "ref Program.BarP").WithLocation(20, 43), // (21,47): error CS1510: A ref or out argument must be an assignable variable @@ -22889,13 +22889,13 @@ static void Test(Func Baz) // (17,47): error CS1510: A ref or out argument must be an assignable variable // var z5 = new Func(ref Goo(x => x)); Diagnostic(ErrorCode.ERR_RefLvalueExpected, "Goo(x => x)").WithLocation(17, 47), - // (18,47): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // (18,47): error CS0206: A non ref-returning property or indexer may not be used as an out or ref value // var z6 = new Func(ref BarP); Diagnostic(ErrorCode.ERR_RefProperty, "BarP").WithLocation(18, 47), // (19,47): error CS1510: A ref or out argument must be an assignable variable // var z7 = new Func(ref new Func(x => x)); Diagnostic(ErrorCode.ERR_RefLvalueExpected, "new Func(x => x)").WithLocation(19, 47), - // (20,47): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // (20,47): error CS0206: A non ref-returning property or indexer may not be used as an out or ref value // var z8 = new Func(ref Program.BarP); Diagnostic(ErrorCode.ERR_RefProperty, "Program.BarP").WithLocation(20, 47), // (21,47): error CS1510: A ref or out argument must be an assignable variable @@ -23007,7 +23007,7 @@ static void Test(Func Baz) // (10,46): error CS0149: Method name expected // var c = new Func(ref Baz, ref Baz.Invoke); Diagnostic(ErrorCode.ERR_MethodNameExpected, "Baz, ref Baz.Invoke").WithLocation(10, 46), - // (11,42): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // (11,42): error CS0206: A non ref-returning property or indexer may not be used as an out or ref value // var d = new Func(ref BarP, BarP.Invoke); Diagnostic(ErrorCode.ERR_RefProperty, "ref BarP").WithLocation(11, 42), // (11,46): error CS0149: Method name expected @@ -23016,7 +23016,7 @@ static void Test(Func Baz) // (12,42): error CS0149: Method name expected // var e = new Func(BarP, ref BarP.Invoke); Diagnostic(ErrorCode.ERR_MethodNameExpected, "BarP, ref BarP.Invoke").WithLocation(12, 42), - // (13,42): error CS0206: An indexer or auto-implemented property may not be used as an out or ref value + // (13,42): error CS0206: A non ref-returning property or indexer may not be used as an out or ref value // var f = new Func(ref BarP, ref BarP.Invoke); Diagnostic(ErrorCode.ERR_RefProperty, "ref BarP").WithLocation(13, 42), // (13,46): error CS0149: Method name expected From 8bd1291c2aa3769f8bfae14e31c70e674fbe10c2 Mon Sep 17 00:00:00 2001 From: Marc Zwart Date: Mon, 17 Oct 2022 16:37:51 +0200 Subject: [PATCH 8/8] fix typo --- src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs index 811bdab5d176e..340d40b11f666 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs @@ -8848,7 +8848,7 @@ public void RefAndOut_PropertiesAndIndexers_As_ValuesAndParameters() _ = M2(out r.N); //OK _ = M2(out c[0]); //CS0206 _ = M2(out r[0]); //OK -//defenitions +//definitions static string M(ref int number) { return """"; } static string M2(out int number) { number = 42; return """"; } class C