swiftlang / swift-package-manager

The Package Manager for the Swift Programming Language
Apache License 2.0
9.71k stars 1.33k forks source link

[SR-13640] Duplicate diagnostics when using 'swift build' #4494

Open b2e1c890-44b4-46cf-bfdd-23ab48233d92 opened 3 years ago

b2e1c890-44b4-46cf-bfdd-23ab48233d92 commented 3 years ago
Previous ID SR-13640
Radar rdar://problem/69845492
Original Reporter @ackyshake
Type Bug
Environment OS: macOS 11.0 (Build 20A5384c) Swift: Apple Swift version 5.3.1 (swiftlang-1200.0.39 clang-1200.0.32.6) Target: x86_64-apple-darwin20.1.0 Xcode: Version 12.2 beta 2 (12B5025f)
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler, Package Manager | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 2414cf1601592c74d817051b25d951c4

Issue Description:

Hi there,

I've noticed duplicate error diagnostics from the compiler when I try to use swift build to compile my projects, for some time now. Notably, the spurious duplication of diagnostics are only visible in the Terminal. In Xcode, diagnostic messages, if any, are unique.

Note that my current environment is a beta OS with Xcode 12.2. However, this has been an issue ever since swiftpm was released, and is reproducible in macOS Catalina with Xcode 11 and Swift 5.

As an example, I cloned swift-argument-parser at tag 0.3.1, and intentionally introduced a typo in two lines like so:

[ajh@Bessie:~/Developer/vendor/swift-argument-parser]% git diff
diff --git a/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift b/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift
index 3ec9e54..1d2aa84 100644
--- a/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift
+++ b/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift
@@ -11,7 +11,7 @@ struct BashCompletionsGenerator {
   /// Generates a Bash completion script for the given command.
-  static func generateCompletionScript(_ type: ParsableCommand.Type) -> String {
+  static func generateCompletionScript(_ type: ParsableCommand.Type) -> Stringt {
     // TODO: Add a check to see if the command is installed where we expect?
     let initialFunctionName = [type].completionFunctionName()
     return """
@@ -24,7 +24,7 @@ struct BashCompletionsGenerator {
   }   /// Generates a Bash completion function for the last command in the given list.
-  fileprivate static func generateCompletionFunction(_ commands: [ParsableCommand.Type]) -> String {
+  fileprivate static func generateCompletionFunction<T>(_ commands: [ParsableCommand.Type]) -> String {
     let type = commands.last!
     let functionName = commands.completionFunctionName()

Next, I invoked swift build.

I would expect two diagnostic messages from the compiler, one for each of the errors I introduced. However, I get three diagnostic messages, one of them, a duplicate:

[ajh@Bessie:~/Developer/vendor/swift-argument-parser]% swift build
/Users/ajh/Developer/vendor/swift-argument-parser/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift:14:73: error: cannot find type 'Stringt' in scope
  static func generateCompletionScript(_ type: ParsableCommand.Type) -> Stringt {
                                                                        ^~~~~~~
/Users/ajh/Developer/vendor/swift-argument-parser/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift:14:73: error: cannot find type 'Stringt' in scope
  static func generateCompletionScript(_ type: ParsableCommand.Type) -> Stringt {
                                                                        ^~~~~~~
/Users/ajh/Developer/vendor/swift-argument-parser/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift:27:54: error: generic parameter 'T' is not used in function signature
  fileprivate static func generateCompletionFunction<T>(_ commands: [ParsableCommand.Type]) -> String {
                                                     ^
[2/6] Compiling ArgumentParser BashCompletionsGenerator.swift

Moreover, if I use swift build --jobs 1, I get even more duplicates:

[1 ajh@Bessie:~/Developer/vendor/swift-argument-parser]% swift build --jobs 1
/Users/ajh/Developer/vendor/swift-argument-parser/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift:14:73: error: cannot find type 'Stringt' in scope
  static func generateCompletionScript(_ type: ParsableCommand.Type) -> Stringt {
                                                                        ^~~~~~~
/Users/ajh/Developer/vendor/swift-argument-parser/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift:27:54: error: generic parameter 'T' is not used in function signature
  fileprivate static func generateCompletionFunction<T>(_ commands: [ParsableCommand.Type]) -> String {
                                                     ^
/Users/ajh/Developer/vendor/swift-argument-parser/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift:14:73: error: cannot find type 'Stringt' in scope
  static func generateCompletionScript(_ type: ParsableCommand.Type) -> Stringt {
                                                                        ^~~~~~~
/Users/ajh/Developer/vendor/swift-argument-parser/Sources/ArgumentParser/Completions/BashCompletionsGenerator.swift:27:54: error: generic parameter 'T' is not used in function signature
  fileprivate static func generateCompletionFunction<T>(_ commands: [ParsableCommand.Type]) -> String {
                                                     ^
[2/6] Compiling ArgumentParser CompletionsGenerator.swift

I have several targets in my one of my own projects (however I cannot share this project), and I get over 10 duplicate diagnostic messages for one line of error.

typesanitizer commented 3 years ago

@swift-ci create