Browse Source

Type analysis for "yield return"

pull/100/head
Daniel Grunwald 15 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 @@ -458,11 +458,22 @@ namespace ICSharpCode.Decompiler.ILAst
case ILCode.Rethrow:
case ILCode.LoopOrSwitchBreak:
case ILCode.LoopContinue:
case ILCode.YieldBreak:
return null;
case ILCode.Ret:
if (forceInferChildren && expr.Arguments.Count == 1)
InferTypeForExpression(expr.Arguments[0], context.CurrentMethod.ReturnType);
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
case ILCode.Pop:
return null;

7
ICSharpCode.Decompiler/Tests/YieldReturn.cs

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

Loading…
Cancel
Save