Skip to content

[SR-4758] SE-0142: derived protocol that restricts associatedtype should be allowed as a variable type #47335

@nsalmoria

Description

@nsalmoria
Previous ID SR-4758
Radar rdar://problem/58438127
Original Reporter @nsalmoria
Type Improvement
Environment

Swift Development Snapshot 2017-04-24 (a)
Xcode 8.3.2
macOS Sierra 10.12.4

Additional Detail from JIRA
Votes 3
Component/s Compiler
Labels Improvement
Assignee @slavapestov
Priority Medium

md5: 992bea1bd30120d41ee308b8b85d8e1e

is duplicated by:

relates to:

Issue Description:

With the implementation of SE-0142, it is now possible to force the associated types of a derived protocol to be of a specific type.

Arguably, when all the associated types are restricted, it should be possible to use the derived protocol as the type of a variable. However, the compiler still rejects the code.

Example:

protocol A {
    associatedtype B
}

protocol C: A where B == Int {

}

struct D {
    var c: C  // error: Protocol 'C' can only be used as a generic constraint because it has Self or associated type requirements
}

In the example above, protocol C has no degrees of freedom so it shouldn't need to be restricted to generic code.

Metadata

Metadata

Assignees

Labels

compilerThe Swift compiler itselfexistentialsFeature: values of types like `any Collection`, `Any` and `AnyObject`; type-erased valuesfeatureA feature request or implementationimprovementswift evolution implementedFlag → feature: A feature that was approved through the Swift evolution process and implementedtype 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