[FIR] propagate copy of original ConeKotlinType to anonymous functions to avoid concurrent modification

It is required to avoid leakage of annotations instance from
the original type
It should be enough to just create a new instance of an annotation
without a deep copy, because transformer shouldn't touch it

^KT-60387 Fixed
This commit is contained in:
Dmitrii Gridin
2023-07-13 16:22:59 +02:00
committed by Space Team
parent 51b9059123
commit d0854d5b45
21 changed files with 336 additions and 16 deletions
@@ -0,0 +1,21 @@
// FILE: usage.kt
<expr>
val propertyToResolve: String
get() = JavaClass.function()?.let { " ($it)" } ?: ""
</expr>
// FILE: Anno.java
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target(ElementType.TYPE_USE)
public @interface Anno {
String value();
}
// FILE: JavaClass.java
public class JavaClass {
public static @Anno("outer") List<@Anno("middle") List<@Anno("inner") Integer>> function() {
return null;
}
}
@@ -0,0 +1,23 @@
KT element: KtProperty
FIR element: FirPropertyImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
public final [ResolvedTo(BODY_RESOLVE)] val propertyToResolve: R|kotlin/String|
public [ResolvedTo(BODY_RESOLVE)] get(): R|kotlin/String| {
^ <Unresolved name: JavaClass>#.<Unresolved name: function>#()?.{ $subj$.<Unresolved name: let>#(<L> = [ResolvedTo(BODY_RESOLVE)] let@fun <anonymous>(): R|kotlin/String| <inline=Unknown> {
^ <strcat>(String( (), <Unresolved name: it>#, String()))
}
) } ?: String()
}
FIR FILE:
FILE: [ResolvedTo(IMPORTS)] usage.kt
[ResolvedTo(BODY_RESOLVE)] annotations container
public final [ResolvedTo(BODY_RESOLVE)] val propertyToResolve: R|kotlin/String|
public [ResolvedTo(BODY_RESOLVE)] get(): R|kotlin/String| {
^ <Unresolved name: JavaClass>#.<Unresolved name: function>#()?.{ $subj$.<Unresolved name: let>#(<L> = [ResolvedTo(BODY_RESOLVE)] let@fun <anonymous>(): R|kotlin/String| <inline=Unknown> {
^ <strcat>(String( (), <Unresolved name: it>#, String()))
}
) } ?: String()
}
@@ -0,0 +1,23 @@
KT element: KtProperty
FIR element: FirPropertyImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
public final [ResolvedTo(BODY_RESOLVE)] val propertyToResolve: R|kotlin/String|
public [ResolvedTo(BODY_RESOLVE)] get(): R|kotlin/String| {
^ Q|JavaClass|.R|/JavaClass.function|()?.{ $subj$.R|kotlin/let|<R|@R|Anno|(value = String(outer)) List|, R|kotlin/String|>(<L> = [ResolvedTo(BODY_RESOLVE)] [MatchingParameterFunctionTypeKey=kotlin/Function1<T, R>] let@fun <anonymous>([ResolvedTo(BODY_RESOLVE)] it: R|@R|Anno|(value = String(outer)) List|): R|kotlin/String| <inline=Inline, kind=EXACTLY_ONCE> {
^ <strcat>(String( (), R|<local>/it|, String()))
}
) } ?: String()
}
FIR FILE:
FILE: [ResolvedTo(IMPORTS)] usage.kt
[ResolvedTo(BODY_RESOLVE)] annotations container
public final [ResolvedTo(BODY_RESOLVE)] val propertyToResolve: R|kotlin/String|
public [ResolvedTo(BODY_RESOLVE)] get(): R|kotlin/String| {
^ Q|JavaClass|.R|/JavaClass.function|()?.{ $subj$.R|kotlin/let|<R|@R|Anno|(value = String(outer)) List|, R|kotlin/String|>(<L> = [ResolvedTo(BODY_RESOLVE)] [MatchingParameterFunctionTypeKey=kotlin/Function1<T, R>] let@fun <anonymous>([ResolvedTo(BODY_RESOLVE)] it: R|@R|Anno|(value = String(outer)) List|): R|kotlin/String| <inline=Inline, kind=EXACTLY_ONCE> {
^ <strcat>(String( (), R|<local>/it|, String()))
}
) } ?: String()
}
@@ -0,0 +1,21 @@
// FILE: usage.kt
<expr>
val propertyToResolve: String
get() = JavaClass.function().let { " ($it)" }
</expr>
// FILE: Anno.java
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;
@Target(ElementType.TYPE_USE)
public @interface Anno {
String value();
}
// FILE: JavaClass.java
public class JavaClass {
public static @Anno("outer") List<@Anno("middle") List<@Anno("inner") Integer>> function() {
return null;
}
}
@@ -0,0 +1,23 @@
KT element: KtProperty
FIR element: FirPropertyImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
public final [ResolvedTo(BODY_RESOLVE)] val propertyToResolve: R|kotlin/String|
public [ResolvedTo(BODY_RESOLVE)] get(): R|kotlin/String| {
^ <Unresolved name: JavaClass>#.<Unresolved name: function>#().<Unresolved name: let>#(<L> = [ResolvedTo(BODY_RESOLVE)] let@fun <anonymous>(): R|kotlin/String| <inline=Unknown> {
^ <strcat>(String( (), <Unresolved name: it>#, String()))
}
)
}
FIR FILE:
FILE: [ResolvedTo(IMPORTS)] usage.kt
[ResolvedTo(BODY_RESOLVE)] annotations container
public final [ResolvedTo(BODY_RESOLVE)] val propertyToResolve: R|kotlin/String|
public [ResolvedTo(BODY_RESOLVE)] get(): R|kotlin/String| {
^ <Unresolved name: JavaClass>#.<Unresolved name: function>#().<Unresolved name: let>#(<L> = [ResolvedTo(BODY_RESOLVE)] let@fun <anonymous>(): R|kotlin/String| <inline=Unknown> {
^ <strcat>(String( (), <Unresolved name: it>#, String()))
}
)
}
@@ -0,0 +1,23 @@
KT element: KtProperty
FIR element: FirPropertyImpl
FIR source kind: KtRealSourceElementKind
FIR element rendered:
public final [ResolvedTo(BODY_RESOLVE)] val propertyToResolve: R|kotlin/String|
public [ResolvedTo(BODY_RESOLVE)] get(): R|kotlin/String| {
^ Q|JavaClass|.R|/JavaClass.function|().R|kotlin/let|<R|@R|Anno|(value = String(outer)) List!|, R|kotlin/String|>(<L> = [ResolvedTo(BODY_RESOLVE)] [MatchingParameterFunctionTypeKey=kotlin/Function1<T, R>] let@fun <anonymous>([ResolvedTo(BODY_RESOLVE)] it: R|@R|Anno|(value = String(outer)) List!|): R|kotlin/String| <inline=Inline, kind=EXACTLY_ONCE> {
^ <strcat>(String( (), R|<local>/it|, String()))
}
)
}
FIR FILE:
FILE: [ResolvedTo(IMPORTS)] usage.kt
[ResolvedTo(BODY_RESOLVE)] annotations container
public final [ResolvedTo(BODY_RESOLVE)] val propertyToResolve: R|kotlin/String|
public [ResolvedTo(BODY_RESOLVE)] get(): R|kotlin/String| {
^ Q|JavaClass|.R|/JavaClass.function|().R|kotlin/let|<R|@R|Anno|(value = String(outer)) List!|, R|kotlin/String|>(<L> = [ResolvedTo(BODY_RESOLVE)] [MatchingParameterFunctionTypeKey=kotlin/Function1<T, R>] let@fun <anonymous>([ResolvedTo(BODY_RESOLVE)] it: R|@R|Anno|(value = String(outer)) List!|): R|kotlin/String| <inline=Inline, kind=EXACTLY_ONCE> {
^ <strcat>(String( (), R|<local>/it|, String()))
}
)
}
@@ -229,8 +229,8 @@ FILE: [ResolvedTo(IMPORTS)] anonymousFunctionWithAnnotatedParameter.kt
public [ResolvedTo(STATUS)] [ContainingClassKey=Anno] get(): R|kotlin/String|
}
public final [ResolvedTo(CONTRACTS)] val nullablePropertyWithAnnotatedType: R|@R|Anno|(message = String(outer)) kotlin/collections/List<@R|Anno|(message = String(middle)) kotlin/collections/List<@R|Anno|(message = String(inner)) kotlin/Int>>?|
public [ResolvedTo(CONTRACTS)] get(): R|@R|Anno|(message = String(outer)) kotlin/collections/List<@R|Anno|(message = String(middle)) kotlin/collections/List<@R|Anno|(message = String(inner)) kotlin/Int>>?| {
public final [ResolvedTo(CONTRACTS)] val nullablePropertyWithAnnotatedType: R|@R|Anno|(String(outer)) kotlin/collections/List<@R|Anno|(String(middle)) kotlin/collections/List<@R|Anno|(String(inner)) kotlin/Int>>?|
public [ResolvedTo(CONTRACTS)] get(): R|@R|Anno|(String(outer)) kotlin/collections/List<@R|Anno|(String(middle)) kotlin/collections/List<@R|Anno|(String(inner)) kotlin/Int>>?| {
^ Null(null)
}
public final [ResolvedTo(BODY_RESOLVE)] val propertyToResolve: R|kotlin/String|
@@ -229,13 +229,13 @@ FILE: [ResolvedTo(IMPORTS)] anonymousFunctionWithAnnotatedParameter2.kt
public [ResolvedTo(STATUS)] [ContainingClassKey=Anno] get(): R|kotlin/String|
}
public final [ResolvedTo(CONTRACTS)] val nullablePropertyWithAnnotatedType: R|@R|Anno|(message = String(outer)) kotlin/collections/List<@R|Anno|(message = String(middle)) kotlin/collections/List<@R|Anno|(message = String(inner)) kotlin/Int>>?|
public [ResolvedTo(CONTRACTS)] get(): R|@R|Anno|(message = String(outer)) kotlin/collections/List<@R|Anno|(message = String(middle)) kotlin/collections/List<@R|Anno|(message = String(inner)) kotlin/Int>>?| {
public final [ResolvedTo(CONTRACTS)] val nullablePropertyWithAnnotatedType: R|@R|Anno|(String(outer)) kotlin/collections/List<@R|Anno|(String(middle)) kotlin/collections/List<@R|Anno|(String(inner)) kotlin/Int>>?|
public [ResolvedTo(CONTRACTS)] get(): R|@R|Anno|(String(outer)) kotlin/collections/List<@R|Anno|(String(middle)) kotlin/collections/List<@R|Anno|(String(inner)) kotlin/Int>>?| {
^ Null(null)
}
public final [ResolvedTo(BODY_RESOLVE)] val propertyToResolve: R|kotlin/String|
public [ResolvedTo(BODY_RESOLVE)] get(): R|kotlin/String| {
^ R|/nullablePropertyWithAnnotatedType|.R|kotlin/let|<R|@R|Anno|(message = String(outer)) kotlin/collections/List<@R|Anno|(message = String(middle)) kotlin/collections/List<@R|Anno|(message = String(inner)) kotlin/Int>>?|, R|kotlin/String|>(<L> = [ResolvedTo(BODY_RESOLVE)] [MatchingParameterFunctionTypeKey=kotlin/Function1<T, R>] let@fun <anonymous>([ResolvedTo(BODY_RESOLVE)] it: R|@R|Anno|(message = String(outer)) kotlin/collections/List<@R|Anno|(message = String(middle)) kotlin/collections/List<@R|Anno|(message = String(inner)) kotlin/Int>>?|): R|kotlin/String| <inline=Inline, kind=EXACTLY_ONCE> {
^ R|/nullablePropertyWithAnnotatedType|.R|kotlin/let|<R|@R|Anno|(String(outer)) kotlin/collections/List<@R|Anno|(String(middle)) kotlin/collections/List<@R|Anno|(String(inner)) kotlin/Int>>?|, R|kotlin/String|>(<L> = [ResolvedTo(BODY_RESOLVE)] [MatchingParameterFunctionTypeKey=kotlin/Function1<T, R>] let@fun <anonymous>([ResolvedTo(BODY_RESOLVE)] it: R|@R|Anno|(message = String(outer)) kotlin/collections/List<@R|Anno|(message = String(middle)) kotlin/collections/List<@R|Anno|(message = String(inner)) kotlin/Int>>?|): R|kotlin/String| <inline=Inline, kind=EXACTLY_ONCE> {
^ <strcat>(String( (), R|<local>/it|, String()))
}
)
@@ -185,8 +185,8 @@ FILE: [ResolvedTo(IMPORTS)] anonymousFunctionWithAnnotatedParameterOnImplicitTyp
public [ResolvedTo(STATUS)] [ContainingClassKey=Anno] get(): R|kotlin/String|
}
public final [ResolvedTo(CONTRACTS)] val nullablePropertyWithAnnotatedType: R|@R|Anno|(message = String(str)) kotlin/String?|
public [ResolvedTo(CONTRACTS)] get(): R|@R|Anno|(message = String(str)) kotlin/String?| {
public final [ResolvedTo(CONTRACTS)] val nullablePropertyWithAnnotatedType: R|@R|Anno|(String(str)) kotlin/String?|
public [ResolvedTo(CONTRACTS)] get(): R|@R|Anno|(String(str)) kotlin/String?| {
^ Null(null)
}
public final [ResolvedTo(IMPLICIT_TYPES_BODY_RESOLVE)] val propertyToResolve: R|kotlin/String|
@@ -209,8 +209,8 @@ FILE: [ResolvedTo(IMPORTS)] anonymousFunctionWithAnnotatedParameterOnImplicitTyp
public [ResolvedTo(STATUS)] [ContainingClassKey=Anno] get(): R|kotlin/String|
}
public final [ResolvedTo(CONTRACTS)] val nullablePropertyWithAnnotatedType: R|@R|Anno|(message = String(str)) kotlin/String?|
public [ResolvedTo(CONTRACTS)] get(): R|@R|Anno|(message = String(str)) kotlin/String?| {
public final [ResolvedTo(CONTRACTS)] val nullablePropertyWithAnnotatedType: R|@R|Anno|(String(str)) kotlin/String?|
public [ResolvedTo(CONTRACTS)] get(): R|@R|Anno|(String(str)) kotlin/String?| {
^ Null(null)
}
public final [ResolvedTo(ANNOTATIONS_ARGUMENTS_MAPPING)] val propertyToResolve: R|kotlin/String|
@@ -233,8 +233,8 @@ FILE: [ResolvedTo(IMPORTS)] anonymousFunctionWithAnnotatedParameterOnImplicitTyp
public [ResolvedTo(STATUS)] [ContainingClassKey=Anno] get(): R|kotlin/String|
}
public final [ResolvedTo(CONTRACTS)] val nullablePropertyWithAnnotatedType: R|@R|Anno|(message = String(str)) kotlin/String?|
public [ResolvedTo(CONTRACTS)] get(): R|@R|Anno|(message = String(str)) kotlin/String?| {
public final [ResolvedTo(CONTRACTS)] val nullablePropertyWithAnnotatedType: R|@R|Anno|(String(str)) kotlin/String?|
public [ResolvedTo(CONTRACTS)] get(): R|@R|Anno|(String(str)) kotlin/String?| {
^ Null(null)
}
public final [ResolvedTo(BODY_RESOLVE)] val propertyToResolve: R|kotlin/String|
@@ -1159,6 +1159,18 @@ public class OutOfContentRootGetOrBuildFirTestGenerated extends AbstractOutOfCon
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/wholeDeclaration/primaryConstructorValueParameter.kt");
}
@Test
@TestMetadata("propagateFlexibleTypeToAnonymousFunction.kt")
public void testPropagateFlexibleTypeToAnonymousFunction() throws Exception {
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/wholeDeclaration/propagateFlexibleTypeToAnonymousFunction.kt");
}
@Test
@TestMetadata("propagateFlexibleTypeToAnonymousFunction2.kt")
public void testPropagateFlexibleTypeToAnonymousFunction2() throws Exception {
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/wholeDeclaration/propagateFlexibleTypeToAnonymousFunction2.kt");
}
@Test
@TestMetadata("secondaryConstructorValueParameter.kt")
public void testSecondaryConstructorValueParameter() throws Exception {
@@ -1159,6 +1159,18 @@ public class SourceGetOrBuildFirTestGenerated extends AbstractSourceGetOrBuildFi
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/wholeDeclaration/primaryConstructorValueParameter.kt");
}
@Test
@TestMetadata("propagateFlexibleTypeToAnonymousFunction.kt")
public void testPropagateFlexibleTypeToAnonymousFunction() throws Exception {
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/wholeDeclaration/propagateFlexibleTypeToAnonymousFunction.kt");
}
@Test
@TestMetadata("propagateFlexibleTypeToAnonymousFunction2.kt")
public void testPropagateFlexibleTypeToAnonymousFunction2() throws Exception {
runTest("analysis/low-level-api-fir/testdata/getOrBuildFir/wholeDeclaration/propagateFlexibleTypeToAnonymousFunction2.kt");
}
@Test
@TestMetadata("secondaryConstructorValueParameter.kt")
public void testSecondaryConstructorValueParameter() throws Exception {
@@ -20258,6 +20258,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/j+k/privatePropertyAndSetterMultiModule.kt");
}
@Test
@TestMetadata("propagateFlexibleTypeToAnonymousFunction.kt")
public void testPropagateFlexibleTypeToAnonymousFunction() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/propagateFlexibleTypeToAnonymousFunction.kt");
}
@Test
@TestMetadata("protectedStaticSamePackage.kt")
public void testProtectedStaticSamePackage() throws Exception {
@@ -20258,6 +20258,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/j+k/privatePropertyAndSetterMultiModule.kt");
}
@Test
@TestMetadata("propagateFlexibleTypeToAnonymousFunction.kt")
public void testPropagateFlexibleTypeToAnonymousFunction() throws Exception {
runTest("compiler/testData/diagnostics/tests/j+k/propagateFlexibleTypeToAnonymousFunction.kt");
}
@Test
@TestMetadata("protectedStaticSamePackage.kt")
public void testProtectedStaticSamePackage() throws Exception {