google / google/ksp

[ksp2] Unexpected symbol type class org.jetbrains.kotlin.analysis.api.fir.symbols.KaFirEnumEntrySymbol

Open
#2,271 2 comments 1 reaction 0 assignees View on GitHub
bug P3
Dominant language
Kotlin
Stars
3.5k
Forks
415
Avg merge
1d 2h
Merged PRs (30d)
53

Description

For a Enum in library, like
```
enum class SomeEnumInLib {
ONE,
TWO,
THREE,
}
```
if you query `SomeEnumInLib.ONE` and ask for its `modifiers` it will crash with `IllegalStateException: Unexpected symbol type class KaFirEnumEntrySymbol`

# Repro

https://github.com/acejingbo/ksp/commit/f370e4c7bbb2d60d088ad635422b9b3da33431b7

See `resolver.getClassDeclarationByName("SomeEnumInSrc.ONE")!!.modifiers}` did not crash
but `resolver.getClassDeclarationByName("SomeEnumInLib.ONE")!!.modifiers}` crash with
```
java.lang.IllegalStateException: Unexpected symbol type class org.jetbrains.kotlin.analysis.api.fir.symbols.KaFirEnumEntrySymbol
at com.google.devtools.ksp.impl.symbol.kotlin.AbstractKSDeclarationImpl$modifiers$2.invoke(AbstractKSDeclarationImpl.kt:67)
at com.google.devtools.ksp.impl.symbol.kotlin.AbstractKSDeclarationImpl$modifiers$2.invoke(AbstractKSDeclarationImpl.kt:59)
at kotlin.SynchronizedLazyImpl.getValue(LazyJVM.kt:83)
at com.google.devtools.ksp.impl.symbol.kotlin.AbstractKSDeclarationImpl.getModifiers(AbstractKSDeclarationImpl.kt:59)
at com.google.devtools.ksp.processor.JavaModifierProcessor.process(JavaModifierProcessor.kt:61)
at com.google.devtools.ksp.impl.KotlinSymbolProcessing$execute$1$1.invoke(KotlinSymbolProcessing.kt:549)
at com.google.devtools.ksp.impl.KotlinSymbolProcessing$execute$1$1.invoke(KotlinSymbolProcessing.kt:547)
at com.google.devtools.ksp.common.IncrementalContextBase.closeFilesOnException(IncrementalContextBase.kt:409)
at com.google.devtools.ksp.impl.KotlinSymbolProcessing.execute(KotlinSymbolProcessing.kt:547)
at com.google.devtools.ksp.test.AbstractKSPAATest.runTest(AbstractKSPAATest.kt:142)
at com.google.devtools.ksp.test.AbstractKSPTest.runTest(AbstractKSPTest.kt:229)
at com.google.devtools.ksp.test.KSPAATest.testJavaModifiers(KSPAATest.kt:353)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.