# Trying to understand the difference in the choice of method called in a generic context

**URL:** <https://forums.swift.org/t/trying-to-understand-the-difference-in-the-choice-of-method-called-in-a-generic-context/79123>\
**Category:** Using Swift\
**Tags:** generics, protocols, some-keyword\
**Created:** [April 6, 2025, 10:37am UTC](https://forums.swift.org/t/trying-to-understand-the-difference-in-the-choice-of-method-called-in-a-generic-context/79123 "2025-04-06T10:37:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pelekon](https://avatars.discourse-cdn.com/v4/letter/p/db5fbb/32.png) [@pelekon](https://forums.swift.org/u/pelekon)\
**Post date:** [April 6, 2025, 10:37am UTC](https://forums.swift.org/t/trying-to-understand-the-difference-in-the-choice-of-method-called-in-a-generic-context/79123/1 "2025-04-06T10:37:49Z")

</div>

Hello, today I created a small piece of code to try out an idea, but the result was not what I expected. Given this snippet: [Generics.swift · GitHub](https://gist.github.com/pelekon/aed2a90b5c26e97d36a71a509786b865) . I expected to get 2x "Hi, I am generic func" and 3x "Hi, I am special func" outputted in the console. Instead I got 4x "generic" and one "special" and this is the part that confuses me. From what I understand, `runNormalGeneric` and `makeOpaque` cause the compiler to know the underlaying type, which is TestB, and I expected it to call the `perform` function declared for it. I would be grateful if someone could explain to me or point me to a link to an explanation of why the compiler chooses the "generic" variant of the method.

---

<div class="post-metadata">

**Author:** ![Slava\_Pestov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/slava_pestov/32/30204_2.png) [@Slava\_Pestov](https://forums.swift.org/u/Slava_Pestov)\
**Post date:** [April 6, 2025, 12:18pm UTC](https://forums.swift.org/t/trying-to-understand-the-difference-in-the-choice-of-method-called-in-a-generic-context/79123/2 "2025-04-06T12:18:57Z")

</div>

> [@pelekon](#):
>
> From what I understand, `runNormalGeneric` and `makeOpaque` cause the compiler to know the underlaying type, which is TestB,

The purpose of an opaque result type is to hide the underlying type, so the compiler intentionally doesn’t “know” it outside the function. The compiler always picks the most specific overload to call based on static type information at the call site, which is the generic overload in this case.

---

<div class="post-metadata">

**Author:** ![pelekon](https://avatars.discourse-cdn.com/v4/letter/p/db5fbb/32.png) [@pelekon](https://forums.swift.org/u/pelekon)\
**Post date:** [April 6, 2025, 12:35pm UTC](https://forums.swift.org/t/trying-to-understand-the-difference-in-the-choice-of-method-called-in-a-generic-context/79123/3 "2025-04-06T12:35:06Z")

</div>

So I misunderstood how opaque result type behaves, thank you very much for explanation.
