diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java index 855dc7949b6..b3e68f01d65 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosisCompilerTestFE10TestdataTestGenerated.java @@ -8336,6 +8336,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag runTest("compiler/testData/diagnostics/tests/delegatedProperty/useTypeParameterOfExtensionProperty.kt"); } + @Test + @TestMetadata("useTypeParameterOfExtensionProperty2.kt") + public void testUseTypeParameterOfExtensionProperty2() throws Exception { + runTest("compiler/testData/diagnostics/tests/delegatedProperty/useTypeParameterOfExtensionProperty2.kt"); + } + @Test @TestMetadata("useTypeParameterOfExtensionProperty_Disabled.kt") public void testUseTypeParameterOfExtensionProperty_Disabled() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index 51ec7fe0789..e0ccedaa0a6 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -8336,6 +8336,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/delegatedProperty/useTypeParameterOfExtensionProperty.kt"); } + @Test + @TestMetadata("useTypeParameterOfExtensionProperty2.kt") + public void testUseTypeParameterOfExtensionProperty2() throws Exception { + runTest("compiler/testData/diagnostics/tests/delegatedProperty/useTypeParameterOfExtensionProperty2.kt"); + } + @Test @TestMetadata("useTypeParameterOfExtensionProperty_Disabled.kt") public void testUseTypeParameterOfExtensionProperty_Disabled() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java index e5638449203..8c559386300 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsWithLightTreeTestGenerated.java @@ -8336,6 +8336,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/delegatedProperty/useTypeParameterOfExtensionProperty.kt"); } + @Test + @TestMetadata("useTypeParameterOfExtensionProperty2.kt") + public void testUseTypeParameterOfExtensionProperty2() throws Exception { + runTest("compiler/testData/diagnostics/tests/delegatedProperty/useTypeParameterOfExtensionProperty2.kt"); + } + @Test @TestMetadata("useTypeParameterOfExtensionProperty_Disabled.kt") public void testUseTypeParameterOfExtensionProperty_Disabled() throws Exception { diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/useTypeParameterOfExtensionProperty2.kt b/compiler/testData/diagnostics/tests/delegatedProperty/useTypeParameterOfExtensionProperty2.kt new file mode 100644 index 00000000000..c10c93be560 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/useTypeParameterOfExtensionProperty2.kt @@ -0,0 +1,30 @@ +// FIR_IDENTICAL +// !LANGUAGE: +ForbidUsingExtensionPropertyTypeParameterInDelegate +// WITH_REFLECT + +import kotlin.reflect.KProperty +import kotlin.properties.ReadOnlyProperty + +fun logged(getter: (T) -> V) = + ReadOnlyProperty { thisRef, property -> + println("Getter for $property is invoked") + getter(thisRef) + } + +val List.second: T by logged { it[1] } + +class Delegate(private val fn: (List) -> T) { + private var cache: T? = null + + operator fun getValue(thisRef: List, kProperty: KProperty<*>) = + cache ?: fn(thisRef).also { cache = it } +} + +val List.leakingT: T by Delegate { it[0] } + +fun main() { + println(listOf("xx", "yy", "zz").leakingT) + val a = arrayListOf(1, 2, 3) + a.add(a.leakingT) + println(a) // [1, 2, 3, xx]! +} diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/useTypeParameterOfExtensionProperty2.txt b/compiler/testData/diagnostics/tests/delegatedProperty/useTypeParameterOfExtensionProperty2.txt new file mode 100644 index 00000000000..6fa461f3095 --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegatedProperty/useTypeParameterOfExtensionProperty2.txt @@ -0,0 +1,16 @@ +package + +public val kotlin.collections.List.leakingT: T +public val kotlin.collections.List.second: T +public fun logged(/*0*/ getter: (T) -> V): kotlin.properties.ReadOnlyProperty +public fun main(): kotlin.Unit + +public final class Delegate { + public constructor Delegate(/*0*/ fn: (kotlin.collections.List) -> T) + private final var cache: T? + private final val fn: (kotlin.collections.List) -> T + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final operator fun getValue(/*0*/ thisRef: kotlin.collections.List, /*1*/ kProperty: kotlin.reflect.KProperty<*>): T + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index d0b36ab907e..3f6283b45c3 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -8342,6 +8342,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/delegatedProperty/useTypeParameterOfExtensionProperty.kt"); } + @Test + @TestMetadata("useTypeParameterOfExtensionProperty2.kt") + public void testUseTypeParameterOfExtensionProperty2() throws Exception { + runTest("compiler/testData/diagnostics/tests/delegatedProperty/useTypeParameterOfExtensionProperty2.kt"); + } + @Test @TestMetadata("useTypeParameterOfExtensionProperty_Disabled.kt") public void testUseTypeParameterOfExtensionProperty_Disabled() throws Exception {