Report the halted-ILAst write through a return value

The ref parameter was only there because a partial method could not return one.
An extended partial can, so the caller reads the answer where it uses it. The
implementation stays behind DEBUG, which now needs a Release counterpart: an
extended partial must have one in every configuration, and there the step limit
is never set, so it never writes.

Assisted-by: Claude:claude-opus-5[1m]:Claude Code
This commit is contained in:
Siegfried Pammer
2026-08-27 09:46:03 +02:00
parent 1e95c82a52
commit 72ed28f903
2 changed files with 13 additions and 10 deletions
+3 -3
View File
@@ -56,10 +56,10 @@ namespace ICSharpCode.ILSpy.Languages
/// highlighting unambiguous, and which member the limit lands in follows decompilation order,
/// not the user's selection.
/// </summary>
static partial void TryWriteILAst(ITextOutput output, DecompilationOptions options, CSharpDecompiler decompiler, ref bool handled)
private static partial bool TryWriteILAst(ITextOutput output, DecompilationOptions options, CSharpDecompiler decompiler)
{
if (decompiler.StepLimitHaltedFunction is not { } function)
return;
return false;
if (output is AvaloniaEditTextOutput avaloniaOutput)
{
// The dump is IL, not C#; without this the editor would highlight it as C#.
@@ -67,7 +67,7 @@ namespace ICSharpCode.ILSpy.Languages
}
output.WriteLine();
function.WriteTo(output, DebugStepsPane?.WritingOptions ?? new ILAstWritingOptions());
handled = true;
return true;
}
/// <summary>
+10 -7
View File
@@ -738,9 +738,7 @@ namespace ICSharpCode.ILSpy.Languages
static void WriteCode(ITextOutput output, DecompilationOptions options, SyntaxTree syntaxTree, CSharpDecompiler decompiler)
{
bool handled = false;
TryWriteILAst(output, options, decompiler, ref handled);
if (!handled)
if (!TryWriteILAst(output, options, decompiler))
{
var settings = options.DecompilerSettings;
syntaxTree.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true });
@@ -776,10 +774,15 @@ namespace ICSharpCode.ILSpy.Languages
}
}
// Implemented only under DEBUG (CSharpLanguage.DebugSteps.cs): writes the ILAst the pipeline was
// halted in, when a Debug Steps replay stopped it before there was any C# to show. A no-op
// partial in Release, where nothing sets a step limit.
static partial void TryWriteILAst(ITextOutput output, DecompilationOptions options, CSharpDecompiler decompiler, ref bool handled);
// Writes the ILAst the pipeline was halted in, when a Debug Steps replay stopped it before
// there was any C# to show, and reports whether it wrote anything. Implemented under DEBUG in
// CSharpLanguage.DebugSteps.cs; in Release nothing sets a step limit, so it never writes.
private static partial bool TryWriteILAst(ITextOutput output, DecompilationOptions options, CSharpDecompiler decompiler);
#if !DEBUG
private static partial bool TryWriteILAst(ITextOutput output, DecompilationOptions options, CSharpDecompiler decompiler)
=> false;
#endif
void AddWarningMessage(MetadataFile module, ITextOutput output, string line1, string? line2 = null,
string? buttonText = null, global::Avalonia.Media.IImage? buttonImage = null,