# BindingContext.get(TYPE, typeReference) returns null

**URL:** <https://discuss.kotlinlang.org/t/bindingcontext-get-type-typereference-returns-null/21566>\
**Category:** Support\
**Created:** [April 18, 2021, 5:34am UTC](https://discuss.kotlinlang.org/t/bindingcontext-get-type-typereference-returns-null/21566 "2021-04-18T05:34:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AhmedMourad](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ahmedmourad/32/7847_2.png) [@AhmedMourad](https://discuss.kotlinlang.org/u/AhmedMourad)\
**Post date:** [April 18, 2021, 5:34am UTC](https://discuss.kotlinlang.org/t/bindingcontext-get-type-typereference-returns-null/21566/1 "2021-04-18T05:34:53Z")

</div>

Hi, so I have this utility function:

```nohighlight
fun KtClassOrObject.findSuperType(
    bindingContext: BindingContext,
    fqName: FqName
): KtSuperTypeListEntry? {
    return this.superTypeListEntries.firstOrNull { entry ->
        bindingContext.get(
            BindingContext.TYPE,
            entry.typeReference
        )?.constructor?.declarationDescriptor?.fqNameSafe == fqName
    }
}

```

It’s called inside an AnalysisHandler’s `analysisCompleted`.

The problem is that `bindingContext#get` always returns null, despite `entry.typeReference` not being null.

It looks like it might be a Kotlin bug to me but I’m not sure … I’m using Kotlin 1.4.32

---

<div class="post-metadata">

**Author:** ![Wasabi375](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wasabi375/32/4741_2.png) [@Wasabi375](https://discuss.kotlinlang.org/u/Wasabi375)\
**Post date:** [April 18, 2021, 7:48am UTC](https://discuss.kotlinlang.org/t/bindingcontext-get-type-typereference-returns-null/21566/2 "2021-04-18T07:48:15Z")

</div>

Based on my short search for `KtClassOrObject` I’m guessing you are working or at least using the kotlin compiler as a library.  
I did not spend much time looking thorugh it (only browsed the code a bit on github). The first thing I would check is that your instance of `BindingContext` isn’t `BindingContext.EMPTY`. I couldn’t find another class that implements `BindingContext` but there probably is one.  
Not sure how much more help I can give you without any real context. I’m guessing you know that you are using an internal and undocumented API . I don’t think there are many people who know the kotlin compiler here. I suggest you ask in the kotlin slack([Kotlin Slack Sign-up](https://kotl.in/slack)). IIRC there are a number of groups there with people who should be able to help you.

---

<div class="post-metadata">

**Author:** ![AhmedMourad](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/ahmedmourad/32/7847_2.png) [@AhmedMourad](https://discuss.kotlinlang.org/u/AhmedMourad)\
**Post date:** [April 19, 2021, 3:47am UTC](https://discuss.kotlinlang.org/t/bindingcontext-get-type-typereference-returns-null/21566/3 "2021-04-19T03:47:07Z")

</div>

> I’m guessing you know that you are using an internal and undocumented API

Yup, it’s part of a compiler plugin.

> I don’t think there are many people who know the kotlin compiler here.

I was under the impression that the Kotlin team was involved with answering the questions here, I took the question to the Kotlin Slack and got an answer there.

Thank you.

---

<div class="post-metadata">

**Author:** ![Wasabi375](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/wasabi375/32/4741_2.png) [@Wasabi375](https://discuss.kotlinlang.org/u/Wasabi375)\
**Post date:** [April 19, 2021, 1:26pm UTC](https://discuss.kotlinlang.org/t/bindingcontext-get-type-typereference-returns-null/21566/4 "2021-04-19T13:26:32Z")

</div>

> [@AhmedMourad](#):
>
> I was under the impression that the Kotlin team was involved with answering the questions here

They are but it generaly takes some time for them to answer here. They are far more active on slack.

---

<div class="post-metadata">

**Author:** ![allaudin](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@allaudin](https://discuss.kotlinlang.org/u/allaudin)\
**Post date:** [November 22, 2024, 11:00pm UTC](https://discuss.kotlinlang.org/t/bindingcontext-get-type-typereference-returns-null/21566/5 "2024-11-22T23:00:11Z")

</div>

did you get the answer? How did you fix it?
