From cdb3a9c7692584af3c5615c42387d94862a09d66 Mon Sep 17 00:00:00 2001 From: Omar Tawfik Date: Wed, 22 Feb 2017 21:37:38 -0800 Subject: [PATCH] Reverse readonly ref to ref readonly in declarations --- .../Portable/Binder/Binder_Statements.cs | 2 +- .../CSharp/Portable/Parser/LanguageParser.cs | 39 +++------ .../CSharp/Portable/PublicAPI.Unshipped.txt | 4 +- .../CSharp/Portable/Symbols/MethodSymbol.cs | 6 +- .../CSharp/Portable/Syntax/RefTypeSyntax.cs | 4 +- .../CSharp/Portable/Syntax/Syntax.xml | 6 +- .../CodeGen/CodeGenReadonlyRefReturnTests.cs | 2 +- .../Syntax/Parsing/DeclarationParsingTests.cs | 18 ++--- .../Syntax/Parsing/ReadonlyRefReturnsTests.cs | 81 +++++++++---------- .../Core/Portable/PublicAPI.Unshipped.txt | 4 +- .../Core/Portable/Symbols/IMethodSymbol.cs | 6 +- .../Core/Portable/Symbols/RefKind.cs | 8 +- .../Portable/Symbols/MethodSymbol.vb | 4 +- ...dataAsSourceService.WrappedMethodSymbol.cs | 4 +- .../CodeGenerationAbstractMethodSymbol.cs | 2 +- .../CodeGenerationConstructedMethodSymbol.cs | 4 +- .../Symbols/CodeGenerationMethodSymbol.cs | 6 +- 17 files changed, 91 insertions(+), 109 deletions(-) diff --git a/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs b/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs index 852fa793b70..4c8235ad822 100644 --- a/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs +++ b/src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs @@ -786,7 +786,7 @@ private TypeSymbol BindVariableType(CSharpSyntaxNode declarationNode, Diagnostic // might own nested scope. bool hasErrors = localSymbol.ScopeBinder.ValidateDeclarationNameConflictsInScope(localSymbol, diagnostics); - if (localSymbol.RefKind == RefKind.In) + if (localSymbol.RefKind == RefKind.RefReadOnly) { var refKeyword = typeSyntax.GetFirstToken(); diagnostics.Add(ErrorCode.ERR_UnexpectedToken, refKeyword.GetLocation(), refKeyword.ToString()); diff --git a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs index 00ee8af4cf8..aea51389f51 100644 --- a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs +++ b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs @@ -1355,16 +1355,6 @@ private void ParseModifiers(SyntaxListBuilder tokens) } return; } - case SyntaxModifier.ReadOnly: - { - if (PeekToken(1).Kind == SyntaxKind.RefKeyword) - { - // readonly is not a modifier in "readonly ref", since "ref" is not a modifier. - return; - } - - goto default; - } default: { modTok = this.EatToken(); @@ -6308,16 +6298,14 @@ private ScanTypeFlags ScanNonArrayType(ParseTypeMode mode, out SyntaxToken lastT { ScanTypeFlags result; - // in a ref local or ref return, we treat "ref" and "readonly ref" as part of the type - if (this.CurrentToken.Kind == SyntaxKind.ReadOnlyKeyword && - this.PeekToken(1).Kind == SyntaxKind.RefKeyword) - { - this.EatToken(); - this.EatToken(); - } - else if (this.CurrentToken.Kind == SyntaxKind.RefKeyword) + // in a ref local or ref return, we treat "ref" and "ref readonly" as part of the type + if (this.CurrentToken.Kind == SyntaxKind.RefKeyword) { this.EatToken(); + if (this.CurrentToken.Kind == SyntaxKind.ReadOnlyKeyword) + { + this.EatToken(); + } } if (this.CurrentToken.Kind == SyntaxKind.IdentifierToken) @@ -6529,21 +6517,20 @@ private enum ParseTypeMode ParseTypeMode mode = ParseTypeMode.Normal, bool expectSizes = false) { - if (mode == ParseTypeMode.Normal && !expectSizes) + if (mode == ParseTypeMode.Normal && !expectSizes && this.CurrentToken.Kind == SyntaxKind.RefKeyword) { + var refKeyword = this.EatToken(); + refKeyword = this.CheckFeatureAvailability(refKeyword, MessageID.IDS_FeatureRefLocalsReturns); + SyntaxToken readonlyKeyword = null; - if (this.CurrentToken.Kind == SyntaxKind.ReadOnlyKeyword && this.PeekToken(1).Kind == SyntaxKind.RefKeyword) + if (this.CurrentToken.Kind == SyntaxKind.ReadOnlyKeyword) { readonlyKeyword = this.EatToken(); readonlyKeyword = this.CheckFeatureAvailability(readonlyKeyword, MessageID.IDS_FeatureReadonlyReferences); } - if (this.CurrentToken.Kind == SyntaxKind.RefKeyword) - { - var refKeyword = this.EatToken(); - var type = ParseTypeCore(mode, expectSizes); - return this.CheckFeatureAvailability(_syntaxFactory.RefType(readonlyKeyword, refKeyword, type), MessageID.IDS_FeatureRefLocalsReturns); - } + var type = ParseTypeCore(mode, expectSizes); + return _syntaxFactory.RefType(refKeyword, readonlyKeyword, type); } return ParseTypeCore(mode, expectSizes); diff --git a/src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt b/src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt index 40c902de01a..448d8cdca52 100644 --- a/src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt +++ b/src/Compilers/CSharp/Portable/PublicAPI.Unshipped.txt @@ -115,7 +115,7 @@ Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax.ReadOnlyKeyword.get -> Microsoft.CodeAnalysis.SyntaxToken Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax.RefKeyword.get -> Microsoft.CodeAnalysis.SyntaxToken Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax.Type.get -> Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax -Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax.Update(Microsoft.CodeAnalysis.SyntaxToken readOnlyKeyword, Microsoft.CodeAnalysis.SyntaxToken refKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax type) -> Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax +Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax.Update(Microsoft.CodeAnalysis.SyntaxToken refKeyword, Microsoft.CodeAnalysis.SyntaxToken readOnlyKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax type) -> Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax.Update(Microsoft.CodeAnalysis.SyntaxToken refKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax type) -> Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax.WithReadOnlyKeyword(Microsoft.CodeAnalysis.SyntaxToken readOnlyKeyword) -> Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax.WithRefKeyword(Microsoft.CodeAnalysis.SyntaxToken refKeyword) -> Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax @@ -298,7 +298,7 @@ static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.ParenthesizedVariableDesignat static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.RefExpression(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax expression) -> Microsoft.CodeAnalysis.CSharp.Syntax.RefExpressionSyntax static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.RefExpression(Microsoft.CodeAnalysis.SyntaxToken refKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax expression) -> Microsoft.CodeAnalysis.CSharp.Syntax.RefExpressionSyntax static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.RefType(Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax type) -> Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax -static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.RefType(Microsoft.CodeAnalysis.SyntaxToken readOnlyKeyword, Microsoft.CodeAnalysis.SyntaxToken refKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax type) -> Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax +static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.RefType(Microsoft.CodeAnalysis.SyntaxToken refKeyword, Microsoft.CodeAnalysis.SyntaxToken readOnlyKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax type) -> Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.RefType(Microsoft.CodeAnalysis.SyntaxToken refKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax type) -> Microsoft.CodeAnalysis.CSharp.Syntax.RefTypeSyntax static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.SingleVariableDesignation(Microsoft.CodeAnalysis.SyntaxToken identifier) -> Microsoft.CodeAnalysis.CSharp.Syntax.SingleVariableDesignationSyntax static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.ThrowExpression(Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax expression) -> Microsoft.CodeAnalysis.CSharp.Syntax.ThrowExpressionSyntax diff --git a/src/Compilers/CSharp/Portable/Symbols/MethodSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/MethodSymbol.cs index a10605e3da1..74ea1f3e0a2 100644 --- a/src/Compilers/CSharp/Portable/Symbols/MethodSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/MethodSymbol.cs @@ -181,14 +181,14 @@ public bool ReturnsByRef } /// - /// Indicates whether or not the method returns by readonly reference + /// Indicates whether or not the method returns by ref readonly /// - public bool ReturnsByReadonlyRef + public bool ReturnsByRefReadonly { get { Debug.Assert(this.RefKind != RefKind.Out); - return this.RefKind == RefKind.In; + return this.RefKind == RefKind.RefReadOnly; } } diff --git a/src/Compilers/CSharp/Portable/Syntax/RefTypeSyntax.cs b/src/Compilers/CSharp/Portable/Syntax/RefTypeSyntax.cs index 8d2bacf046a..a4d4294fdf7 100644 --- a/src/Compilers/CSharp/Portable/Syntax/RefTypeSyntax.cs +++ b/src/Compilers/CSharp/Portable/Syntax/RefTypeSyntax.cs @@ -11,7 +11,7 @@ public partial class RefTypeSyntax { public RefTypeSyntax Update(SyntaxToken refKeyword, TypeSyntax type) { - return Update(default(SyntaxToken), refKeyword, type); + return Update(refKeyword, default(SyntaxToken), type); } } } @@ -23,7 +23,7 @@ public partial class SyntaxFactory /// Creates a new RefTypeSyntax instance. public static RefTypeSyntax RefType(SyntaxToken refKeyword, TypeSyntax type) { - return RefType(default(SyntaxToken), refKeyword, type); + return RefType(refKeyword, default(SyntaxToken), type); } } } diff --git a/src/Compilers/CSharp/Portable/Syntax/Syntax.xml b/src/Compilers/CSharp/Portable/Syntax/Syntax.xml index 0a9c7ef9d2f..debf5eca54a 100644 --- a/src/Compilers/CSharp/Portable/Syntax/Syntax.xml +++ b/src/Compilers/CSharp/Portable/Syntax/Syntax.xml @@ -298,15 +298,15 @@ The ref modifier of a method's return value or a local. + + + Gets the optional "readonly" keyword. - - - diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenReadonlyRefReturnTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenReadonlyRefReturnTests.cs index 170f424644f..2b51054b516 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenReadonlyRefReturnTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenReadonlyRefReturnTests.cs @@ -21,7 +21,7 @@ public void RefReturnArrayAccess() var text = @" class Program { - static readonly ref int M() + static ref readonly int M() { return ref (new int[1])[0]; } diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs index 1769ca5fc28..37201cc79cd 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/DeclarationParsingTests.cs @@ -1981,7 +1981,7 @@ public void TestDelegateWithRefReturnType() [Fact] public void TestDelegateWithReadonlyRefReturnType() { - var text = "delegate readonly ref a b();"; + var text = "delegate ref readonly a b();"; var file = this.ParseFile(text, TestOptions.Regular); Assert.NotNull(file); @@ -1993,7 +1993,7 @@ public void TestDelegateWithReadonlyRefReturnType() var ds = (DelegateDeclarationSyntax)file.Members[0]; Assert.NotNull(ds.DelegateKeyword); Assert.NotNull(ds.ReturnType); - Assert.Equal("readonly ref a", ds.ReturnType.ToString()); + Assert.Equal("ref readonly a", ds.ReturnType.ToString()); Assert.NotNull(ds.Identifier); Assert.Equal("b", ds.Identifier.ToString()); Assert.NotNull(ds.ParameterList.OpenParenToken); @@ -2498,7 +2498,7 @@ public void TestClassMethodWithRefReturn() [Fact] public void TestClassMethodWithReadonlyRefReturn() { - var text = "class a { readonly ref b X() { } }"; + var text = "class a { ref readonly b X() { } }"; var file = this.ParseFile(text, TestOptions.Regular); Assert.NotNull(file); @@ -2525,7 +2525,7 @@ public void TestClassMethodWithReadonlyRefReturn() var ms = (MethodDeclarationSyntax)cs.Members[0]; Assert.Equal(0, ms.AttributeLists.Count); Assert.NotNull(ms.ReturnType); - Assert.Equal("readonly ref b", ms.ReturnType.ToString()); + Assert.Equal("ref readonly b", ms.ReturnType.ToString()); Assert.NotNull(ms.Identifier); Assert.Equal("X", ms.Identifier.ToString()); Assert.NotNull(ms.ParameterList.OpenParenToken); @@ -2572,7 +2572,7 @@ public void TestClassMethodWithRef() [Fact] public void TestClassMethodWithReadonlyRef() { - var text = "class a { readonly ref }"; + var text = "class a { ref readonly }"; var file = this.ParseFile(text, parseOptions: TestOptions.Regular); Assert.NotNull(file); @@ -3946,7 +3946,7 @@ public void TestClassPropertyWithRefReturn() [Fact] public void TestClassPropertyWithReadonlyRefReturn() { - var text = "class a { readonly ref b c { get; set; } }"; + var text = "class a { ref readonly b c { get; set; } }"; var file = this.ParseFile(text, TestOptions.Regular); Assert.NotNull(file); @@ -3974,7 +3974,7 @@ public void TestClassPropertyWithReadonlyRefReturn() Assert.Equal(0, ps.AttributeLists.Count); Assert.Equal(0, ps.Modifiers.Count); Assert.NotNull(ps.Type); - Assert.Equal("readonly ref b", ps.Type.ToString()); + Assert.Equal("ref readonly b", ps.Type.ToString()); Assert.NotNull(ps.Identifier); Assert.Equal("c", ps.Identifier.ToString()); @@ -4889,7 +4889,7 @@ public void TestClassIndexerWithRefReturn() [Fact] public void TestClassIndexerWithReadonlyRefReturn() { - var text = "class a { readonly ref b this[c d] { get; set; } }"; + var text = "class a { ref readonly b this[c d] { get; set; } }"; var file = this.ParseFile(text, TestOptions.Regular); Assert.NotNull(file); @@ -4917,7 +4917,7 @@ public void TestClassIndexerWithReadonlyRefReturn() Assert.Equal(0, ps.AttributeLists.Count); Assert.Equal(0, ps.Modifiers.Count); Assert.NotNull(ps.Type); - Assert.Equal("readonly ref b", ps.Type.ToString()); + Assert.Equal("ref readonly b", ps.Type.ToString()); Assert.NotNull(ps.ThisKeyword); Assert.Equal("this", ps.ThisKeyword.ToString()); diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/ReadonlyRefReturnsTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/ReadonlyRefReturnsTests.cs index a80f8fac6b1..c5fc2e76234 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/ReadonlyRefReturnsTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/ReadonlyRefReturnsTests.cs @@ -25,35 +25,33 @@ public void ReadonlyRefReturn_CSharp7() var text = @" unsafe class Program { - delegate readonly ref int D1(); + delegate ref readonly int D1(); - static readonly ref T M() + static ref readonly T M() { return ref (new T[1])[0]; } - public virtual readonly ref int* P1 => throw null; + public virtual ref readonly int* P1 => throw null; - public readonly ref int[][] this[int i] => throw null; + public ref readonly int[][] this[int i] => throw null; } "; var comp = CreateCompilationWithMscorlib45(text, parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp7), options: TestOptions.UnsafeDebugDll); comp.VerifyDiagnostics( - // (4,14): error CS8107: Feature 'readonly references' is not available in C# 7. Please use language version 71 or greater. - // delegate readonly ref int D1(); - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "readonly").WithArguments("readonly references", "71").WithLocation(4, 14), - // (6,12): error CS8107: Feature 'readonly references' is not available in C# 7. Please use language version 71 or greater. - // static readonly ref T M() - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "readonly").WithArguments("readonly references", "71").WithLocation(6, 12), - // (11,20): error CS8107: Feature 'readonly references' is not available in C# 7. Please use language version 71 or greater. - // public virtual readonly ref int* P1 => throw null; - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "readonly").WithArguments("readonly references", "71").WithLocation(11, 20), - // (13,12): error CS8107: Feature 'readonly references' is not available in C# 7. Please use language version 71 or greater. - // public readonly ref int[][] this[int i] => throw null; - Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "readonly").WithArguments("readonly references", "71").WithLocation(13, 12) - - ); + // (4,18): error CS8107: Feature 'readonly references' is not available in C# 7. Please use language version 71 or greater. + // delegate ref readonly int D1(); + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "readonly").WithArguments("readonly references", "71").WithLocation(4, 18), + // (6,16): error CS8107: Feature 'readonly references' is not available in C# 7. Please use language version 71 or greater. + // static ref readonly T M() + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "readonly").WithArguments("readonly references", "71").WithLocation(6, 16), + // (11,24): error CS8107: Feature 'readonly references' is not available in C# 7. Please use language version 71 or greater. + // public virtual ref readonly int* P1 => throw null; + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "readonly").WithArguments("readonly references", "71").WithLocation(11, 24), + // (13,16): error CS8107: Feature 'readonly references' is not available in C# 7. Please use language version 71 or greater. + // public ref readonly int[][] this[int i] => throw null; + Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "readonly").WithArguments("readonly references", "71").WithLocation(13, 16)); } [Fact] @@ -67,36 +65,36 @@ static void Main() { } - readonly ref int Field; + ref readonly int Field; - public static readonly ref Program operator +(Program x, Program y) + public static ref readonly Program operator +(Program x, Program y) { throw null; } // this parses fine - static async readonly ref Task M() + static async ref readonly Task M() { throw null; } - public readonly ref virtual int* P1 => throw null; + public ref readonly virtual int* P1 => throw null; } "; ParseAndValidate(text, TestOptions.Regular, // (9,27): error CS1003: Syntax error, '(' expected - // readonly ref int Field; + // ref readonly int Field; Diagnostic(ErrorCode.ERR_SyntaxError, ";").WithArguments("(", ";").WithLocation(9, 27), // (9,27): error CS1026: ) expected - // readonly ref int Field; + // ref readonly int Field; Diagnostic(ErrorCode.ERR_CloseParenExpected, ";").WithLocation(9, 27), // (11,41): error CS1519: Invalid token 'operator' in class, struct, or interface member declaration - // public static readonly ref Program operator +(Program x, Program y) + // public static ref readonly Program operator +(Program x, Program y) Diagnostic(ErrorCode.ERR_InvalidMemberDecl, "operator").WithArguments("operator").WithLocation(11, 41), // (11,41): error CS1519: Invalid token 'operator' in class, struct, or interface member declaration - // public static readonly ref Program operator +(Program x, Program y) + // public static ref readonly Program operator +(Program x, Program y) Diagnostic(ErrorCode.ERR_InvalidMemberDecl, "operator").WithArguments("operator").WithLocation(11, 41), // (12,5): error CS1519: Invalid token '{' in class, struct, or interface member declaration // { @@ -105,12 +103,11 @@ static void Main() // { Diagnostic(ErrorCode.ERR_InvalidMemberDecl, "{").WithArguments("{").WithLocation(12, 5), // (22,25): error CS1031: Type expected - // public readonly ref virtual int* P1 => throw null; + // public ref readonly virtual int* P1 => throw null; Diagnostic(ErrorCode.ERR_TypeExpected, "virtual").WithLocation(22, 25), // (24,1): error CS1022: Type or namespace definition, or end-of-file expected // } - Diagnostic(ErrorCode.ERR_EOFExpected, "}").WithLocation(24, 1) - ); + Diagnostic(ErrorCode.ERR_EOFExpected, "}").WithLocation(24, 1)); } [Fact] @@ -122,11 +119,11 @@ class Program { static void Main() { - readonly ref int local = ref (new int[1])[0]; + ref readonly int local = ref (new int[1])[0]; - (readonly ref int, readonly ref int Alice)? t = null; + (ref readonly int, ref readonly int Alice)? t = null; - System.Collections.Generic.List x = null; + System.Collections.Generic.List x = null; Use(local); Use(t); @@ -142,17 +139,15 @@ static void Use(T dummy) var comp = CreateCompilationWithMscorlib45(text, new[] { ValueTupleRef, SystemRuntimeFacadeRef }); comp.VerifyDiagnostics( - // (9,19): error CS1073: Unexpected token 'ref' - // (readonly ref int, readonly ref int Alice)? t = null; - Diagnostic(ErrorCode.ERR_UnexpectedToken, "ref").WithArguments("ref").WithLocation(9, 19), - // (9,37): error CS1073: Unexpected token 'ref' - // (readonly ref int, readonly ref int Alice)? t = null; - Diagnostic(ErrorCode.ERR_UnexpectedToken, "ref").WithArguments("ref").WithLocation(9, 37), - // (11,50): error CS1073: Unexpected token 'ref' - // System.Collections.Generic.List x = null; - Diagnostic(ErrorCode.ERR_UnexpectedToken, "ref").WithArguments("ref").WithLocation(11, 50) - ); + // (9,10): error CS1073: Unexpected token 'ref' + // (ref readonly int, ref readonly int Alice)? t = null; + Diagnostic(ErrorCode.ERR_UnexpectedToken, "ref").WithArguments("ref").WithLocation(9, 10), + // (9,28): error CS1073: Unexpected token 'ref' + // (ref readonly int, ref readonly int Alice)? t = null; + Diagnostic(ErrorCode.ERR_UnexpectedToken, "ref").WithArguments("ref").WithLocation(9, 28), + // (11,41): error CS1073: Unexpected token 'ref' + // System.Collections.Generic.List x = null; + Diagnostic(ErrorCode.ERR_UnexpectedToken, "ref").WithArguments("ref").WithLocation(11, 41)); } - } } diff --git a/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt b/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt index f98a39a93a4..ac02cb3e47f 100644 --- a/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt +++ b/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt @@ -93,7 +93,7 @@ Microsoft.CodeAnalysis.IDiscardSymbol.Type.get -> Microsoft.CodeAnalysis.ITypeSy Microsoft.CodeAnalysis.IFieldSymbol.CorrespondingTupleField.get -> Microsoft.CodeAnalysis.IFieldSymbol Microsoft.CodeAnalysis.ILocalSymbol.IsRef.get -> bool Microsoft.CodeAnalysis.IMethodSymbol.RefCustomModifiers.get -> System.Collections.Immutable.ImmutableArray -Microsoft.CodeAnalysis.IMethodSymbol.ReturnsByReadonlyRef.get -> bool +Microsoft.CodeAnalysis.IMethodSymbol.ReturnsByRefReadonly.get -> bool Microsoft.CodeAnalysis.IMethodSymbol.ReturnsByRef.get -> bool Microsoft.CodeAnalysis.INamedTypeSymbol.GetTypeArgumentCustomModifiers(int ordinal) -> System.Collections.Immutable.ImmutableArray Microsoft.CodeAnalysis.INamedTypeSymbol.IsComImport.get -> bool @@ -190,7 +190,7 @@ Microsoft.CodeAnalysis.OperationKind.WithStatement = 82 -> Microsoft.CodeAnalysi Microsoft.CodeAnalysis.OperationKind.YieldBreakStatement = 12 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.OperationKind.YieldReturnStatement = 16 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.PortableExecutableReference.GetMetadataId() -> Microsoft.CodeAnalysis.MetadataId -Microsoft.CodeAnalysis.RefKind.In = 3 -> Microsoft.CodeAnalysis.RefKind +Microsoft.CodeAnalysis.RefKind.RefReadOnly = 3 -> Microsoft.CodeAnalysis.RefKind Microsoft.CodeAnalysis.SemanticModel.GetOperation(Microsoft.CodeAnalysis.SyntaxNode node, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> Microsoft.CodeAnalysis.IOperation Microsoft.CodeAnalysis.Semantics.ArgumentKind Microsoft.CodeAnalysis.Semantics.ArgumentKind.DefaultValue = 4 -> Microsoft.CodeAnalysis.Semantics.ArgumentKind diff --git a/src/Compilers/Core/Portable/Symbols/IMethodSymbol.cs b/src/Compilers/Core/Portable/Symbols/IMethodSymbol.cs index fe8a4354680..e0ab8eb61a7 100644 --- a/src/Compilers/Core/Portable/Symbols/IMethodSymbol.cs +++ b/src/Compilers/Core/Portable/Symbols/IMethodSymbol.cs @@ -75,11 +75,11 @@ public interface IMethodSymbol : ISymbol /// bool ReturnsByRef { get; } - // PROTOTYPE(readonlyRef): this is very preliminary. We need to have _some_ API for now. + // PROTOTYPE(refreadonly): this is very preliminary. We need to have _some_ API for now. /// - /// Returns true if this method returns by readonly reference. + /// Returns true if this method returns by ref readonly. /// - bool ReturnsByReadonlyRef { get; } + bool ReturnsByRefReadonly { get; } /// /// Gets the return type of the method. diff --git a/src/Compilers/Core/Portable/Symbols/RefKind.cs b/src/Compilers/Core/Portable/Symbols/RefKind.cs index 9525d050dbd..edb533491eb 100644 --- a/src/Compilers/Core/Portable/Symbols/RefKind.cs +++ b/src/Compilers/Core/Portable/Symbols/RefKind.cs @@ -25,9 +25,9 @@ public enum RefKind : byte Out = 2, /// - /// Indicates an "in" parameter. + /// Indicates a "ref readonly" or an "in" parameter. /// - In = 3, + RefReadOnly = 3, } internal static class RefKindExtensions @@ -38,7 +38,7 @@ internal static string ToDisplayString(this RefKind kind) { case RefKind.Out: return "out"; case RefKind.Ref: return "ref"; - case RefKind.In: return "in"; + case RefKind.RefReadOnly: return "ref readonly"; default: return null; } } @@ -49,7 +49,7 @@ internal static string ToPrefix(this RefKind kind) { case RefKind.Out: return "out "; case RefKind.Ref: return "ref "; - case RefKind.In: return "in "; + case RefKind.RefReadOnly: return "ref readonly "; default: return string.Empty; } } diff --git a/src/Compilers/VisualBasic/Portable/Symbols/MethodSymbol.vb b/src/Compilers/VisualBasic/Portable/Symbols/MethodSymbol.vb index 67949069df8..a1ee95d5783 100644 --- a/src/Compilers/VisualBasic/Portable/Symbols/MethodSymbol.vb +++ b/src/Compilers/VisualBasic/Portable/Symbols/MethodSymbol.vb @@ -949,9 +949,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols End Get End Property - Private ReadOnly Property IMethodSymbol_ReturnsByReadonlyRef As Boolean Implements IMethodSymbol.ReturnsByReadonlyRef + Private ReadOnly Property IMethodSymbol_ReturnsByRefReadonly As Boolean Implements IMethodSymbol.ReturnsByRefReadonly Get - ' PROTOTYPE(readonlyRef): NYI + ' PROTOTYPE(refreadonly): NYI Return False End Get End Property diff --git a/src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService.WrappedMethodSymbol.cs b/src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService.WrappedMethodSymbol.cs index 8958caae334..98b1cf1e65f 100644 --- a/src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService.WrappedMethodSymbol.cs +++ b/src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService.WrappedMethodSymbol.cs @@ -178,11 +178,11 @@ public bool ReturnsByRef } } - public bool ReturnsByReadonlyRef + public bool ReturnsByRefReadonly { get { - return _symbol.ReturnsByReadonlyRef; + return _symbol.ReturnsByRefReadonly; } } diff --git a/src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationAbstractMethodSymbol.cs b/src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationAbstractMethodSymbol.cs index 4bc4cb325ac..36ee3dc4caa 100644 --- a/src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationAbstractMethodSymbol.cs +++ b/src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationAbstractMethodSymbol.cs @@ -32,7 +32,7 @@ public virtual ImmutableArray GetReturnTypeAttributes() public abstract int Arity { get; } public abstract bool ReturnsVoid { get; } public abstract bool ReturnsByRef { get; } - public abstract bool ReturnsByReadonlyRef { get; } + public abstract bool ReturnsByRefReadonly { get; } public abstract ITypeSymbol ReturnType { get; } public abstract ImmutableArray TypeArguments { get; } public abstract ImmutableArray TypeParameters { get; } diff --git a/src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationConstructedMethodSymbol.cs b/src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationConstructedMethodSymbol.cs index 0af58bb9dbd..d68afa43de9 100644 --- a/src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationConstructedMethodSymbol.cs +++ b/src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationConstructedMethodSymbol.cs @@ -48,11 +48,11 @@ public override bool ReturnsByRef } } - public override bool ReturnsByReadonlyRef + public override bool ReturnsByRefReadonly { get { - return _constructedFrom.ReturnsByReadonlyRef; + return _constructedFrom.ReturnsByRefReadonly; } } diff --git a/src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationMethodSymbol.cs b/src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationMethodSymbol.cs index efc9da547df..6e6251bda2a 100644 --- a/src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationMethodSymbol.cs +++ b/src/Workspaces/Core/Portable/CodeGeneration/Symbols/CodeGenerationMethodSymbol.cs @@ -33,7 +33,7 @@ internal partial class CodeGenerationMethodSymbol : CodeGenerationAbstractMethod : base(containingType, attributes, declaredAccessibility, modifiers, name, returnTypeAttributes) { _returnType = returnType; - // PROTOTYPE(readonlyRef): NYI + // PROTOTYPE(refreadonly): NYI _refKind = returnsByRef ? RefKind.Ref: RefKind.None; _typeParameters = typeParameters.AsImmutableOrEmpty(); _parameters = parameters.AsImmutableOrEmpty(); @@ -119,11 +119,11 @@ public override bool ReturnsByRef } } - public override bool ReturnsByReadonlyRef + public override bool ReturnsByRefReadonly { get { - return _refKind == RefKind.In; + return _refKind == RefKind.RefReadOnly; } } -- GitLab