Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-726] Can't access associated types through class-constrained generic parameters #43341

Closed
swift-ci opened this issue Feb 13, 2016 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

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 }
                            ^
@swift-ci
Copy link
Collaborator Author

Comment by Janek Spaderna (JIRA)

#1302

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

1 participant