Fix "PSI/index mismatch" in case of @ParameterName on non-functional types (KT-34524)
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ public/*package*/ open class Bar : test.Foo {
|
||||
|
||||
public open class Foo {
|
||||
public constructor Foo()
|
||||
public open fun request(): kotlin.reflect.KFunction1<@kotlin.ParameterName(name = "id") kotlin.Long, test.Request>
|
||||
public open fun request(): kotlin.reflect.KFunction1<kotlin.Long, test.Request>
|
||||
}
|
||||
|
||||
public final class Request {
|
||||
|
||||
Vendored
+1
-1
@@ -1,7 +1,7 @@
|
||||
package
|
||||
|
||||
public val annClassRef: kotlin.reflect.KClass<Ann>
|
||||
public val annCtorRef: kotlin.reflect.KFunction1<@kotlin.ParameterName(name = "prop") kotlin.String, Ann>
|
||||
public val annCtorRef: kotlin.reflect.KFunction1<kotlin.String, Ann>
|
||||
public val annPropRef: kotlin.reflect.KProperty1<Ann, kotlin.String>
|
||||
|
||||
public final annotation class Ann : kotlin.Annotation {
|
||||
|
||||
@@ -5,17 +5,17 @@ public fun f2(): kotlin.reflect.KFunction1<java.lang.Runnable, kotlin.Unit>
|
||||
public fun f3(): kotlin.reflect.KClass<java.lang.Runnable>
|
||||
public fun f4(): kotlin.reflect.KFunction1<java.lang.Runnable, kotlin.Unit>
|
||||
public fun f5(): kotlin.reflect.KClass<test.GenericSam<*>>
|
||||
public fun f6(): kotlin.reflect.KFunction2<test.GenericSam<*>, @kotlin.ParameterName(name = "t") kotlin.Nothing!, kotlin.Unit>
|
||||
public fun f6(): kotlin.reflect.KFunction2<test.GenericSam<*>, kotlin.Nothing!, kotlin.Unit>
|
||||
public fun f7(): kotlin.reflect.KClass<test.GenericSam<*>>
|
||||
public fun f8(): kotlin.reflect.KFunction2<test.GenericSam<kotlin.String>, @kotlin.ParameterName(name = "t") kotlin.String!, kotlin.Unit>
|
||||
public fun f8(): kotlin.reflect.KFunction2<test.GenericSam<kotlin.String>, kotlin.String!, kotlin.Unit>
|
||||
public fun g1(): kotlin.reflect.KClass<out java.lang.Runnable>
|
||||
public fun g2(): kotlin.reflect.KFunction0<kotlin.Unit>
|
||||
public fun g3(): kotlin.reflect.KClass<out java.lang.Runnable>
|
||||
public fun g4(): kotlin.reflect.KFunction0<kotlin.Unit>
|
||||
public fun g5(): kotlin.reflect.KClass<out test.GenericSam<kotlin.String>>
|
||||
public fun g6(): kotlin.reflect.KFunction1<@kotlin.ParameterName(name = "t") kotlin.String!, kotlin.Unit>
|
||||
public fun g6(): kotlin.reflect.KFunction1<kotlin.String!, kotlin.Unit>
|
||||
public fun g7(): kotlin.reflect.KClass<out test.GenericSam<kotlin.String>>
|
||||
public fun g8(): kotlin.reflect.KFunction1<@kotlin.ParameterName(name = "t") kotlin.String!, kotlin.Unit>
|
||||
public fun g8(): kotlin.reflect.KFunction1<kotlin.String!, kotlin.Unit>
|
||||
|
||||
package test {
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ package
|
||||
public fun block(): kotlin.Unit
|
||||
public fun expression(): UsefulClass
|
||||
public fun invoker(): kotlin.Unit
|
||||
public fun reflection(): kotlin.reflect.KFunction1<@kotlin.ParameterName(name = "param") kotlin.Int, UsefulClass>
|
||||
public fun reflection(): kotlin.reflect.KFunction1<kotlin.Int, UsefulClass>
|
||||
public fun reflection2(): kotlin.reflect.KFunction1<UsefulClass, kotlin.Unit>
|
||||
@kotlin.Deprecated(message = "does nothing good") public fun kotlin.Any.doNothing(): kotlin.String
|
||||
|
||||
|
||||
@@ -95,9 +95,9 @@ fun <T> Inv<out T>.case_7() {
|
||||
// TESTCASE NUMBER: 8
|
||||
fun <T> T.case_8() {
|
||||
this <!UNCHECKED_CAST!>as MutableList<T><!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.reflect.KFunction1<@kotlin.ParameterName kotlin.Any?, kotlin.Boolean>")!><!DEBUG_INFO_SMARTCAST!>this<!>::equals<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.reflect.KFunction1<kotlin.Any?, kotlin.Boolean>")!><!DEBUG_INFO_SMARTCAST!>this<!>::equals<!>
|
||||
<!DEBUG_INFO_SMARTCAST!>this<!>.equals(10)
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.reflect.KFunction1<@kotlin.ParameterName kotlin.Any?, kotlin.Boolean>")!>::<!DEBUG_INFO_IMPLICIT_RECEIVER_SMARTCAST!>equals<!><!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.reflect.KFunction1<kotlin.Any?, kotlin.Boolean>")!>::<!DEBUG_INFO_IMPLICIT_RECEIVER_SMARTCAST!>equals<!><!>
|
||||
<!DEBUG_INFO_IMPLICIT_RECEIVER_SMARTCAST!>equals<!>(10)
|
||||
}
|
||||
|
||||
|
||||
@@ -41,10 +41,6 @@ internal class DescriptorRendererImpl(
|
||||
} as DescriptorRendererImpl
|
||||
}
|
||||
|
||||
private val functionTypeParameterTypesRenderer: DescriptorRenderer by lazy {
|
||||
withOptions { excludedTypeAnnotationClasses += listOf(KotlinBuiltIns.FQ_NAMES.parameterName) }
|
||||
}
|
||||
|
||||
/* FORMATTING */
|
||||
private fun renderKeyword(keyword: String): String = when (textFormat) {
|
||||
RenderingFormat.PLAIN -> keyword
|
||||
@@ -365,7 +361,7 @@ internal class DescriptorRendererImpl(
|
||||
append(": ")
|
||||
}
|
||||
|
||||
append(functionTypeParameterTypesRenderer.renderTypeProjection(typeProjection))
|
||||
append(renderTypeProjection(typeProjection))
|
||||
}
|
||||
|
||||
append(") ").append(arrow()).append(" ")
|
||||
@@ -413,7 +409,10 @@ internal class DescriptorRendererImpl(
|
||||
|
||||
val annotationFilter = annotationFilter
|
||||
for (annotation in annotated.annotations) {
|
||||
if (annotation.fqName !in excluded && (annotationFilter == null || annotationFilter(annotation))) {
|
||||
if (annotation.fqName !in excluded
|
||||
&& !annotation.isParameterName()
|
||||
&& (annotationFilter == null || annotationFilter(annotation))
|
||||
) {
|
||||
append(renderAnnotation(annotation, target))
|
||||
if (eachAnnotationOnNewLine) {
|
||||
appendln()
|
||||
@@ -424,6 +423,10 @@ internal class DescriptorRendererImpl(
|
||||
}
|
||||
}
|
||||
|
||||
private fun AnnotationDescriptor.isParameterName(): Boolean {
|
||||
return fqName == KotlinBuiltIns.FQ_NAMES.parameterName
|
||||
}
|
||||
|
||||
override fun renderAnnotation(annotation: AnnotationDescriptor, target: AnnotationUseSiteTarget?): String {
|
||||
return buildString {
|
||||
append('@')
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.renderer
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// IntelliJ API Decompiler stub source generated from a class file
|
||||
// Implementation of methods is not available
|
||||
|
||||
package test
|
||||
|
||||
public inline fun <A, B, C : kotlin.Any, D> test.Foo.Companion.foo(crossinline block: test.Context<B, C>.(A, B) -> D): kotlin.Unit { /* compiled code */ }
|
||||
@@ -0,0 +1,10 @@
|
||||
@file:JvmName("ParameterName")
|
||||
package test
|
||||
|
||||
class Foo {
|
||||
companion object
|
||||
}
|
||||
|
||||
class Context<T, U>
|
||||
|
||||
inline fun <A, B, C : Any, D> Foo.Companion.foo(crossinline block: Context<B, C>.(input: A, state: B) -> D) {}
|
||||
+1
-5
@@ -6,9 +6,5 @@ fun foo(a: Int, b: String, d: Baz) {
|
||||
|
||||
}
|
||||
|
||||
class TestClass(
|
||||
val prop1: KFunction3<@ParameterName(name = "a") Int, @ParameterName(name = "b") String, @ParameterName(
|
||||
name = "d"
|
||||
) Baz, Unit> = ::foo
|
||||
) {
|
||||
class TestClass(val prop1: KFunction3<Int, String, Baz, Unit> = ::foo) {
|
||||
}
|
||||
Generated
+18
@@ -48,6 +48,11 @@ public class JvmDecompiledTextTestGenerated extends AbstractJvmDecompiledTextTes
|
||||
runTest("idea/testData/decompiler/decompiledTextJvm/PackageWithQuotes/");
|
||||
}
|
||||
|
||||
@TestMetadata("ParameterName")
|
||||
public void testParameterName() throws Exception {
|
||||
runTest("idea/testData/decompiler/decompiledTextJvm/ParameterName/");
|
||||
}
|
||||
|
||||
@TestMetadata("TestKt")
|
||||
public void testTestKt() throws Exception {
|
||||
runTest("idea/testData/decompiler/decompiledTextJvm/TestKt/");
|
||||
@@ -110,6 +115,19 @@ public class JvmDecompiledTextTestGenerated extends AbstractJvmDecompiledTextTes
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/decompiler/decompiledTextJvm/ParameterName")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class ParameterName extends AbstractJvmDecompiledTextTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInParameterName() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/decompiler/decompiledTextJvm/ParameterName"), Pattern.compile("^([^\\.]+)$"), null, true);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/decompiler/decompiledTextJvm/TestKt")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user