Skip to content

Commit

Permalink
Don't require receiver label for KSP declarations
Browse files Browse the repository at this point in the history
Matching the default Kotlin behaviour
  • Loading branch information
rickclephas committed Jul 27, 2024
1 parent a7cad96 commit 9865536
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private fun KSAnnotation.toObjCNameAnnotationSpec(objCName: String?): Annotation
}

@Suppress("FunctionName")
private fun ObjCNameAnnotationSpec(name: String?, swiftName: String?): AnnotationSpec =
internal fun ObjCNameAnnotationSpec(name: String?, swiftName: String?): AnnotationSpec =
AnnotationSpec.builder(objCNameAnnotationClassName).apply {
if (name != null)
addMember("%N = %S", "name", name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ internal fun KSFunctionDeclaration.toNativeCoroutinesFunSpec(
builder.receiver(classDeclaration.toTypeName(typeParameterResolver))
if (extensionReceiver != null) {
val type = extensionReceiver.toTypeName(typeParameterResolver)
receiverParameter = ParameterSpec.builder("receiver", type).build().also(builder::addParameter)
receiverParameter = ParameterSpec.builder("receiver", type)
.addAnnotation(ObjCNameAnnotationSpec(null, "_"))
.build().also(builder::addParameter)
}
} else if (extensionReceiver != null) {
builder.receiver(extensionReceiver.toTypeName(typeParameterResolver))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class CoroutineScopeProviderTests: CompilationTests() {
import kotlin.run
@ObjCName(name = "returnSuspendValue")
public fun MyClass.returnSuspendValueNative(`receiver`: MyOtherClass): NativeSuspend<String> =
nativeSuspend(null) { run { `receiver`.returnSuspendValue() } }
public fun MyClass.returnSuspendValueNative(@ObjCName(swiftName = "_") `receiver`: MyOtherClass):
NativeSuspend<String> = nativeSuspend(null) { run { `receiver`.returnSuspendValue() } }
""".trimIndent())
}
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ class NativeCoroutinesFunSpecTests: CompilationTests() {
import kotlin.run
@ObjCName(name = "returnReceiverValue")
public fun MyClass.returnReceiverValueNative(`receiver`: String): NativeSuspend<String> =
nativeSuspend(null) { run { `receiver`.returnReceiverValue() } }
public fun MyClass.returnReceiverValueNative(@ObjCName(swiftName = "_") `receiver`: String):
NativeSuspend<String> = nativeSuspend(null) { run { `receiver`.returnReceiverValue() } }
""".trimIndent())

@Test
Expand Down

0 comments on commit 9865536

Please sign in to comment.