-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System.Linq.Expressions; | ||
using System.Reflection; | ||
using DotNext.Linq.Expressions; | ||
|
||
namespace DotNext.Metaprogramming; | ||
|
||
using static Linq.Expressions.ExpressionBuilder; | ||
using static Metaprogramming.CodeGenerator; | ||
|
||
public sealed class RegressionIssue223 : Test | ||
{ | ||
[Fact] | ||
public static async Task ThrowOnReturn() | ||
{ | ||
var lambda = AsyncLambda<Func<Task<int>>>(_ => | ||
{ | ||
Try(() => | ||
{ | ||
var methodInfo = new Func<Task<int>>(Throw).Method; | ||
var methodResult = Expression.Call(null, methodInfo); | ||
|
||
Return(methodResult.Await()); | ||
}) | ||
.Catch(typeof(Exception), _ => | ||
{ | ||
CallStatic(typeof(Console), nameof(Console.WriteLine), Expression.Constant("Exception caught")); | ||
}) | ||
.End(); | ||
}); | ||
|
||
var action = lambda.Compile(); | ||
|
||
Equal(0, await action()); | ||
|
||
static async Task<int> Throw() | ||
{ | ||
await Task.Yield(); | ||
throw new InvalidOperationException("Exception was not caught"); | ||
} | ||
} | ||
} |