Browse Source

Fix decompiling iterator method that consists only of "yield break;".

pull/734/merge
Daniel Grunwald 8 years ago
parent
commit
904b4e768b
  1. 6
      ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs
  2. 5
      ICSharpCode.Decompiler/Tests/TestCases/Correctness/YieldReturn.cs

6
ICSharpCode.Decompiler/CSharp/CSharpDecompiler.cs

@ -630,9 +630,13 @@ namespace ICSharpCode.Decompiler.CSharp
AddDefinesForConditionalAttributes(function); AddDefinesForConditionalAttributes(function);
var statementBuilder = new StatementBuilder(specializingTypeSystem, decompilationContext, method, function); var statementBuilder = new StatementBuilder(specializingTypeSystem, decompilationContext, method, function);
entityDecl.AddChild(statementBuilder.ConvertAsBlock(function.Body), Roles.Body); var body = statementBuilder.ConvertAsBlock(function.Body);
entityDecl.AddChild(body, Roles.Body);
if (function.IsIterator) { if (function.IsIterator) {
if (!body.Descendants.Any(d => d is YieldReturnStatement || d is YieldBreakStatement)) {
body.Add(new YieldBreakStatement());
}
RemoveAttribute(entityDecl, new TopLevelTypeName("System.Runtime.CompilerServices", "IteratorStateMachineAttribute")); RemoveAttribute(entityDecl, new TopLevelTypeName("System.Runtime.CompilerServices", "IteratorStateMachineAttribute"));
} }
} }

5
ICSharpCode.Decompiler/Tests/TestCases/Correctness/YieldReturn.cs

@ -309,6 +309,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
} }
} }
public static IEnumerable<int> YieldBreakOnly()
{
yield break;
}
public static IEnumerable<int> UnconditionalThrowInTryFinally() public static IEnumerable<int> UnconditionalThrowInTryFinally()
{ {
// Here, MoveNext() doesn't call the finally methods at all // Here, MoveNext() doesn't call the finally methods at all

Loading…
Cancel
Save