While KSP2 is binary compatible with processors written for KSP1, there are some changes in the return values. The differences are listed below:
- KSP1: The whole type will be an error type due to failed type resolution.
- KSP2: It will successfully resolve the container type, and for the non-existent type in the type argument, it will correctly report errors on the specific type argument.
- KSP1: No bounds
- KSP2: An upper bound of
Any?is always inserted for consistency
- KSP1: Expanded to the underlying, non-alias type
- KSP2: Not expanded, like uses in other places
- KSP1: Constructors have FQN if the constructor is from source, but not if the constructor is from a library.
- KSP2: Constructors do not have FQN
- KSP1: Inner types has arguments from outer types
- KSP2: Inner types has no arguments from outer types
- KSP1: Star projections have type arguments that are expanded to the effective variances according to the declaration sites.
- KSP2: No expansion. Star projections have nulls in their type arguments.
- KSP1: Java Array has a invariant upper bound
- KSP2: Java Array has a covariant upper bound
- KSP1: Each enum entry has itsown type
- KSP2: All enum entries share the same type with the enclosing enum class
- KSP1: An annotation argument that is an enum entry is evaluated as a
KSTypeof the corresponding enum entry - KSP2: An annotation argument that is an enum entry is evaluated directly as the corresponding
KSClassDeclarationof the enum entry
For example
interface GrandBaseInterface1 {
fun foo(): Unit
}
interface GrandBaseInterface2 {
fun foo(): Unit
}
interface BaseInterface1 : GrandBaseInterface1 {
}
interface BaseInterface2 : GrandBaseInterface2 {
}
class OverrideOrder1 : BaseInterface1, GrandBaseInterface2 {
override fun foo() = TODO()
}
class OverrideOrder2 : BaseInterface2, GrandBaseInterface1 {
override fun foo() = TODO()
}
- KSP1: Find overridden symbols in BFS order, first super type found on direct super type list that contains overridden
symbol is returned. For the example, KSP will say
OverrideOrder1.foo()overridesGrandBaseInterface2.foo()andOverrideOrder2.foo()overridesGrandBaseInterface1.foo(). - KSP2: DFS order, first super type found overridden symbols (with recursive super type look up) in direct super type
list is returned. For the example, KSP will say
OverrideOrder1.foo()overridesGrandBaseInterface1.foo()andOverrideOrder2.foo()overridesGrandBaseInterface2.foo().
- KSP1: Transient/volatile fields are final by default
- KSP2: Transient/volatile fields are open by default
- KSP1: Type annotations on a type argument is only reflected on the type argument symbol
- KSP2: Type annotations on a type argument now present in the resolved type as well
- KSP1: Considered as an
Arraytype when it is from Java sources. - KSP2: Not considered as an
Arraytype. KSValueParameter returns the declared type consistently.
- KSP1:
valuesandvalueOfare missing if the enum is defined in Kotlin sources - KSP2:
valuesandvalueOfare always present
- KSP1:
componentNandcopyare missing if the data class is defined in Kotlin sources - KSP2:
componentNandcopyare always present
- KSP1: The super type of Enum classes is
Any - KSP2: The super type of Enum classes is
Enum