From b1fde3b8c1ea93fc7ac13c612eafeb722956680a Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 9 Mar 2020 11:56:32 -0700 Subject: [PATCH] Update docs --- .../TypeStyle/CSharpUseImplicitTypeHelper.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Utilities/TypeStyle/CSharpUseImplicitTypeHelper.cs b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Utilities/TypeStyle/CSharpUseImplicitTypeHelper.cs index 8ce27b4ca84..dc891e47082 100644 --- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Utilities/TypeStyle/CSharpUseImplicitTypeHelper.cs +++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Utilities/TypeStyle/CSharpUseImplicitTypeHelper.cs @@ -217,16 +217,14 @@ protected override bool IsStylePreferred(in State state) private bool IsMatchingArgumentToSimpleMethod(DeclarationExpressionSyntax declarationExpression, SemanticModel semanticModel, CancellationToken cancellationToken) { + // If there was only one member in the group, and it was non-generic itself, then this + // change is commonly safe to make without having to actually change to `var` and + // speculatively determine if the change is ok or not. if (!(declarationExpression.Parent is ArgumentSyntax argument) || !(argument.Parent is ArgumentListSyntax argumentList) || !(argumentList.Parent is InvocationExpressionSyntax invocationExpression)) return false; - // If there was only one member in the group, and it was non-generic itself, - // then this change is safe to make without doing any complex analysis. - // Multiple methods mean that switching to 'var' might remove information - // that affects overload resolution. And if the method is generic, then - // switching to 'var' may mean that inference might not work properly. var memberGroup = semanticModel.GetMemberGroup(invocationExpression.Expression, cancellationToken); if (memberGroup.Length != 1) return false; @@ -238,6 +236,11 @@ private bool IsMatchingArgumentToSimpleMethod(DeclarationExpressionSyntax declar if (!method.GetTypeParameters().IsEmpty) return false; + // Looks pretty good so far. However, this change is not allowed if the user is + // specifying something like `out (int x, int y) t` and the method signature has + // different names for those tuple elements. Check and make sure the types are the + // same before proceeding. + var invocationOp = semanticModel.GetOperation(invocationExpression) as IInvocationOperation; if (invocationOp == null) return false; -- GitLab