aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiaxiang Chen <jiaxiang@google.com>2022-05-17 14:52:24 -0700
committerJiaxiang Chen <roaringacw@gmail.com>2022-05-17 16:59:20 -0700
commitda7c2b65d16c25dfbbcce4fce21de95d50d61da8 (patch)
tree92b27fe287f821c64d14324f41359ce03ae1ae66
parentc145d89d1d0a591a19179a92363675e9d1660a43 (diff)
downloadksp-da7c2b65d16c25dfbbcce4fce21de95d50d61da8.tar.gz
use correct type for vararg value parameter descriptor implementation
-rw-r--r--compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSValueParameterDescriptorImpl.kt7
-rw-r--r--compiler-plugin/testData/api/allFunctions.kt36
-rw-r--r--test-utils/src/main/kotlin/com/google/devtools/ksp/processor/AllFunctionsProcessor.kt3
3 files changed, 45 insertions, 1 deletions
diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSValueParameterDescriptorImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSValueParameterDescriptorImpl.kt
index 4d28c8a5..705d49a5 100644
--- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSValueParameterDescriptorImpl.kt
+++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSValueParameterDescriptorImpl.kt
@@ -58,7 +58,12 @@ class KSValueParameterDescriptorImpl private constructor(
}
override val type: KSTypeReference by lazy {
- KSTypeReferenceDescriptorImpl.getCached(descriptor.type, origin, this)
+ // Descriptor wraps vararg with Array<>, to align with the actual behavior in source.
+ if (isVararg) {
+ KSTypeReferenceDescriptorImpl.getCached(descriptor.varargElementType!!, origin, this)
+ } else {
+ KSTypeReferenceDescriptorImpl.getCached(descriptor.type, origin, this)
+ }
}
override val hasDefault: Boolean = descriptor.hasDefaultValue()
diff --git a/compiler-plugin/testData/api/allFunctions.kt b/compiler-plugin/testData/api/allFunctions.kt
index 7d65c760..88dca856 100644
--- a/compiler-plugin/testData/api/allFunctions.kt
+++ b/compiler-plugin/testData/api/allFunctions.kt
@@ -75,6 +75,28 @@
// equals(kotlin.Any): kotlin.Boolean
// hashCode(): kotlin.Int
// toString(): kotlin.String
+// class: Sub
+// equals(kotlin.Any): kotlin.Boolean
+// foo(kotlin.String ...): kotlin.Unit
+// hashCode(): kotlin.Int
+// toString(): kotlin.String
+// class: SubAbstract
+// <init>(): SubAbstract
+// equals(kotlin.Any): kotlin.Boolean
+// foo(kotlin.String ...): kotlin.Unit
+// hashCode(): kotlin.Int
+// toString(): kotlin.String
+// class: Super
+// equals(kotlin.Any): kotlin.Boolean
+// foo(kotlin.String ...): kotlin.Unit
+// hashCode(): kotlin.Int
+// toString(): kotlin.String
+// class: SuperAbstract
+// <init>(): SuperAbstract
+// equals(kotlin.Any): kotlin.Boolean
+// foo(kotlin.String ...): kotlin.Unit
+// hashCode(): kotlin.Int
+// toString(): kotlin.String
// END
// FILE: a.kt
abstract class Foo : C(), List<out Number> {
@@ -97,6 +119,20 @@ data class Data(val a: String) {
}
}
+interface Super {
+ fun foo(vararg values: String)
+}
+
+interface Sub : Super
+
+class SubAbstract: SuperAbstract()
+
+abstract class SuperAbstract {
+ fun foo(vararg values: String) {
+
+ }
+}
+
// FILE: C.java
import java.util.Collection;
diff --git a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/AllFunctionsProcessor.kt b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/AllFunctionsProcessor.kt
index ee25d423..65c682b2 100644
--- a/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/AllFunctionsProcessor.kt
+++ b/test-utils/src/main/kotlin/com/google/devtools/ksp/processor/AllFunctionsProcessor.kt
@@ -50,6 +50,9 @@ class AllFunctionsProcessor : AbstractTestProcessor() {
if (it.hasDefault) {
append("(hasDefault)")
}
+ if (it.isVararg) {
+ append(" ...")
+ }
}
}.joinToString(",")})" +
": ${this.returnType?.resolve()?.declaration?.qualifiedName?.asString() ?: ""}"