Skip to content

[SR-8719] Associated type 1 == Associated type 2 requires explicitly stating both types #51230

@swift-ci

Description

@swift-ci
Previous ID SR-8719
Radar None
Original Reporter Nasamura (JIRA User)
Type New Feature
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels New Feature, AssociatedTypeInference
Assignee @DougGregor
Priority Medium

md5: 583798a6a88eb7fa7fc4d602ce5716b8

relates to:

Issue Description:

Xcode: Version 10.0 beta 6 (10L232m)

public protocol Prot1 {
    associatedtype AType: StringProtocol
}

public protocol Prot2 {
    associatedtype BType: StringProtocol
}

public protocol Prot3: Prot1, Prot2 where AType == BType {
}

struct Struct1: Prot3 {
    typealias AType = String
}

// Type 'Struct1' does not conform to protocol 'Prot2'

This is a simplified example of where I'm combining two protocols and AType will always equal BType but the compiler is not able to infer one type from the other and has to be explicitly stated. This leads to unnecessary code duplication.

Metadata

Metadata

Assignees

Labels

associated type inferencebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfconformancesFeature → protocol: protocol conformancesgeneric constraintsFeature → generics: generic constraintsgenericsFeature: generic declarations and typesswift 5.10type checkerArea → compiler: Semantic analysisunexpected errorBug: Unexpected error

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions