Repository: dotnet/roslyn
File: src/Compilers/CSharp/Portable/Binder/Binder_Lookup.cs (C#)

Code before:
            }

            singleLookupResults.Free();
        }

        internal void EnumerateAllExtensionMembersInSingleBinder(ArrayBuilder<SingleLookupResult> result,
            string? name, int arity, LookupOptions options, Binder originalBinder, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo, ref CompoundUseSiteInfo<AssemblySymbol> classicExtensionUseSiteInfo)
        {
            PooledHashSet<MethodSymbol>? implementationsToShadow = null;

            // 1. Collect new extension members
            var extensionCandidates = ArrayBuilder<Symbol>.GetInstance();
            this.GetCandidateExtensionMembersInSingleBinder(extensionCandidates, name, alternativeName: null, arity, options, originalBinder);

            foreach (var candidate in extensionCandidates)
            {
                SingleLookupResult resultOfThisMember = originalBinder.CheckViability(candidate, arity, options, null, diagnose: true, useSiteInfo: ref useSiteInfo);
                if (resultOfThisMember.Kind != LookupResultKind.Empty)
                {
                    result.Add(resultOfThisMember);
                }

                if (candidate is MethodSymbol { IsStatic: false } shadows &&
                    shadows.OriginalDefinition.TryGetCorrespondingExtensionImplementationMethod() is { } toShadow)
                {
                    implementationsToShadow ??= PooledHashSet<MethodSymbol>.GetInstance();
                    implementationsToShadow.Add(toShadow);
                }
            }

            extensionCandidates.Free();

            // 2. Collect classic extension methods
            var extensionMethods = ArrayBuilder<MethodSymbol>.GetInstance();
            this.GetCandidateExtensionMethodsInSingleBinder(extensionMethods, name, arity, options, originalBinder: originalBinder);

            foreach (var method in extensionMethods)
            {
                // Prefer instance extension declarations vs. their implementations
                if (implementationsToShadow is null || !implementationsToShadow.Remove(method.OriginalDefinition))
                {
                    SingleLookupResult resultOfThisMember = originalBinder.CheckViability(method, arity, options, null, diagnose: true, useSiteInfo: ref classicExtensionUseSiteInfo);
                    if (resultOfThisMember.Kind != LookupResultKind.Empty)
                    {
                        result.Add(resultOfThisMember);
                    }
                }
            }

            extensionMethods.Free();
            implementationsToShadow?.Free();

Review comment (suggestion):
>if (candidate is MethodSymbol { IsStatic: false } shadows && [](http://example.com/codeflow?start=16&length=60)

It looks like this `if` belongs inside the `if` added above #Closed

Code after:
            }

            singleLookupResults.Free();
        }

        internal void EnumerateAllExtensionMembersInSingleBinder(ArrayBuilder<SingleLookupResult> result,
            string? name, int arity, LookupOptions options, Binder originalBinder, ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo, ref CompoundUseSiteInfo<AssemblySymbol> classicExtensionUseSiteInfo)
        {
            PooledHashSet<MethodSymbol>? implementationsToShadow = null;

            // 1. Collect new extension members
            var extensionCandidates = ArrayBuilder<Symbol>.GetInstance();
            this.GetCandidateExtensionMembersInSingleBinder(extensionCandidates, name, alternativeName: null, arity, options, originalBinder);

            foreach (var candidate in extensionCandidates)
            {
                SingleLookupResult resultOfThisMember = originalBinder.CheckViability(candidate, arity, options, null, diagnose: true, useSiteInfo: ref useSiteInfo);
                if (resultOfThisMember.Kind == LookupResultKind.Empty)
                {
                    continue;
                }

                Debug.Assert(resultOfThisMember.Symbol is not null);
                result.Add(resultOfThisMember);

                if (candidate is MethodSymbol { IsStatic: false } shadows &&
                    shadows.OriginalDefinition.TryGetCorrespondingExtensionImplementationMethod() is { } toShadow)
                {
                    implementationsToShadow ??= PooledHashSet<MethodSymbol>.GetInstance();
                    implementationsToShadow.Add(toShadow);
                }
            }

            extensionCandidates.Free();

            // 2. Collect classic extension methods
            var extensionMethods = ArrayBuilder<MethodSymbol>.GetInstance();
            this.GetCandidateExtensionMethodsInSingleBinder(extensionMethods, name, arity, options, originalBinder: originalBinder);

            foreach (var method in extensionMethods)
            {
                // Prefer instance extension declarations vs. their implementations
                if (implementationsToShadow is null || !implementationsToShadow.Remove(method.OriginalDefinition))
                {
                    SingleLookupResult resultOfThisMember = originalBinder.CheckViability(method, arity, options, null, diagnose: true, useSiteInfo: ref classicExtensionUseSiteInfo);
                    if (resultOfThisMember.Kind != LookupResultKind.Empty)
                    {
                        result.Add(resultOfThisMember);
                    }
                }
            }