未验证 提交 57f248fd 编写于 作者: Y Youssef Victor 提交者: GitHub

Update InferTypeInForEachStatement to respect await foreach

上级 1ec8b6bd
...@@ -1230,18 +1230,21 @@ private IEnumerable<TypeInferenceInfo> InferTypeInForEachStatement(ForEachStatem ...@@ -1230,18 +1230,21 @@ private IEnumerable<TypeInferenceInfo> InferTypeInForEachStatement(ForEachStatem
return SpecializedCollections.EmptyEnumerable<TypeInferenceInfo>(); return SpecializedCollections.EmptyEnumerable<TypeInferenceInfo>();
} }
var enumerableType = forEachStatementSyntax.AwaitKeyword == default
? this.Compilation.GetSpecialType(SpecialType.System_Collections_Generic_IEnumerable_T)
: this.Compilation.GetTypeByMetadataName(typeof(IAsyncEnumerable<>).FullName);
// foreach (int v = Goo()) // foreach (int v = Goo())
var variableTypes = GetTypes(forEachStatementSyntax.Type); var variableTypes = GetTypes(forEachStatementSyntax.Type);
if (!variableTypes.Any()) if (!variableTypes.Any())
{ {
return CreateResult( return CreateResult(
this.Compilation.GetSpecialType(SpecialType.System_Collections_Generic_IEnumerable_T) enumerableType
.Construct(Compilation.GetSpecialType(SpecialType.System_Object))); .Construct(Compilation.GetSpecialType(SpecialType.System_Object)));
} }
var type = this.Compilation.GetSpecialType(SpecialType.System_Collections_Generic_IEnumerable_T); return variableTypes.Select(v => new TypeInferenceInfo(enumerableType.Construct(v.InferredType)));
return variableTypes.Select(v => new TypeInferenceInfo(type.Construct(v.InferredType)));
} }
private IEnumerable<TypeInferenceInfo> InferTypeInForStatement(ForStatementSyntax forStatement, ExpressionSyntax expressionOpt = null, SyntaxToken? previousToken = null) private IEnumerable<TypeInferenceInfo> InferTypeInForStatement(ForStatementSyntax forStatement, ExpressionSyntax expressionOpt = null, SyntaxToken? previousToken = null)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册