From ad092cbe5573e5f1e5ce6f5659c94a828c76528f Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Thu, 8 Oct 2020 13:05:01 +0000 Subject: [PATCH] Fix FAR counting for target-typed new --- .../FindReferencesTests.ConstructorSymbols.vb | 28 +++++++++++++++++++ .../Finders/AbstractReferenceFinder.cs | 5 ++++ 2 files changed, 33 insertions(+) diff --git a/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.ConstructorSymbols.vb b/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.ConstructorSymbols.vb index 6dec719af6f6e..f34108c51c3c3 100644 --- a/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.ConstructorSymbols.vb +++ b/src/EditorFeatures/Test2/FindReferences/FindReferencesTests.ConstructorSymbols.vb @@ -895,6 +895,34 @@ class C Await TestAPIAndFeature(input, kind, host) End Function + + + Public Async Function DoNotCountInstantiationTwiceWhenTargetTypedNewExists(kind As TestKind, host As TestHost) As Task + Dim input = + + + +class Bar +{ + public {|Definition:$$Bar|}() { } +} + + +public class Foo +{ + private readonly Bar bar1 = [|new|](); + private readonly Bar bar2; + public Foo(Bar bar) + { + this.bar2 = new [|Bar|](); + } +} + + + + Await TestAPIAndFeature(input, kind, host) + End Function + Public Async Function TestConstructorReferenceInGlobalSuppression(kind As TestKind, host As TestHost) As Task diff --git a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder.cs b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder.cs index da3b22e55c747..4c4d69af9c4f0 100644 --- a/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder.cs +++ b/src/Workspaces/Core/Portable/FindSymbols/FindReferences/Finders/AbstractReferenceFinder.cs @@ -637,6 +637,11 @@ static bool IsRelevantDocument(SyntaxTreeIndex syntaxTreeInfo) void CollectMatchingReferences(ISymbol originalUnreducedSymbolDefinition, SyntaxNode node, ISyntaxFactsService syntaxFacts, ISemanticFactsService semanticFacts, ArrayBuilder locations) { + if (syntaxFacts.IsImplicitObjectCreation(node)) + { + return; + } + var constructor = semanticModel.GetSymbolInfo(node, cancellationToken).Symbol; if (Matches(constructor, originalUnreducedSymbolDefinition))