Browse Source

Fix assertion with async lambdas; fix async local functions.

pull/1612/head
Daniel Grunwald 6 years ago
parent
commit
c56714c607
  1. 30
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/Async.cs
  2. 3
      ICSharpCode.Decompiler/CSharp/StatementBuilder.cs
  3. 2
      ICSharpCode.Decompiler/IL/ControlFlow/YieldReturnDecompiler.cs
  4. 2
      ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs

30
ICSharpCode.Decompiler.Tests/TestCases/Pretty/Async.cs

@ -137,6 +137,36 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -137,6 +137,36 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
}
return num;
}
public static Func<Task<int>> AsyncLambda()
{
return async () => await GetIntegerSumAsync(new int[3] {
1,
2,
3
});
}
public static Func<Task<int>> AsyncDelegate()
{
return async delegate {
await Task.Delay(10);
return 2;
};
}
#if CS70
public static async Task<int> AsyncLocalFunctions()
{
return await Nested(1) + await Nested(2);
async Task<int> Nested(int i)
{
await Task.Delay(i);
return i;
}
}
#endif
}
public struct HopToThreadPoolAwaitable : INotifyCompletion

3
ICSharpCode.Decompiler/CSharp/StatementBuilder.cs

@ -968,6 +968,9 @@ namespace ICSharpCode.Decompiler.CSharp @@ -968,6 +968,9 @@ namespace ICSharpCode.Decompiler.CSharp
stmt.Parameters.AddRange(exprBuilder.MakeParameters(function.Parameters, function));
stmt.ReturnType = exprBuilder.ConvertType(function.Method.ReturnType);
stmt.Body = nestedBuilder.ConvertAsBlock(function.Body);
if (function.IsAsync) {
stmt.Modifiers |= Modifiers.Async;
}
stmt.AddAnnotation(new MemberResolveResult(null, function.ReducedMethod));
return stmt;
}

2
ICSharpCode.Decompiler/IL/ControlFlow/YieldReturnDecompiler.cs

@ -390,7 +390,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow @@ -390,7 +390,7 @@ namespace ICSharpCode.Decompiler.IL.ControlFlow
methodTypeParameters: null);
var body = context.TypeSystem.MainModule.PEFile.Reader.GetMethodBody(methodDef.RelativeVirtualAddress);
var il = context.CreateILReader()
.ReadIL(method, body, genericContext, context.Function.Kind, context.CancellationToken);
.ReadIL(method, body, genericContext, ILFunctionKind.TopLevelFunction, context.CancellationToken);
il.RunTransforms(CSharpDecompiler.EarlyILTransforms(true),
new ILTransformContext(il, context.TypeSystem, context.DebugInfo, context.Settings) {
CancellationToken = context.CancellationToken,

2
ICSharpCode.Decompiler/IL/Instructions/ILFunction.cs

@ -226,7 +226,7 @@ namespace ICSharpCode.Decompiler.IL @@ -226,7 +226,7 @@ namespace ICSharpCode.Decompiler.IL
Debug.Assert(DelegateType?.FullName == "System.Linq.Expressions.Expression" && DelegateType.TypeParameterCount == 1);
break;
case ILFunctionKind.LocalFunction:
Debug.Assert(Parent is ILFunction);
Debug.Assert(Parent is ILFunction && SlotInfo == ILFunction.LocalFunctionsSlot);
Debug.Assert(DeclarationScope != null);
Debug.Assert(DelegateType == null);
Debug.Assert(Method != null);

Loading…
Cancel
Save