# Weird behaviour with protocol conforming to itself

**URL:** <https://forums.swift.org/t/weird-behaviour-with-protocol-conforming-to-itself/60924>\
**Category:** Using Swift\
**Created:** [October 19, 2022, 1:19am UTC](https://forums.swift.org/t/weird-behaviour-with-protocol-conforming-to-itself/60924 "2022-10-19T01:19:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mead](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mead/32/21663_2.png) [@Mead](https://forums.swift.org/u/Mead)\
**Post date:** [October 19, 2022, 1:19am UTC](https://forums.swift.org/t/weird-behaviour-with-protocol-conforming-to-itself/60924/1 "2022-10-19T01:19:22Z")

</div>

When I run the following extension code on macOS Monterey 12.6 with Xcode 14.0.1 in a playground, it compiles and runs fine.

However when I run it on my laptop on macOS Big Sur 11.7 with Xcode 13.2.1 it gives me a compilation error saying "Protocol Encodable as a type cannot conform to the protocol itself".

My project iOS deployment target is 15.2

Has something changed in recent version so that now this works?

```swift
import SwiftUI

extension URLRequest {
    init?(baseUrl: String, controller: String, action: String = String(), httpBody: Encodable? = nil) {
        let url = "\(baseUrl)/\(controller)/\(action)"
        guard let url = URL(string: url) else {
            return nil
        }

        self.init(url: url)
        self.setValue(URLRequest.Constants.applicationJson, forHTTPHeaderField: URLRequest.Constants.headerContentType)
        
        if let httpBody = httpBody {
            // here is where it messes up on my laptop
            guard let httpBody = try? JSONEncoder().encode(httpBody) else {
                return nil
            }
            
            self.httpBody = httpBody
        }
    }
}

struct AuthenticationInfo: Encodable {
    var username: String
    var password: String
}

let urlRequest = URLRequest(
    baseUrl: "http://1.2.3.4:12345",
    controller: "mycontroller",
    action: "myaction",
    httpBody: AuthenticationInfo(username: "myusername", password: "mypassword"))

```

---

<div class="post-metadata">

**Author:** ![xwu](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xwu](https://forums.swift.org/u/xwu)\
**Post date:** [October 19, 2022, 2:09am UTC](https://forums.swift.org/t/weird-behaviour-with-protocol-conforming-to-itself/60924/2 "2022-10-19T02:09:05Z")

</div>

> [@Mead](#):
>
> Has something changed in recent version so that now this works?

Yes, your code is making use of [implicitly opened existentials](https://github.com/apple/swift-evolution/blob/main/proposals/0352-implicit-open-existentials.md).

---

<div class="post-metadata">

**Author:** ![ksluder](https://avatars.discourse-cdn.com/v4/letter/k/eada6e/32.png) [@ksluder](https://forums.swift.org/u/ksluder)\
**Post date:** [October 19, 2022, 10:20pm UTC](https://forums.swift.org/t/weird-behaviour-with-protocol-conforming-to-itself/60924/3 "2022-10-19T22:20:15Z")

</div>

I think the fact that this “just worked” is a good sign that implicitly opened existentials were well-designed.

---

<div class="post-metadata">

**Author:** ![Mead](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/mead/32/21663_2.png) [@Mead](https://forums.swift.org/u/Mead)\
**Post date:** [October 20, 2022, 12:47am UTC](https://forums.swift.org/t/weird-behaviour-with-protocol-conforming-to-itself/60924/4 "2022-10-20T00:47:42Z")

</div>

Thank you.

I guess I shouldn't have taken dependency injection for granted.
