Skip to content

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

Open
@hborla

Description

@hborla

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.

Metadata

Metadata

Assignees

Labels

bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfdiagnostics QoIBug: Diagnostics Quality of ImplementationexistentialsFeature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased valuesfix-itsFeature: diagnostic fix-itsgenericsFeature: generic declarations and typesgood first issueGood for newcomersopaque typesFeature → types: opaque typesswift 5.9type checkerArea → compiler: Semantic analysistypesFeature: types

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions