-
-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathIssue430_TryCatch_Bad_label_content_in_ILGenerator.cs
More file actions
56 lines (43 loc) · 1.48 KB
/
Issue430_TryCatch_Bad_label_content_in_ILGenerator.cs
File metadata and controls
56 lines (43 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
#if LIGHT_EXPRESSION
using static FastExpressionCompiler.LightExpression.Expression;
namespace FastExpressionCompiler.LightExpression.IssueTests;
#else
using static System.Linq.Expressions.Expression;
namespace FastExpressionCompiler.IssueTests;
#endif
public class Issue430_TryCatch_Bad_label_content_in_ILGenerator : ITest
{
public int Run()
{
Original_case();
return 1;
}
public static void DoSome() { }
public void Original_case()
{
var returnLabelTarget = Label(typeof(int), "ReturnLabel");
var method = GetType().GetMethod("DoSome");
var expr = Lambda<Func<int>>(
Block(
TryCatch(
Block(Call(method), Return(returnLabelTarget, Constant(1))),
Catch(typeof(Exception), Return(returnLabelTarget, Constant(10)))),
Call(method),
Return(returnLabelTarget, Constant(5)),
Label(returnLabelTarget, Constant(0))));
expr.PrintCSharp();
#if LIGHT_EXPRESSION
var sysExpr = expr.ToLambdaExpression();
var restoredExpr = sysExpr.ToLightExpression();
restoredExpr.PrintCSharp();
Asserts.IsTrue(expr.EqualsTo(restoredExpr));
#endif
var fs = expr.CompileSys();
fs.PrintIL();
Asserts.AreEqual(1, fs());
var ff = expr.CompileFast(true, CompilerFlags.ThrowOnNotSupportedExpression);
ff.PrintIL();
Asserts.AreEqual(1, ff());
}
}