ZacSweers / kotlin-compile-testing

A library for testing Kotlin and Java annotation processors, compiler plugins and code generation
Mozilla Public License 2.0
109 stars 7 forks source link

resolver.getSymbolsWithAnnotation doesn't return all annotated symbols #285

Open tokazio opened 1 month ago

tokazio commented 1 month ago

I have a test case that was ok in kotlin 1.9.24 and compatible ksp and kotlin-compile-testing

When upgrading to 2.0.20 (and the latest 0.5.1 from here) it's not ok anymore

Given a data class

data class TestData(
  @FilteredField(read = PermissionScope.PRIVATE)
  var name: String? = ""

  override var description: String? = "",

): TestInterface

and its interface

interface TestInterface {
    @FilteredField(read = PermissionScope.SECRET)
    var description: String?
}

Compiling like

val kotlinSourceData = SourceFile.fromPath("TestData.kt".fromResource())
val kotlinSourceInterface = SourceFile.fromPath("TestInterface.kt".fromResource())
KotlinCompilation().apply {
    sources = listOf(kotlinSourceData,kotlinSourceInterface)
    workingDir = temporaryFolder
    inheritClassPath = true
    jvmTarget = JvmTarget.JVM_17.description
    configureKsp(useKsp2 = true) {
      symbolProcessorProviders.add(FilteredFieldSymbolProvider())
      kspIncremental = true
      incrementalLog = true
      withCompilation = true
      loggingLevels = setOf(CompilerMessageSeverity.INFO)
    }
    kspIncremental = true
  }
    .compile()

I can see the 2 files in the compilation results but

The description property from the interface is not in the result list of resolver.getSymbolsWithAnnotation("...FilteredField",false)

tokazio commented 1 month ago

seems to use a ResolverAAImpl from ksp 2.0.0-1.0.22

when forcing to com.google.devtools.ksp:symbol-processing-aa-embeddable:2.0.20-1.0.25 seems to gives the same result: no symbol from the interface

The 'normaly' generated file is ok and contains the symbol annotated from the interface

ZacSweers commented 1 month ago

Please share a minimally reproducible sample project or failing test case in this repo, thanks!

ZacSweers commented 1 month ago

Also see #257 in case

tokazio commented 1 month ago

Yes using

val compilation = KotlinCompilation().apply {
  sources = sourceFiles
  configureKsp(useKsp2 = true) {
    withCompilation = true
    symbolProcessorProviders.add(...)
  }
}

is better but not sufficient

ZacSweers commented 1 month ago

Sorry that's not a reproducible sample project or test. Going to have to insist on that or I'll need to close this issue.

tokazio commented 1 month ago

yes i need to find some minutes to give you a sample