Skip to content

Commit 18af5e5

Browse files
Michal Kielbowiczampagent
andcommitted
Preserve Kotlin 2.4.0 compiler plugin compatibility
Amp-Thread-ID: https://ampcode.com/threads/T-01a08f5a-c048-7069-a3a5-331ccf6af989 Co-authored-by: Amp <amp@ampcode.com>
1 parent f8c113d commit 18af5e5

2 files changed

Lines changed: 31 additions & 4 deletions

File tree

scip-kotlinc/build.gradle.kts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ dependencies {
2626

2727
tasks.named<Test>("test") {
2828
maxHeapSize = "2g"
29+
dependsOn("testKotlin240")
30+
}
31+
32+
// The plugin runs inside the indexed project's compiler, which can predate our build compiler.
33+
val kotlin240TestRuntime = configurations.create("kotlin240TestRuntime") {
34+
extendsFrom(configurations.testRuntimeClasspath.get())
35+
resolutionStrategy.force("org.jetbrains.kotlin:kotlin-compiler-embeddable:2.4.0")
36+
}
37+
38+
tasks.register<Test>("testKotlin240") {
39+
useJUnitPlatform()
40+
testClassesDirs = sourceSets.test.get().output.classesDirs
41+
classpath = sourceSets.test.get().output + sourceSets.main.get().output + kotlin240TestRuntime
42+
maxHeapSize = "2g"
2943
}
3044

3145
tasks.named<ShadowJar>("shadowJar") {

scip-kotlinc/src/main/kotlin/org/scip_code/scip_java/kotlinc/AnalyzerCheckers.kt

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.fir.resolve.getContainingClassSymbol
2626
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
2727
import org.jetbrains.kotlin.fir.resolve.toClassLikeSymbol
2828
import org.jetbrains.kotlin.fir.symbols.impl.FirAnonymousObjectSymbol
29+
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
2930
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
3031
import org.jetbrains.kotlin.fir.types.FirTypeRef
3132
import org.jetbrains.kotlin.lexer.KtTokens
@@ -74,7 +75,8 @@ open class AnalyzerCheckers(session: FirSession) : FirAdditionalCheckersExtensio
7475
override val classLikeCheckers: Set<FirClassLikeChecker> = setOf(SemanticClassLikeChecker())
7576
override val constructorCheckers: Set<FirConstructorChecker> =
7677
setOf(SemanticConstructorChecker())
77-
override val namedFunctionCheckers: Set<FirNamedFunctionChecker> =
78+
// The specialized checker property was renamed in Kotlin 2.4.20.
79+
override val functionCheckers: Set<FirFunctionChecker> =
7880
setOf(SemanticSimpleFunctionChecker())
7981
override val anonymousFunctionCheckers: Set<FirAnonymousFunctionChecker> =
8082
setOf(SemanticAnonymousFunctionChecker())
@@ -278,9 +280,10 @@ open class AnalyzerCheckers(session: FirSession) : FirAdditionalCheckersExtensio
278280
}
279281
}
280282

281-
private class SemanticSimpleFunctionChecker : FirNamedFunctionChecker(MppCheckerKind.Common) {
283+
private class SemanticSimpleFunctionChecker : FirFunctionChecker(MppCheckerKind.Common) {
282284
context(context: CheckerContext, reporter: DiagnosticReporter)
283-
override fun check(declaration: FirNamedFunction) {
285+
override fun check(declaration: FirFunction) {
286+
if (declaration !is FirNamedFunction) return
284287
val source = declaration.source ?: return
285288
val ktFile = context.containingFileSymbol?.sourceFile ?: return
286289
val visitor = visitors[ktFile]
@@ -388,9 +391,19 @@ open class AnalyzerCheckers(session: FirSession) : FirAdditionalCheckersExtensio
388391

389392
private class SemanticResolvedQualifierChecker :
390393
FirResolvedQualifierChecker(MppCheckerKind.Common) {
394+
companion object {
395+
// Resolve once against the host compiler: symbol became qualifierSymbol in 2.4.20.
396+
private val symbolGetter =
397+
try {
398+
FirResolvedQualifier::class.java.getMethod("getQualifierSymbol")
399+
} catch (_: NoSuchMethodException) {
400+
FirResolvedQualifier::class.java.getMethod("getSymbol")
401+
}
402+
}
403+
391404
context(context: CheckerContext, reporter: DiagnosticReporter)
392405
override fun check(expression: FirResolvedQualifier) {
393-
val symbol = expression.qualifierSymbol ?: return
406+
val symbol = symbolGetter.invoke(expression) as FirClassLikeSymbol<*>? ?: return
394407
val source = expression.source ?: return
395408
if (source.kind is KtFakeSourceElementKind) return
396409
val ktFile = context.containingFileSymbol?.sourceFile ?: return

0 commit comments

Comments
 (0)