# Associated type inference doesn't work in a situation that I assumed it would

**URL:** <https://forums.swift.org/t/associated-type-inference-doesnt-work-in-a-situation-that-i-assumed-it-would/61056>\
**Category:** Using Swift\
**Tags:** inheritance, protocols, associatedtype, protocol, type-inference\
**Created:** [October 27, 2022, 10:27am UTC](https://forums.swift.org/t/associated-type-inference-doesnt-work-in-a-situation-that-i-assumed-it-would/61056 "2022-10-27T10:27:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeremyabannister](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jeremyabannister/32/10143_2.png) [@jeremyabannister](https://forums.swift.org/u/jeremyabannister)\
**Post date:** [October 27, 2022, 10:27am UTC](https://forums.swift.org/t/associated-type-inference-doesnt-work-in-a-situation-that-i-assumed-it-would/61056/1 "2022-10-27T10:27:43Z")

</div>

Anyone have any knowledge about the code below and the possibility of it working in some future?

```swift
protocol A {
    associatedtype T
}
protocol B: A {
    var t: T { get }
}
struct X: B {
// typealias T = Int // This line makes it compile, but I wish this type could be inferred.
    var t: Int {
        0
    }
}

```

---

<div class="post-metadata">

**Author:** ![mbrandonw](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mbrandonw/32/349_2.png) [@mbrandonw](https://forums.swift.org/u/mbrandonw)\
**Post date:** [October 27, 2022, 1:51pm UTC](https://forums.swift.org/t/associated-type-inference-doesnt-work-in-a-situation-that-i-assumed-it-would/61056/2 "2022-10-27T13:51:15Z")

</div>

This is a known [issue](https://github.com/apple/swift/issues/61077), but it is possible to work around by adding an associated type to `B`:

```swift
protocol A {
  associatedtype T
}
protocol B: A {
  associatedtype T
  var t: T { get }
}
struct X: B {
  var t: Int { 0 }
}

```

However, if in the future `A` picks up additional requirements, you will have to repeat those requirements in `B`:

```swift
protocol A {
  associatedtype T
  var a: T { get }
}
protocol B: A {
  associatedtype T
  var a: T { get }
  var t: T { get }
}
struct X: B {
  var a: Int { 0 }
  var t: Int { 0 }
}

```

Otherwise Swift will erroneously allow the instance variables `a` and `t` to be of different types.
