Skip to content

Commit 6d61ec7

Browse files
committed
fxing stuff, AssertOpCodes will work only for NET8+
1 parent aaf0aa4 commit 6d61ec7

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/FastExpressionCompiler/FastExpressionCompiler.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1892,7 +1892,8 @@ private static bool TryCompileNestedLambda(ref ClosureInfo nestedClosureInfo, Ne
18921892
}
18931893

18941894
/// <summary>Return IDelegateDebugInfo if the delegate is fast compiled with `CompilerFlags.EnableDelegateDebugInfo` flag</summary>
1895-
public static IDelegateDebugInfo TryGetDebugInfo<D>(this D d) where D : Delegate => d.Target as IDelegateDebugInfo;
1895+
public static IDelegateDebugInfo TryGetDebugInfo<TDelegate>(this TDelegate d)
1896+
where TDelegate : Delegate => d?.Target as IDelegateDebugInfo;
18961897

18971898
#if LIGHT_EXPRESSION
18981899
private static Result TryCollectMemberInitExprConstants(ref ClosureInfo closure, MemberInitExpression expr,

src/FastExpressionCompiler/TestTools.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ static TestTools()
4444

4545
public static void AssertOpCodes(this Delegate dlg, params OpCode[] expectedCodes)
4646
{
47-
if (dlg.TryGetDebugInfo() is var diagInfo)
47+
var diagInfo = dlg.TryGetDebugInfo();
48+
if (diagInfo != null)
4849
AssertOpCodes(diagInfo.ILInstructions, expectedCodes);
4950
else
5051
AssertOpCodes(dlg.Method, expectedCodes);
@@ -58,14 +59,14 @@ public static void AssertOpCodes(this IDelegateDebugInfo debugInfo, params OpCod
5859

5960
public static void AssertOpCodes(this IEnumerable<ILInstruction> il, params OpCode[] expectedCodes)
6061
{
62+
#if NET8_0_OR_GREATER
6163
if (DisableAssertOpCodes) return;
6264

63-
var actualCodes = il.Select(x => x.OpCode).ToArray();
64-
6565
var sb = new StringBuilder();
6666
var index = 0;
67-
foreach (var code in actualCodes)
67+
foreach (var i in il)
6868
{
69+
var code = i.OpCode;
6970
if (index < 1000)
7071
sb.AppendLine($"{index,-4}{code}");
7172
else if (index < 10000000)
@@ -75,7 +76,8 @@ public static void AssertOpCodes(this IEnumerable<ILInstruction> il, params OpCo
7576
++index;
7677
}
7778

78-
Asserts.AreEqual(expectedCodes, actualCodes);
79+
Asserts.AreEqual(expectedCodes, il.Select(x => x.OpCode));
80+
#endif
7981
}
8082

8183
public static void PrintExpression(this Expression expr, bool completeTypeNames = false)

0 commit comments

Comments
 (0)