BindingContext.get(TYPE, typeReference) returns null

Hi, so I have this utility function:

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

1 Like

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). IIRC there are a number of groups there with people who should be able to help you.

1 Like

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.

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

1 Like

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