question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Multi-modules: superTypes doesn't return the super types

See original GitHub issue

I’m processing an interface (with generics) from another module, this interface extends another interface (also with generics), I can get the properties & functions from the super but superTypes and getAllSuperTypes() returns nothing.


SSCCE: https://github.com/glureau/ksp-kmp-issues/tree/ksp_multimodule_supers Slack: https://kotlinlang.slack.com/archives/C013BA8EQSE/p1641980604009600

(KSP 1.6.0-1.0.2)

Processing from same module: OK

Given an interface extending another interface in mymodule (Base.kt)

package ksp.example

@MyAnnotation
interface Base<T> {
    fun provide(): T
}

@MyAnnotation
interface Advanced<T> : Base<T>

Using KSP on the mymodule will properly resolve Advanced super.

> Task :mymodule:kspKotlinMetadata
> w: [ksp] Supers of Advanced: 1

Processing from another module: KO

If I wrote another module and define an annotation that points to Advanced class (here)

@file:MyFileAnnotation(
    klass = Advanced::class
)

package ksp.example

And if I define my processor this way:

        resolver.getSymbolsWithAnnotation(MyFileAnnotation::class.java.name).forEach {
            it.accept(object : KSVisitorVoid() {
                override fun visitFile(file: KSFile, data: Unit) {
                    file.annotations.forEach { ksAnnotation ->
                        val klass = ksAnnotation.getArg<KSType>(MyFileAnnotation::klass)
                        val classDeclaration = klass.declaration as KSClassDeclaration
                        environment.logger.warn("From another module - Supers of ${classDeclaration.simpleName.asString()}: ${classDeclaration.superTypes.count()}")
                    }
                }
            }, Unit)
        }

then it’s logging that Advanced have no supers.

[ksp] From another module - Supers of Advanced: 0

I was expecting to found the Base class here, like for the 1st example.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8

github_iconTop GitHub Comments

1reaction
neetopiacommented, Apr 11, 2022

Glad it worked out for you!

As for your question, the annotations on a type a part of the type system, usually you don’t need them, they can be found if the annotation is applied on the type rather than the property, you only need to check type annotations if you know you are looking for type annotations.

1reaction
DVDAndroidcommented, Apr 8, 2022

This release fixes this issue I reported on Slack (kinda related)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Supertypes of the following classes cannot be resolved error ...
I was facing this problem in a very similar module architecture. I solved this issue by changing the dependency declaration in ...
Read more >
Using Dagger-Android in a multi-module project
The first step is installing AndroidInjectionModule in our application component to ensure that all the necessary bindings for our base types ...
Read more >
Don't Pass Around Your Room/Database Entity - Jacques Smuts
If you're using Room, you probably have several Room Entity Objects that look ... Supertypes of the following classes cannot be resolved.
Read more >
Common issues and solutions - mypy 0.991 documentation
This section has examples of cases when you need to update your code to use static typing, and ideas for working around issues...
Read more >
Subtypes and Subclasses
This is called covari ance: the return type of the subtype method is a subtype of the return type of the supertype method....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found