dotnet/roslyn

Implementing interface (or abstract class) whose members reference a type included via a global import adds empty line to the beginning of file

Open

#79,363 创建于 2025年7月14日

在 GitHub 查看
 (5 评论) (0 反应) (0 负责人)C# (4,257 fork)batch import
Area-IDEhelp wanted

仓库指标

Star
 (20,414 star)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 256 个 PR)

描述

Full issue information + repro project:
https://github.com/just-ero/roslyn-issues-repros/tree/main/5.0.0/003_ImplementInterface_ReturnTypeInGlobalUsings

Version

[!NOTE]
Roslyn: 5.0.0-1.25319.11
.NET SDK: 10.0.100-preview.5.25277.114

Visual Studio Code: 1.102.0
C# Extension: 2.84.19
C# Dev Kit Extension: 1.30.44

Steps to Reproduce

  1. Add the following code in separate files:
    namespace N;
    
    class C;
    
    interface II
    {
        C M();
    }
    
    class Repro : II;
    
    Note: C must be in a different namespace than II, and Repro and Repro must not know of C before implemetation.
  2. Add N to the global usings anywhere.
  3. Apply the Implement interface quick fix to Repro.

Expected Behavior

No new line is added to the beginning of the file.

Actual Behavior

It is.

Speculation: this is possibly due to Roslyn making an attempt to add missing namespaces, but stopping after finding the global import.

贡献者指南