Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package kotlinx.rpc.codegen.checkers
Expand Down Expand Up @@ -231,6 +231,7 @@ object FirCheckedAnnotationHelper {
source = source,
context = context,
reporter = reporter,
typeArgumentIndex = i,
)
}

Expand Down Expand Up @@ -304,6 +305,7 @@ object FirCheckedAnnotationHelper {
source: KtSourceElement?,
context: CheckerContext,
reporter: DiagnosticReporter,
typeArgumentIndex: Int,
) {
for (annotationClass in annotations) {
val hasCheckedAnnotation = hasCheckedAnnotation(
Expand All @@ -316,7 +318,9 @@ object FirCheckedAnnotationHelper {
reporter.reportOn(
source = source,
factory = FirRpcDiagnostics.CHECKED_ANNOTATION_VIOLATION,
a = annotationClass.defaultType(),
a = typeArgumentIndex,
b = annotationClass.defaultType(),
c = classSymbol,
context = context,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies
import org.jetbrains.kotlin.diagnostics.error0
import org.jetbrains.kotlin.diagnostics.error1
import org.jetbrains.kotlin.diagnostics.error2
import org.jetbrains.kotlin.diagnostics.error3
import org.jetbrains.kotlin.diagnostics.rendering.RootDiagnosticRendererFactory
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
import org.jetbrains.kotlin.fir.types.ConeKotlinType
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtAnnotated
Expand All @@ -27,7 +29,7 @@ object FirRpcDiagnostics {
val MISSING_RPC_ANNOTATION by error0<KtAnnotated>()
val MISSING_SERIALIZATION_MODULE by error0<KtAnnotated>()
val WRONG_RPC_ANNOTATION_TARGET by error1<KtAnnotated, ConeKotlinType>()
val CHECKED_ANNOTATION_VIOLATION by error1<KtAnnotated, ConeKotlinType>()
val CHECKED_ANNOTATION_VIOLATION by error3<KtAnnotated, Int, ConeKotlinType, FirBasedSymbol<*>>()
val NON_SUSPENDING_REQUEST_WITHOUT_STREAMING_RETURN_TYPE by error0<KtElement>()
val AD_HOC_POLYMORPHISM_IN_RPC_SERVICE by error2<KtElement, Int, Name>()
val TYPE_PARAMETERS_IN_RPC_FUNCTION by error0<KtElement>(SourceElementPositioningStrategies.TYPE_PARAMETERS_LIST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@ object RpcDiagnosticRendererFactory : BaseDiagnosticRendererFactory() {

put(
factory = FirRpcDiagnostics.CHECKED_ANNOTATION_VIOLATION,
message = "Type argument marked with {0} annotation " +
"must be annotated with {0} or an annotation annotated with {0}.",
rendererA = FirDiagnosticRenderers.RENDER_TYPE,
message = "{0} type argument is marked with @{1} annotation, but inferred type is {2}. " +
"Provide a type that is marked with @{1} annotation explicitly " +
"or remove the annotation from the type argument declaration.",
rendererA = Renderer { it.indexPositionSpelled() },
rendererB = FirDiagnosticRenderers.RENDER_TYPE,
rendererC = FirDiagnosticRenderers.SYMBOL,
)

put(
Expand All @@ -64,6 +67,18 @@ object RpcDiagnosticRendererFactory : BaseDiagnosticRendererFactory() {
}
}

private fun Int.indexPositionSpelled(): String {
val padded = this + 1
val suffix = when (padded % 10) {
1 -> "st"
2 -> "nd"
3 -> "rd"
else -> "th"
}

return "$padded$suffix"
}

class RpcStrictModeDiagnosticRendererFactory(
private val diagnostics: FirRpcStrictModeDiagnostics,
) : BaseDiagnosticRendererFactory() {
Expand Down