Reputation: 81
In my project, I use the GeneratedRegex attribute like so:
public partial class Game
{
...
[GeneratedRegex(@"<regex>", RegexOptions.Compiled, "en-US")]
private static partial Regex MoveLegalityRegex();
...
}
The regex inputted into the generator is:
@"(?<!.)(([1-4](10|a|A|k|K|q|Q|j|J|[2-9]))|bs)(?(?<=bs)| ??: ??(?(?<=1\3 ??: ??)(10|a|A|k|K|q|Q|j|J|[2-9]){1}|((?<=2.{2,5}?)(10|a|A|k|K|q|Q|j|J|[2-9]){2}|((?<=3.{2,5}?)(10|a|A|k|K|q|Q|j|J|[2-9]){3}|((?<=4.{2,5}?)(10|a|A|k|K|q|Q|j|J|[2-9]){4})))))(?!.)"
When I compile my code to run, it throws the following error: Line 466: Use of unassigned local variable 'lazyloop_iteration' (CS0165)
After some digging in the RegexGenerator.g.cs file, I find the relevant chunk of code:
// Match ' ' lazily, optionally.
//{
pos++;
slice = inputSpan.Slice(pos);
int lazyloop_iteration = 0;
lazyloop_pos = pos;
goto LazyLoopEnd;
LazyLoopBacktrack:
UncaptureUntil(lazyloop_capturepos);
if (lazyloop_iteration >= 1)
{
goto CaptureBacktrack2;
}
lazyloop_iteration++;
if (Utilities.s_hasTimeout)
{
base.CheckTimeout();
}
pos = lazyloop_pos;
slice = inputSpan.Slice(pos);
if (slice.IsEmpty || slice[0] != ' ')
{
goto CaptureBacktrack2;
}
pos++;
slice = inputSpan.Slice(pos);
lazyloop_pos = pos;
LazyLoopEnd:
lazyloop_capturepos = base.Crawlpos();
//}
I can't edit this file, as it is auto-generated so I'm not sure what to do. Can anyone explain how I can fix this, if there is a problem with my regex, or is there some other issue going on?
I tried using the GeneratedRegex attribute with the regex described. I expected the GeneratedRegex would generate an implementation of my specified regex without issue or error. The resulting regex generated was not error-free and I was not able to fix it, as the file is read-only.
UPDATE:
When I try to compile the project, it fails because of this error.
I'm using .NET version 7. For me, SYSLIB1044 (couldn't generate implementation) does not appear on my code and there is a file generated by the RegexGenerator that includes a full source implementation of the regex. It does not include any remarks about it being unable to support any feature of my regex.
Restarting Visual Studio does not fix the issue. Neither does running the project directly from the terminal using dotnet run
.
Upvotes: 4
Views: 343
Reputation: 81
Fixed by dotnet runtime:
See https://github.com/dotnet/runtime/issues/103942 for more details
Upvotes: 2