diff --git a/src/Features/CSharp/Portable/Completion/SuggestionMode/CSharpSuggestionModeCompletionProvider.cs b/src/Features/CSharp/Portable/Completion/SuggestionMode/CSharpSuggestionModeCompletionProvider.cs index 7932afdbd4ab0a159936abd7c24244d67a8cd185..988088cf45b45ba79f4de3f53671341833f384cb 100644 --- a/src/Features/CSharp/Portable/Completion/SuggestionMode/CSharpSuggestionModeCompletionProvider.cs +++ b/src/Features/CSharp/Portable/Completion/SuggestionMode/CSharpSuggestionModeCompletionProvider.cs @@ -157,17 +157,17 @@ private bool IsLambdaExpression(SemanticModel semanticModel, int position, Synta // If we're an argument to a function with multiple overloads, // open the builder if any overload takes a delegate at our argument position - var inferredTypes = typeInferrer.GetTypeInferenceInfo(semanticModel, position, cancellationToken: cancellationToken); + var inferredTypeInfo = typeInferrer.GetTypeInferenceInfo(semanticModel, position, cancellationToken: cancellationToken); - return inferredTypes.Any(type => GetDelegateType(type, semanticModel.Compilation).IsDelegateType()); + return inferredTypeInfo.Any(type => GetDelegateType(type, semanticModel.Compilation).IsDelegateType()); } - private ITypeSymbol GetDelegateType(TypeInferenceInfo type, Compilation compilation) + private ITypeSymbol GetDelegateType(TypeInferenceInfo typeInferenceInfo, Compilation compilation) { - ITypeSymbol typeSymbol = type.InferredType; - if (type.IsParams && type.InferredType.IsArrayType()) + ITypeSymbol typeSymbol = typeInferenceInfo.InferredType; + if (typeInferenceInfo.IsParams && typeInferenceInfo.InferredType.IsArrayType()) { - typeSymbol = ((IArrayTypeSymbol)type.InferredType).ElementType; + typeSymbol = ((IArrayTypeSymbol)typeInferenceInfo.InferredType).ElementType; } return typeSymbol.GetDelegateType(compilation); diff --git a/src/Workspaces/CSharp/Portable/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs b/src/Workspaces/CSharp/Portable/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs index 9ffff8d845c8836c3ffa4af02aca8a4b2fa772ae..0d3ca50469a76ad3f2f02374844dbc0cc7d83bec 100644 --- a/src/Workspaces/CSharp/Portable/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs +++ b/src/Workspaces/CSharp/Portable/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs @@ -95,20 +95,20 @@ private IEnumerable GetTypesSimple(ExpressionSyntax expressio if (symbolInfo.CandidateReason != CandidateReason.WrongArity) { - TypeInferenceInfo type = new TypeInferenceInfo(typeInfo.Type); + var typeInferenceInfo = new TypeInferenceInfo(typeInfo.Type); // If it bound to a method, try to get the Action/Func form of that method. - if (type.InferredType == null && + if (typeInferenceInfo.InferredType == null && symbolInfo.GetAllSymbols().Count() == 1 && symbolInfo.GetAllSymbols().First().Kind == SymbolKind.Method) { var method = symbolInfo.GetAllSymbols().First(); - type = new TypeInferenceInfo(method.ConvertToType(this.Compilation)); + typeInferenceInfo = new TypeInferenceInfo(method.ConvertToType(this.Compilation)); } - if (IsUsableTypeFunc(type)) + if (IsUsableTypeFunc(typeInferenceInfo)) { - return SpecializedCollections.SingletonEnumerable(type); + return SpecializedCollections.SingletonEnumerable(typeInferenceInfo); } } } @@ -1205,7 +1205,8 @@ private IEnumerable InferTypeInIfStatement(IfStatementSyntax var addMethodParameterTypes = addMethodSymbols .Cast() .Where(a => a.Parameters.Length == initializerExpression.Expressions.Count) - .Select(a => new TypeInferenceInfo(a.Parameters.ElementAtOrDefault(parameterIndex)?.Type)); + .Select(a => new TypeInferenceInfo(a.Parameters.ElementAtOrDefault(parameterIndex)?.Type)) + .Where(t => t.InferredType != null); if (addMethodParameterTypes.Any()) { diff --git a/src/Workspaces/Core/Portable/LanguageServices/TypeInferenceService/AbstractTypeInferenceService.cs b/src/Workspaces/Core/Portable/LanguageServices/TypeInferenceService/AbstractTypeInferenceService.cs index 7e84cdb503057ee7b3272dcaa64197cd4ab8f422..e8d06ede7ea78c9c477f0ebd47de5bae346f39ab 100644 --- a/src/Workspaces/Core/Portable/LanguageServices/TypeInferenceService/AbstractTypeInferenceService.cs +++ b/src/Workspaces/Core/Portable/LanguageServices/TypeInferenceService/AbstractTypeInferenceService.cs @@ -101,7 +101,14 @@ public IEnumerable InferTypes(SemanticModel semanticModel, int posi public IEnumerable InferTypes(SemanticModel semanticModel, SyntaxNode expression, CancellationToken cancellationToken) { - return CreateTypeInferrer(semanticModel, cancellationToken).InferTypes(expression as TExpressionSyntax).Select(t => t.InferredType); + var result = new List(); + var typeInferenceInfo = CreateTypeInferrer(semanticModel, cancellationToken).InferTypes(expression as TExpressionSyntax); + foreach (var info in typeInferenceInfo) + { + result.Add(info.InferredType); + } + + return result; } public IEnumerable GetTypeInferenceInfo(SemanticModel semanticModel, int position, CancellationToken cancellationToken) diff --git a/src/Workspaces/Core/Portable/LanguageServices/TypeInferenceService/ITypeInferenceService.cs b/src/Workspaces/Core/Portable/LanguageServices/TypeInferenceService/ITypeInferenceService.cs index 1b4a8dacc24e0b974c7d9a5cd58873ce37960006..44563d155fbeb17f76df75117573446aff6c7822 100644 --- a/src/Workspaces/Core/Portable/LanguageServices/TypeInferenceService/ITypeInferenceService.cs +++ b/src/Workspaces/Core/Portable/LanguageServices/TypeInferenceService/ITypeInferenceService.cs @@ -32,14 +32,13 @@ internal interface ITypeInferenceService : ILanguageService internal struct TypeInferenceInfo { - private bool isParams; - - public TypeInferenceInfo(ITypeSymbol type) : this() + public TypeInferenceInfo(ITypeSymbol type) { InferredType = type; + IsParams = false; } - public TypeInferenceInfo(ITypeSymbol type, bool isParams) : this() + public TypeInferenceInfo(ITypeSymbol type, bool isParams) { InferredType = type; IsParams = isParams; diff --git a/src/Workspaces/VisualBasic/Portable/LanguageServices/VisualBasicTypeInferenceService.TypeInferrer.vb b/src/Workspaces/VisualBasic/Portable/LanguageServices/VisualBasicTypeInferenceService.TypeInferrer.vb index 10e98e3da4afafe1685b38b9b2248e05e400c58c..3c3699699cbfad3ab366bcb14ba87fb9bd20260b 100644 --- a/src/Workspaces/VisualBasic/Portable/LanguageServices/VisualBasicTypeInferenceService.TypeInferrer.vb +++ b/src/Workspaces/VisualBasic/Portable/LanguageServices/VisualBasicTypeInferenceService.TypeInferrer.vb @@ -1,4 +1,4 @@ -'Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. Imports System.Collections.Immutable Imports System.Threading