Skip to content

Commit

Permalink
Added compiler tests for generic checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr3zee committed Dec 4, 2024
1 parent 386bbcc commit 909f8a2
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,10 @@ class FirRpcServiceGenerator(
owner: FirClassSymbol<*>,
name: Name,
rpcServiceStubKey: RpcGeneratedStubKey,
): FirClassLikeSymbol<*> {
): FirClassLikeSymbol<*>? {
val methodName = name.rpcMethodName
val rpcMethod = rpcServiceStubKey.functions.single { it.name == methodName }
val rpcMethod = rpcServiceStubKey.functions.singleOrNull { it.name == methodName }
?: return null
val rpcMethodClassKey = RpcGeneratedRpcMethodClassKey(rpcMethod)
val classKind = if (rpcMethodClassKey.isObject) ClassKind.OBJECT else ClassKind.CLASS

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public void testRpcChecked() {
runTest("src/testData/diagnostics/rpcChecked.kt");
}

@Test
@TestMetadata("rpcService.kt")
public void testRpcService() {
runTest("src/testData/diagnostics/rpcService.kt");
}

@Test
@TestMetadata("strictMode.kt")
public void testStrictMode() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
FILE: rpcService.kt
@FILE:R|kotlin/OptIn|(markerClass = vararg(<getClass>(Q|kotlinx/rpc/internal/utils/ExperimentalRpcApi|)))
@R|kotlinx/rpc/annotations/Rpc|() public abstract interface MyService : R|kotlin/Any|, R|kotlinx/rpc/RemoteService| {
public abstract fun hello(): R|kotlin/Unit|

public abstract suspend fun <T> generic(a: R|T|): R|kotlin/Unit|

public abstract suspend fun <T, T2, T3, T4 : R|kotlin/collections/List<T>|> generic2(a: R|T|, b: R|kotlin/Int|, c: R|T4|, t2: R|T2|): R|T3|

public abstract suspend fun sameName(): R|kotlin/Unit|

public abstract suspend fun sameName(a: R|kotlin/Int|): R|kotlin/Unit|

public abstract suspend fun sameName(a: R|kotlin/Int|, b: R|kotlin/Int|): R|kotlin/Unit|

public abstract suspend fun sameName(a: R|kotlin/Int|, b: R|kotlin/Int|, c: R|kotlin/Int|): R|kotlin/Unit|

public abstract suspend fun sameName2(): R|kotlin/Unit|

public abstract suspend fun sameName2(a: R|kotlin/Int|): R|kotlin/Unit|

public final class $rpcServiceStub : R|kotlin/Any| {
@R|kotlinx/serialization/Serializable|() public final object hello$rpcMethod : R|kotlin/Any| {
public final fun serializer(): R|kotlinx/serialization/KSerializer<MyService.$rpcServiceStub.hello$rpcMethod>|

private constructor(): R|MyService.$rpcServiceStub.hello$rpcMethod| {
super<R|kotlin/Any|>()
}

}

@R|kotlinx/serialization/Serializable|() public final class generic$rpcMethod : R|kotlin/Any| {
public final val a: R|T|
public get(): R|T|

public constructor(a: R|T|): R|MyService.$rpcServiceStub.generic$rpcMethod|

public final companion object Companion : R|kotlin/Any| {
public final fun serializer(): R|kotlinx/serialization/KSerializer<MyService.$rpcServiceStub.generic$rpcMethod>|

private constructor(): R|MyService.$rpcServiceStub.generic$rpcMethod.Companion| {
super<R|kotlin/Any|>()
}

}

@R|kotlin/Deprecated|(message = String(This synthesized declaration should not be used directly), level = Q|kotlin/DeprecationLevel|.R|kotlin/DeprecationLevel.HIDDEN|) public final object $serializer : R|kotlinx/serialization/internal/GeneratedSerializer<MyService.$rpcServiceStub.generic$rpcMethod>| {
public final override fun serialize(encoder: R|kotlinx/serialization/encoding/Encoder|, value: R|MyService.$rpcServiceStub.generic$rpcMethod|): R|kotlin/Unit|

public final override fun deserialize(decoder: R|kotlinx/serialization/encoding/Decoder|): R|MyService.$rpcServiceStub.generic$rpcMethod|

public final val descriptor: R|kotlinx/serialization/descriptors/SerialDescriptor|
public get(): R|kotlinx/serialization/descriptors/SerialDescriptor|

public final override fun childSerializers(): R|kotlin/Array<kotlinx/serialization/KSerializer<*>>|

private constructor(): R|MyService.$rpcServiceStub.generic$rpcMethod.$serializer| {
super<R|kotlin/Any|>()
}

}

}

@R|kotlinx/serialization/Serializable|() public final class generic2$rpcMethod : R|kotlin/Any| {
public final val a: R|T|
public get(): R|T|

public final val b: R|kotlin/Int|
public get(): R|kotlin/Int|

public final val c: R|T4|
public get(): R|T4|

public final val t2: R|T2|
public get(): R|T2|

public constructor(a: R|T|, b: R|kotlin/Int|, c: R|T4|, t2: R|T2|): R|MyService.$rpcServiceStub.generic2$rpcMethod|

public final companion object Companion : R|kotlin/Any| {
public final fun serializer(): R|kotlinx/serialization/KSerializer<MyService.$rpcServiceStub.generic2$rpcMethod>|

private constructor(): R|MyService.$rpcServiceStub.generic2$rpcMethod.Companion| {
super<R|kotlin/Any|>()
}

}

@R|kotlin/Deprecated|(message = String(This synthesized declaration should not be used directly), level = Q|kotlin/DeprecationLevel|.R|kotlin/DeprecationLevel.HIDDEN|) public final object $serializer : R|kotlinx/serialization/internal/GeneratedSerializer<MyService.$rpcServiceStub.generic2$rpcMethod>| {
public final override fun serialize(encoder: R|kotlinx/serialization/encoding/Encoder|, value: R|MyService.$rpcServiceStub.generic2$rpcMethod|): R|kotlin/Unit|

public final override fun deserialize(decoder: R|kotlinx/serialization/encoding/Decoder|): R|MyService.$rpcServiceStub.generic2$rpcMethod|

public final val descriptor: R|kotlinx/serialization/descriptors/SerialDescriptor|
public get(): R|kotlinx/serialization/descriptors/SerialDescriptor|

public final override fun childSerializers(): R|kotlin/Array<kotlinx/serialization/KSerializer<*>>|

private constructor(): R|MyService.$rpcServiceStub.generic2$rpcMethod.$serializer| {
super<R|kotlin/Any|>()
}

}

}

public final companion object Companion : R|kotlin/Any| {
}

}

}
@R|kotlinx/rpc/annotations/Rpc|() public abstract interface MyServiceT<T> : R|kotlin/Any|, R|kotlinx/rpc/RemoteService| {
public final class $rpcServiceStub : R|kotlin/Any| {
public final companion object Companion : R|kotlin/Any| {
}

}

}
@R|kotlinx/rpc/annotations/Rpc|() public abstract interface MyServiceT2<T, R, A, B> : R|kotlin/Any|, R|kotlinx/rpc/RemoteService| {
public final class $rpcServiceStub : R|kotlin/Any| {
public final companion object Companion : R|kotlin/Any| {
}

}

}
44 changes: 44 additions & 0 deletions tests/compiler-plugin-tests/src/testData/diagnostics/rpcService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2023-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

@file:OptIn(ExperimentalRpcApi::class)

import kotlin.coroutines.*
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import kotlinx.serialization.Serializable
import kotlinx.serialization.Contextual
import kotlinx.rpc.annotations.Rpc
import kotlinx.rpc.krpc.streamScoped
import kotlinx.rpc.krpc.withStreamScope
import kotlinx.rpc.krpc.StreamScope
import kotlinx.rpc.krpc.invokeOnStreamScopeCompletion
import kotlinx.rpc.internal.utils.ExperimentalRpcApi

@Rpc
interface MyService {
<!NON_SUSPENDING_REQUEST_WITHOUT_STREAMING_RETURN_TYPE!>fun hello()<!>

suspend fun <!TYPE_PARAMETERS_IN_RPC_FUNCTION!><T><!> generic(a: T)

suspend fun <!TYPE_PARAMETERS_IN_RPC_FUNCTION!><T, T2, T3, T4 : List<T>><!> generic2(a: T, b: Int, c: T4, t2: T2): T3

<!AD_HOC_POLYMORPHISM_IN_RPC_SERVICE!>suspend fun sameName()<!>

<!AD_HOC_POLYMORPHISM_IN_RPC_SERVICE!>suspend fun sameName(a: Int)<!>

<!AD_HOC_POLYMORPHISM_IN_RPC_SERVICE!>suspend fun sameName(a: Int, b: Int)<!>

<!AD_HOC_POLYMORPHISM_IN_RPC_SERVICE!>suspend fun sameName(a: Int, b: Int, c: Int)<!>

<!AD_HOC_POLYMORPHISM_IN_RPC_SERVICE!>suspend fun sameName2()<!>

<!AD_HOC_POLYMORPHISM_IN_RPC_SERVICE!>suspend fun sameName2(a: Int)<!>
}

@Rpc
interface MyServiceT<!TYPE_PARAMETERS_IN_RPC_INTERFACE!><T><!>

@Rpc
interface MyServiceT2<!TYPE_PARAMETERS_IN_RPC_INTERFACE!><T, R, A, B><!>

0 comments on commit 909f8a2

Please sign in to comment.