Skip to content

Commit 5026cfd

Browse files
authored
Defer optics generation of invalid classes to later ksp rounds (#3537)
1 parent 2319143 commit 5026cfd

File tree

1 file changed

+8
-6
lines changed
  • arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin

1 file changed

+8
-6
lines changed

arrow-libs/optics/arrow-optics-ksp-plugin/src/main/kotlin/arrow/optics/plugin/OpticsProcessor.kt

+8-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import com.google.devtools.ksp.processing.Resolver
1515
import com.google.devtools.ksp.processing.SymbolProcessor
1616
import com.google.devtools.ksp.symbol.KSAnnotated
1717
import com.google.devtools.ksp.symbol.KSClassDeclaration
18+
import com.google.devtools.ksp.validate
1819

1920
class OpticsProcessor(
2021
private val codegen: CodeGenerator,
@@ -23,15 +24,16 @@ class OpticsProcessor(
2324
) :
2425
SymbolProcessor {
2526
override fun process(resolver: Resolver): List<KSAnnotated> {
26-
resolver
27+
val (resolved, deferred) = resolver
2728
.getSymbolsWithAnnotation("arrow.optics.optics")
2829
.filterIsInstance<KSClassDeclaration>()
29-
.forEach(::processClass)
30+
.partition { it.validate() }
31+
resolved.forEach(::processClass)
3032

31-
// the docs say that [process] should return
32-
// "deferred symbols that the processor can't process"
33-
// and in theory we have none
34-
return emptyList()
33+
// If types used by the annotated class are by other processors,
34+
// such class will fail the validation. In that case, we need to
35+
// defer the code generation for the class to the next round
36+
return deferred
3537
}
3638

3739
private fun processClass(klass: KSClassDeclaration) {

0 commit comments

Comments
 (0)