Skip to content

Commit 74dd853

Browse files
authored
Fix definite assignment error in regex source gen for some lazy loops (#104007)
1 parent d23f852 commit 74dd853

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/libraries/System.Text.RegularExpressions/gen/RegexGenerator.Emitter.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3458,7 +3458,8 @@ void EmitSingleCharLazy(RegexNode node, RegexNode? subsequent = null, bool emitL
34583458
maxIterations = $"{node.N - node.M}";
34593459

34603460
iterationCount = ReserveName("lazyloop_iteration");
3461-
writer.WriteLine($"int {iterationCount} = 0;");
3461+
additionalDeclarations.Add($"int {iterationCount} = 0;");
3462+
writer.WriteLine($"{iterationCount} = 0;");
34623463
}
34633464

34643465
// Track the current crawl position. Upon backtracking, we'll unwind any captures beyond this point.

src/libraries/System.Text.RegularExpressions/tests/FunctionalTests/Regex.Groups.Tests.cs

+2
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,8 @@ public static IEnumerable<object[]> Groups_MemberData()
956956

957957
yield return (enUS, @"(?((\w{3}))\1\1|no)", "dogdogdog", RegexOptions.None, new string[] { "dogdog", "dog" });
958958
yield return (enUS, @"(?((\w{3}))\1\1|no)", "no", RegexOptions.None, new string[] { "no", "" });
959+
960+
yield return (enUS, @"(?()|.??(?<=))(?!.)", "", RegexOptions.None, new string[] { "" });
959961
}
960962

961963
// Special cases involving starting position search optimizations

0 commit comments

Comments
 (0)