From: Stephen Toub Date: Wed, 4 Jan 2023 12:57:57 +0000 (-0500) Subject: Delete erroneous simplifer annotation for regex fixer (#80126) X-Git-Tag: accepted/tizen/unified/riscv/20231226.055536~4843 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=88f75a83803a3b7fe59bcdb3eb748eefa4d35ddb;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Delete erroneous simplifer annotation for regex fixer (#80126) * Delete erroneous simplifer annotation for regex fixer * Fix a few test failures due to lack of simplification --- diff --git a/src/libraries/System.Text.RegularExpressions/gen/UpgradeToGeneratedRegexCodeFixer.cs b/src/libraries/System.Text.RegularExpressions/gen/UpgradeToGeneratedRegexCodeFixer.cs index 442976d648b..e18a40c946c 100644 --- a/src/libraries/System.Text.RegularExpressions/gen/UpgradeToGeneratedRegexCodeFixer.cs +++ b/src/libraries/System.Text.RegularExpressions/gen/UpgradeToGeneratedRegexCodeFixer.cs @@ -16,7 +16,6 @@ using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Editing; using Microsoft.CodeAnalysis.Operations; -using Microsoft.CodeAnalysis.Simplification; using Microsoft.CodeAnalysis.Text; namespace System.Text.RegularExpressions.Generator @@ -129,7 +128,7 @@ namespace System.Text.RegularExpressions.Generator if (!typeDeclaration.Modifiers.Any(m => m.IsKind(SyntaxKind.PartialKeyword))) { typesModified++; - return typeDeclaration.AddModifiers(SyntaxFactory.Token(SyntaxKind.PartialKeyword)).WithAdditionalAnnotations(Simplifier.Annotation); + return typeDeclaration.AddModifiers(SyntaxFactory.Token(SyntaxKind.PartialKeyword)); } return typeDeclaration; diff --git a/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/UpgradeToGeneratedRegexAnalyzerTests.cs b/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/UpgradeToGeneratedRegexAnalyzerTests.cs index 9dafdf41020..2de03c9b3f4 100644 --- a/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/UpgradeToGeneratedRegexAnalyzerTests.cs +++ b/src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/UpgradeToGeneratedRegexAnalyzerTests.cs @@ -754,6 +754,37 @@ partial class Program Regex r = MyRegex(); } + [GeneratedRegex(""a|b"", RegexOptions.None)] + private static partial Regex MyRegex(); +}"; + + await VerifyCS.VerifyCodeFixAsync(test, fixedSource); + } + + [Fact] + public async Task CodeFixerDoesNotSimplifyStyle() + { + string test = @"using System.Text.RegularExpressions; + +class Program +{ + static void Main() + { + int i = (4 - 4); // this shouldn't be changed by fixer + Regex r = [|new Regex(options: RegexOptions.None, pattern: ""a|b"")|]; + } +}"; + + string fixedSource = @"using System.Text.RegularExpressions; + +partial class Program +{ + static void Main() + { + int i = (4 - 4); // this shouldn't be changed by fixer + Regex r = MyRegex(); + } + [GeneratedRegex(""a|b"", RegexOptions.None)] private static partial Regex MyRegex(); }"; @@ -942,7 +973,7 @@ public partial class A Regex regex = MyRegex(); } - [GeneratedRegex(""pattern"", (RegexOptions)2048)] + [GeneratedRegex(""pattern"", (RegexOptions)(2048))] private static partial Regex MyRegex(); } "; @@ -974,7 +1005,7 @@ public partial class A Regex regex = MyRegex(); } - [GeneratedRegex(""pattern"", (RegexOptions)2048)] + [GeneratedRegex(""pattern"", (RegexOptions)(2048))] private static partial Regex MyRegex(); } ";