Skip to content

Extensions: follow-ups related to using directives #79440

@jcouv

Description

@jcouv

This issue is referenced in source.

        internal override void GetExtensionDeclarations(ArrayBuilder<NamedTypeSymbol> extensions, Binder originalBinder)
        {
            Debug.Assert(extensions.Count == 0);

            // Tracked by https://github.com/dotnet/roslyn/issues/79440 : using directives, test this flag (see TestUnusedExtensionMarksImportsAsUsed)
            bool callerIsSemanticModel = originalBinder.IsSemanticModelBinder;

            foreach (var nsOrType in this.GetUsings(basesBeingResolved: null))
            {
                if (nsOrType.NamespaceOrType is NamespaceSymbol ns)
                {
                    var count = extensions.Count;
                    ns.GetExtensionContainers(extensions);
                    // If we found any extension declarations, then consider this using as used.
                    // Tracked by https://github.com/dotnet/roslyn/issues/79440 : using directives, consider refining this logic
                    if (extensions.Count != count)
                    {
                        MarkImportDirective(nsOrType.UsingDirectiveReference, callerIsSemanticModel);
                    }
                }
...

Relates to test plan #76130

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions