-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Closed
Copy link
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselftype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis
Description
| Previous ID | SR-726 |
| Radar | None |
| Original Reporter | jaspa (JIRA User) |
| Type | Bug |
| Status | Closed |
| Resolution | Done |
Additional Detail from JIRA
| Votes | 0 |
| Component/s | Compiler |
| Labels | Bug, TypeChecker |
| Assignee | jaspa (JIRA) |
| Priority | Medium |
md5: 28453193dbd999bd7c7c32caa1cb0e83
Issue Description:
Given a protocol P with an associated type A, a class C conforming to P and a function f with an generic parameter T constrained to C, it is not possible to access A through through T (T.A) inside the body of f.
In the function signature though, T.A works as expected (for example as a return type).
Example:
protocol P { associatedtype A }
class C : P { typealias A = Int }
func foo<T : C>(x: T) {
let a: T.A? = nil
}Compiler output:
<stdin>:4:12: error: ambiguous type name 'A' in 'T'
let a: T.A? = nil
~ ^
<stdin>:2:25: note: found candidate with type 'A' (aka 'Int')
class C : P { typealias A = Int }
^
<stdin>:1:29: note: found candidate with type '<<error type>>'
protocol P { associatedtype A }
^Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfThe Swift compiler itselftype checkerArea → compiler: Semantic analysisArea → compiler: Semantic analysis