Skip to content

Commit 93c246c

Browse files
authored
Fix usage of protobufMessage.arguments in RpcStubGenerator (#436)
1 parent bacb8a5 commit 93c246c

File tree

9 files changed

+31
-3
lines changed

9 files changed

+31
-3
lines changed

compiler-plugin/compiler-plugin-backend/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
77
plugins {
88
alias(libs.plugins.conventions.jvm)
99
alias(libs.plugins.compiler.specific.module)
10+
alias(libs.plugins.conventions.no.psi.element)
1011
}
1112

1213
kotlin {

compiler-plugin/compiler-plugin-backend/src/main/kotlin/kotlinx/rpc/codegen/extension/RpcStubGenerator.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ internal class RpcStubGenerator(
12451245
val protobufMessage = owner.getAnnotation(ctx.withCodecAnnotation.owner.kotlinFqName)
12461246

12471247
return if (protobufMessage != null) {
1248-
val classReference = protobufMessage.arguments.single() as? IrClassReference
1248+
val classReference = vsApi{ protobufMessage.argumentsVS }.single() as? IrClassReference
12491249
?: error("Expected IrClassReference for ${ctx.withCodecAnnotation.owner.kotlinFqName} parameter")
12501250

12511251
val codec = classReference.classType

compiler-plugin/compiler-plugin-cli/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
77
plugins {
88
alias(libs.plugins.conventions.jvm)
99
alias(libs.plugins.compiler.specific.module)
10+
alias(libs.plugins.conventions.no.psi.element)
1011
}
1112

1213
kotlin {

compiler-plugin/compiler-plugin-common/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode
77
plugins {
88
alias(libs.plugins.conventions.jvm)
99
alias(libs.plugins.compiler.specific.module)
10+
alias(libs.plugins.conventions.no.psi.element)
1011
}
1112

1213
kotlin {

compiler-plugin/compiler-plugin-k2/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import util.whenKotlinCompilerIsAtLeast
1010
plugins {
1111
alias(libs.plugins.conventions.jvm)
1212
alias(libs.plugins.compiler.specific.module)
13+
alias(libs.plugins.conventions.no.psi.element)
1314
}
1415

1516
tasks.jar {

compiler-plugin/compiler-plugin-k2/src/main/kotlin/kotlinx/rpc/codegen/checkers/FirWithCodecDeclarationChecker.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ object FirWithCodecDeclarationChecker {
5757

5858
val codecTargetClass = codecClassSymbol.findMessageCodecSuperType(context.session)
5959
.typeArguments.first().type
60+
?: error("Unexpected unresolved type argument for @WithCodec annotation")
6061

61-
if (codecTargetClass?.classId != declaration.symbol.classId) {
62+
if (codecTargetClass.classId != declaration.symbol.classId) {
6263
reporter.reportOn(
6364
source = withCodec.findArgumentByName(CODEC_ARGUMENT_NAME)?.source,
6465
factory = FirGrpcDiagnostics.CODEC_TYPE_MISMATCH,
6566
a = declaration.symbol.defaultType(),
66-
b = kClassValue,
67+
b = codecTargetClass,
6768
context = context,
6869
)
6970
}

compiler-plugin/compiler-plugin-k2/src/main/templates/kotlinx/rpc/codegen/checkers/diagnostics/RpcKtDiagnosticsContainer.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ fun registerDiagnosticRendererFactories() {
3232
//##csm specific=[2.0.0...2.2.10]
3333
RootDiagnosticRendererFactory.registerFactory(FirRpcDiagnostics.getRendererFactoryVs())
3434
RootDiagnosticRendererFactory.registerFactory(FirRpcStrictModeDiagnostics.getRendererFactoryVs())
35+
RootDiagnosticRendererFactory.registerFactory(FirGrpcDiagnostics.getRendererFactoryVs())
3536
//##csm /specific
3637
//##csm /registerDiagnosticRendererFactories
3738
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
3+
*/
4+
5+
import kotlin.io.path.readLines
6+
7+
gradle.afterProject {
8+
layout.projectDirectory.dir("src").asFileTree.visit {
9+
if (isDirectory) return@visit
10+
if (file.name.endsWith(".kt")) {
11+
file.toPath().readLines().forEach { line ->
12+
if (!line.trim().startsWith("//") && line.contains("PsiElement")) {
13+
throw GradleException(
14+
"Kotlin source file $file must not contain `PsiElement` reference " +
15+
"in the compiler plugin. Use KtElement instead."
16+
)
17+
}
18+
}
19+
}
20+
}
21+
}

versions-root/libs.versions.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ conventions-npm = { id = "conventions-npm" }
159159
conventions-root = { id = "conventions-root" }
160160
conventions-dokka-spec = { id = "conventions-dokka-spec" }
161161
conventions-dokka-public = { id = "conventions-dokka-public" }
162+
conventions-no-psi-element = { id = "conventions-no-psi-element" }
162163
compiler-specific-module = { id = "compiler-specific-module" }
163164

164165
# gradle-plugin project

0 commit comments

Comments
 (0)