Skip to content

Commit c076ad5

Browse files
committed
Don't assign type parameters from original proto if type is substituted with Any (KT-15128)
#KT-15128 Fixed
1 parent e9e1b3f commit c076ad5

File tree

5 files changed

+70
-4
lines changed

5 files changed

+70
-4
lines changed

compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ object KotlinStubVersions {
2828
// Binary stub version should be increased if stub format (org.jetbrains.kotlin.psi.stubs.impl) is changed
2929
// or changes are made to the core stub building code (org.jetbrains.kotlin.idea.decompiler.stubBuilder).
3030
// Increasing this version will lead to reindexing of all binary files that are potentially kotlin binaries (including all class files).
31-
private const val BINARY_STUB_VERSION = 56
31+
private const val BINARY_STUB_VERSION = 57
3232

3333
// Classfile stub version should be increased if changes are made to classfile stub building subsystem (org.jetbrains.kotlin.idea.decompiler.classFile)
3434
// Increasing this version will lead to reindexing of all classfiles.

idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/clsStubBuilding.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,12 @@ fun createStubForPackageName(packageDirectiveStub: KotlinPlaceHolderStubImpl<KtP
141141
fun createStubForTypeName(
142142
typeClassId: ClassId,
143143
parent: StubElement<out PsiElement>,
144-
onUserTypeLevel: (KotlinUserTypeStub, Int) -> Unit = { x, y -> }
144+
bindTypeArguments: (KotlinUserTypeStub, Int) -> Unit = { x, y -> }
145145
): KotlinUserTypeStub {
146+
val substituteWithAny = typeClassId.isLocal
147+
146148
val fqName =
147-
if (typeClassId.isLocal) KotlinBuiltIns.FQ_NAMES.any
149+
if (substituteWithAny) KotlinBuiltIns.FQ_NAMES.any
148150
else typeClassId.asSingleFqName().toUnsafe()
149151
val segments = fqName.pathSegments().asReversed()
150152
assert(segments.isNotEmpty())
@@ -156,7 +158,9 @@ fun createStubForTypeName(
156158
recCreateStubForType(userTypeStub, level + 1)
157159
}
158160
KotlinNameReferenceExpressionStubImpl(userTypeStub, lastSegment.ref())
159-
onUserTypeLevel(userTypeStub, level)
161+
if (!substituteWithAny) {
162+
bindTypeArguments(userTypeStub, level)
163+
}
160164
return userTypeStub
161165
}
162166

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
interface Foo<T>
2+
3+
class AnonymousReturnWithGenericType<T> {
4+
val v1 = object : Foo<T> {}
5+
fun f1() = object : Foo<T> {}
6+
7+
private val v2 = object : Foo<T> {}
8+
private fun f2() = object : Foo<T> {}
9+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
PsiJetFileStubImpl[package=]
2+
PACKAGE_DIRECTIVE
3+
IMPORT_LIST
4+
CLASS[fqName=AnonymousReturnWithGenericType, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=true, name=AnonymousReturnWithGenericType, superNames=[]]
5+
MODIFIER_LIST[public final]
6+
TYPE_PARAMETER_LIST
7+
TYPE_PARAMETER[fqName=null, isInVariance=false, isOutVariance=false, name=T]
8+
PRIMARY_CONSTRUCTOR
9+
MODIFIER_LIST[public]
10+
VALUE_PARAMETER_LIST
11+
CLASS_BODY
12+
PROPERTY[fqName=AnonymousReturnWithGenericType.v1, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=v1]
13+
MODIFIER_LIST[public final]
14+
TYPE_REFERENCE
15+
USER_TYPE
16+
REFERENCE_EXPRESSION[referencedName=Foo]
17+
TYPE_ARGUMENT_LIST
18+
TYPE_PROJECTION[projectionKind=NONE]
19+
TYPE_REFERENCE
20+
USER_TYPE
21+
REFERENCE_EXPRESSION[referencedName=T]
22+
PROPERTY[fqName=AnonymousReturnWithGenericType.v2, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=v2]
23+
MODIFIER_LIST[private final]
24+
TYPE_REFERENCE
25+
USER_TYPE
26+
USER_TYPE
27+
REFERENCE_EXPRESSION[referencedName=kotlin]
28+
REFERENCE_EXPRESSION[referencedName=Any]
29+
FUN[fqName=AnonymousReturnWithGenericType.f1, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, name=f1]
30+
MODIFIER_LIST[public final]
31+
VALUE_PARAMETER_LIST
32+
TYPE_REFERENCE
33+
USER_TYPE
34+
REFERENCE_EXPRESSION[referencedName=Foo]
35+
TYPE_ARGUMENT_LIST
36+
TYPE_PROJECTION[projectionKind=NONE]
37+
TYPE_REFERENCE
38+
USER_TYPE
39+
REFERENCE_EXPRESSION[referencedName=T]
40+
FUN[fqName=AnonymousReturnWithGenericType.f2, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, name=f2]
41+
MODIFIER_LIST[private final]
42+
VALUE_PARAMETER_LIST
43+
TYPE_REFERENCE
44+
USER_TYPE
45+
USER_TYPE
46+
REFERENCE_EXPRESSION[referencedName=kotlin]
47+
REFERENCE_EXPRESSION[referencedName=Any]

idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubBuilderTestGenerated.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ public void testAnnotationsOnNullableTypes() throws Exception {
6060
doTest(fileName);
6161
}
6262

63+
@TestMetadata("AnonymousReturnWithGenericType")
64+
public void testAnonymousReturnWithGenericType() throws Exception {
65+
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/stubBuilder/AnonymousReturnWithGenericType/");
66+
doTest(fileName);
67+
}
68+
6369
@TestMetadata("ClassMembers")
6470
public void testClassMembers() throws Exception {
6571
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/stubBuilder/ClassMembers/");

0 commit comments

Comments
 (0)