From 6ae8466979a566a89b1f30ab1348e995034714a0 Mon Sep 17 00:00:00 2001 From: Siegfried Pammer Date: Sat, 4 Jul 2026 13:11:08 +0200 Subject: [PATCH] Add pretty test for exception filters with side effects All existing filter tests only read state; a filter that mutates a ref local observed by the handler pins the ordering between the filter expression and the handler body. Assisted-by: Claude:claude-fable-5:Claude Code --- .../TestCases/Pretty/ExceptionHandling.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.cs b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.cs index 090ccc71c..d564f15ff 100644 --- a/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.cs +++ b/ICSharpCode.Decompiler.Tests/TestCases/Pretty/ExceptionHandling.cs @@ -500,6 +500,25 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty #pragma warning restore CA2200 // Rethrow to preserve stack details } } + + private static bool FilterWithSideEffect(Exception e, ref int log) + { + log++; + return e.Message.Length > 0; + } + + public static void SideEffectingFilter() + { + int log = 0; + try + { + Console.WriteLine("try"); + } + catch (Exception e) when (FilterWithSideEffect(e, ref log)) + { + Console.WriteLine(log); + } + } #endif public static void ContinueInCatchInForeach(int[] arr)