From 48f180dae809121d3fcedeb551a5385e6bab83b9 Mon Sep 17 00:00:00 2001 From: Omar Tawfik Date: Fri, 29 Sep 2017 05:05:25 -0700 Subject: [PATCH] clean up --- .../CSharp/Portable/Parser/LanguageParser.cs | 6 +-- ...rsTests.cs => CodeGenInParametersTests.cs} | 0 .../InKeywordRecommenderTests.cs | 9 ++++ .../ThisKeywordRecommenderTests.cs | 49 ++++++++++++++----- .../ContextQuery/SyntaxTreeExtensions.cs | 2 +- 5 files changed, 47 insertions(+), 19 deletions(-) rename src/Compilers/CSharp/Test/Emit/CodeGen/{CodeGenRefReadOnlyParametersTests.cs => CodeGenInParametersTests.cs} (100%) diff --git a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs index 842fe906349..d088ccec5e8 100644 --- a/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs +++ b/src/Compilers/CSharp/Portable/Parser/LanguageParser.cs @@ -5895,11 +5895,6 @@ private ScanTypeFlags ScanNonArrayType(ParseTypeMode mode, out SyntaxToken lastT this.EatToken(); } } - else if (this.CurrentToken.Kind == SyntaxKind.InKeyword) - { - // Start of a lambda parameter - this.EatToken(); - } if (this.CurrentToken.Kind == SyntaxKind.IdentifierToken) { @@ -9815,6 +9810,7 @@ private bool ScanExplicitlyTypedLambda(Precedence precedence) } break; case SyntaxKind.OutKeyword: + case SyntaxKind.InKeyword: case SyntaxKind.ParamsKeyword: this.EatToken(); foundParameterModifier = true; diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenRefReadOnlyParametersTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenInParametersTests.cs similarity index 100% rename from src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenRefReadOnlyParametersTests.cs rename to src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenInParametersTests.cs diff --git a/src/EditorFeatures/CSharpTest2/Recommendations/InKeywordRecommenderTests.cs b/src/EditorFeatures/CSharpTest2/Recommendations/InKeywordRecommenderTests.cs index f3aea0bd8ea..442a5f2b9b2 100644 --- a/src/EditorFeatures/CSharpTest2/Recommendations/InKeywordRecommenderTests.cs +++ b/src/EditorFeatures/CSharpTest2/Recommendations/InKeywordRecommenderTests.cs @@ -422,5 +422,14 @@ class Program public $$ int Test { get; set; } }"); } + + [Test.Utilities.CompilerTrait(Test.Utilities.CompilerFeature.ReadOnlyReferences)] + [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] + public async Task TestNotAfterThis() + { + await VerifyAbsenceAsync( +@"static class C { + static void Goo(this $$"); + } } } diff --git a/src/EditorFeatures/CSharpTest2/Recommendations/ThisKeywordRecommenderTests.cs b/src/EditorFeatures/CSharpTest2/Recommendations/ThisKeywordRecommenderTests.cs index 6a8ed59e44f..8dcd0057b01 100644 --- a/src/EditorFeatures/CSharpTest2/Recommendations/ThisKeywordRecommenderTests.cs +++ b/src/EditorFeatures/CSharpTest2/Recommendations/ThisKeywordRecommenderTests.cs @@ -120,6 +120,14 @@ public async Task TestNotAfterRef() void Goo(ref $$"); } + [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] + public async Task TestNotAfterIn() + { + await VerifyAbsenceAsync( +@"class C { + void Goo(in $$"); + } + [Fact, Trait(Traits.Feature, Traits.Features.KeywordRecommending)] public async Task TestNotAfterThis_InBogusMethod() { @@ -647,7 +655,22 @@ public static class Extensions public static void Extension(ref $$ object obj, int x) { } }"); } - + + [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() { @@ -664,17 +687,17 @@ public static class Extensions } [Fact] - public async Task TestExtensionMethods_SecondParameter_AfterRefReadonlyKeywords_InClass() + public async Task TestExtensionMethods_SecondParameter_AfterInKeywords_InClass() { await VerifyAbsenceAsync(@" public static class Extensions { - public static void Extension(int x, ref readonly $$"); + public static void Extension(int x, in $$"); await VerifyAbsenceAsync(@" public static class Extensions { - public static void Extension(int x, ref readonly $$ object obj) { } + public static void Extension(int x, in $$ object obj) { } }"); } @@ -687,11 +710,11 @@ public async Task TestExtensionMethods_FirstParameter_AfterRefKeyword_OutsideCla } [Fact] - public async Task TestExtensionMethods_FirstParameter_AfterRefReadOnlyKeywords_OutsideClass() + public async Task TestExtensionMethods_FirstParameter_AfterInKeywords_OutsideClass() { - await VerifyAbsenceAsync("public static void Extension(ref readonly $$"); + await VerifyAbsenceAsync("public static void Extension(in $$"); - await VerifyAbsenceAsync("public static void Extension(ref readonly $$ object obj, int x) { }"); + await VerifyAbsenceAsync("public static void Extension(in $$ object obj, int x) { }"); } [Fact] @@ -710,17 +733,17 @@ public class Extensions } [Fact] - public async Task TestExtensionMethods_FirstParameter_AfterRefReadOnlyKeywords_NonStaticClass() + public async Task TestExtensionMethods_FirstParameter_AfterInKeywords_NonStaticClass() { await VerifyAbsenceAsync(@" public class Extensions { - public static void Extension(ref readonly $$"); + public static void Extension(in $$"); await VerifyAbsenceAsync(@" public class Extensions { - public static void Extension(ref readonly $$ object obj, int x) { } + public static void Extension(in $$ object obj, int x) { } }"); } @@ -740,17 +763,17 @@ public static class Extensions } [Fact] - public async Task TestExtensionMethods_FirstParameter_AfterRefReadOnlyKeywords_NonStaticMethod() + public async Task TestExtensionMethods_FirstParameter_AfterInKeywords_NonStaticMethod() { await VerifyAbsenceAsync(@" public static class Extensions { - public void Extension(ref readonly $$"); + public void Extension(in $$"); await VerifyAbsenceAsync(@" public static class Extensions { - public void Extension(ref readonly $$ object obj, int x) { } + public void Extension(in $$ object obj, int x) { } }"); } } diff --git a/src/Workspaces/CSharp/Portable/Extensions/ContextQuery/SyntaxTreeExtensions.cs b/src/Workspaces/CSharp/Portable/Extensions/ContextQuery/SyntaxTreeExtensions.cs index 132e8712c8c..0dc4d6c2227 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.RefKeyword) || token.IsKind(SyntaxKind.InKeyword)) && token.Parent.GetParent().IsDelegateOrConstructorOrLocalFunctionOrMethodParameterList()) { var parameter = token.GetAncestor(); -- GitLab