swiftlang/swift

Diagnostic for use of plain protocol name in type position should suggest `some` or `any`

Open

#68,284 opened on Sep 1, 2023

View on GitHub
 (19 comments) (0 reactions) (1 assignee)Swift (10,719 forks)batch import
bugcompilerdiagnostics qualityexistentialsfix-itsgenericsgood first issueopaque typesswift 5.9type checkertypes

Repository metrics

Stars
 (69,989 stars)
PR merge metrics
 (Avg merge 8d 17h) (510 merged PRs in 30d)

Description

The following code is invalid:

protocol P {
  associatedtype A
}

func generic(value: P) {}

The compiler currently produces the error message Use of protocol 'P' as a type must be written 'any P' with a fix-it to insert the any keyword.

However, a different (and often better!) fix here is to use the some keyword. The error message should be re-worded to prompt the programmer to consider any or some, and there should be two notes, each with a fix-it to insert any or some, respectively.

Contributor guide