diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs index cc43665b27f7b..78dfcac1dccce 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/RefFieldTests.cs @@ -8832,31 +8832,44 @@ static void Main() /// Ref auto-properties are not supported. /// [Fact] - public void RefAutoProperty_03() + public void RefAndOutProperties() { var source = -@"using System; -class C -{ - public static string P0 { get; } - public static string P1 { get; set; } -} -class Program +@" +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 { - static void Main() + 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) { - ref var p0 = ref C.P0; - ref var p1 = ref C.P1; + return number.ToString(); } -}"; - var comp = CreateCompilation(source); + public static string M2(out int number) + { + number = 42; + return number.ToString(); + } +} +"; + var comp = CreateCompilation(source, targetFramework: TargetFramework.Net70); comp.VerifyEmitDiagnostics( - // (11,26): error CS8145: Auto-implemented properties cannot return by reference - // ref var p0 = ref C.P0; - Diagnostic(ErrorCode.ERR_AutoPropertyCannotBeRefReturning, "C.P0").WithLocation(11, 26), - // (12,26): error CS8145: Auto-implemented properties cannot return by reference - // ref var p1 = ref C.P1; - Diagnostic(ErrorCode.ERR_AutoPropertyCannotBeRefReturning, "C.P1").WithLocation(12, 26) + // (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) ); }