Browse Source

Type analysis for "yield return"

pull/100/head
Daniel Grunwald 16 years ago
parent
commit
ca720c105d
  1. 11
      ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs
  2. 7
      ICSharpCode.Decompiler/Tests/YieldReturn.cs

11
ICSharpCode.Decompiler/ILAst/TypeAnalysis.cs

@ -458,11 +458,22 @@ namespace ICSharpCode.Decompiler.ILAst
case ILCode.Rethrow: case ILCode.Rethrow:
case ILCode.LoopOrSwitchBreak: case ILCode.LoopOrSwitchBreak:
case ILCode.LoopContinue: case ILCode.LoopContinue:
case ILCode.YieldBreak:
return null; return null;
case ILCode.Ret: case ILCode.Ret:
if (forceInferChildren && expr.Arguments.Count == 1) if (forceInferChildren && expr.Arguments.Count == 1)
InferTypeForExpression(expr.Arguments[0], context.CurrentMethod.ReturnType); InferTypeForExpression(expr.Arguments[0], context.CurrentMethod.ReturnType);
return null; return null;
case ILCode.YieldReturn:
if (forceInferChildren) {
GenericInstanceType genericType = context.CurrentMethod.ReturnType as GenericInstanceType;
if (genericType != null) { // IEnumerable<T> or IEnumerator<T>
InferTypeForExpression(expr.Arguments[0], genericType.GenericArguments[0]);
} else { // non-generic IEnumerable or IEnumerator
InferTypeForExpression(expr.Arguments[0], typeSystem.Object);
}
}
return null;
#endregion #endregion
case ILCode.Pop: case ILCode.Pop:
return null; return null;

7
ICSharpCode.Decompiler/Tests/YieldReturn.cs

@ -108,4 +108,11 @@ public static class YieldReturn
yield return i; yield return i;
} }
} }
public static IEnumerable<char> YieldChars()
{
yield return 'a';
yield return 'b';
yield return 'c';
}
} }

Loading…
Cancel
Save