Add test with false/true positives for KT-24643
This commit is contained in:
+6
@@ -8336,6 +8336,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
|||||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/useTypeParameterOfExtensionProperty.kt");
|
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
|
@Test
|
||||||
@TestMetadata("useTypeParameterOfExtensionProperty_Disabled.kt")
|
@TestMetadata("useTypeParameterOfExtensionProperty_Disabled.kt")
|
||||||
public void testUseTypeParameterOfExtensionProperty_Disabled() throws Exception {
|
public void testUseTypeParameterOfExtensionProperty_Disabled() throws Exception {
|
||||||
|
|||||||
+6
@@ -8336,6 +8336,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
|||||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/useTypeParameterOfExtensionProperty.kt");
|
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
|
@Test
|
||||||
@TestMetadata("useTypeParameterOfExtensionProperty_Disabled.kt")
|
@TestMetadata("useTypeParameterOfExtensionProperty_Disabled.kt")
|
||||||
public void testUseTypeParameterOfExtensionProperty_Disabled() throws Exception {
|
public void testUseTypeParameterOfExtensionProperty_Disabled() throws Exception {
|
||||||
|
|||||||
+6
@@ -8336,6 +8336,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
|||||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/useTypeParameterOfExtensionProperty.kt");
|
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
|
@Test
|
||||||
@TestMetadata("useTypeParameterOfExtensionProperty_Disabled.kt")
|
@TestMetadata("useTypeParameterOfExtensionProperty_Disabled.kt")
|
||||||
public void testUseTypeParameterOfExtensionProperty_Disabled() throws Exception {
|
public void testUseTypeParameterOfExtensionProperty_Disabled() throws Exception {
|
||||||
|
|||||||
Vendored
+30
@@ -0,0 +1,30 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
|
// !LANGUAGE: +ForbidUsingExtensionPropertyTypeParameterInDelegate
|
||||||
|
// WITH_REFLECT
|
||||||
|
|
||||||
|
import kotlin.reflect.KProperty
|
||||||
|
import kotlin.properties.ReadOnlyProperty
|
||||||
|
|
||||||
|
fun <T, V> logged(getter: (T) -> V) =
|
||||||
|
ReadOnlyProperty<T, V> { thisRef, property ->
|
||||||
|
println("Getter for $property is invoked")
|
||||||
|
getter(thisRef)
|
||||||
|
}
|
||||||
|
|
||||||
|
val <T> List<T>.second: T <!DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER_ERROR!>by logged { it[1] }<!>
|
||||||
|
|
||||||
|
class Delegate<T>(private val fn: (List<T>) -> T) {
|
||||||
|
private var cache: T? = null
|
||||||
|
|
||||||
|
operator fun getValue(thisRef: List<T>, kProperty: KProperty<*>) =
|
||||||
|
cache ?: fn(thisRef).also { cache = it }
|
||||||
|
}
|
||||||
|
|
||||||
|
val <T> List<T>.leakingT: T <!DELEGATE_USES_EXTENSION_PROPERTY_TYPE_PARAMETER_ERROR!>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]!
|
||||||
|
}
|
||||||
Vendored
+16
@@ -0,0 +1,16 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public val </*0*/ T> kotlin.collections.List<T>.leakingT: T
|
||||||
|
public val </*0*/ T> kotlin.collections.List<T>.second: T
|
||||||
|
public fun </*0*/ T, /*1*/ V> logged(/*0*/ getter: (T) -> V): kotlin.properties.ReadOnlyProperty<T, V>
|
||||||
|
public fun main(): kotlin.Unit
|
||||||
|
|
||||||
|
public final class Delegate</*0*/ T> {
|
||||||
|
public constructor Delegate</*0*/ T>(/*0*/ fn: (kotlin.collections.List<T>) -> T)
|
||||||
|
private final var cache: T?
|
||||||
|
private final val fn: (kotlin.collections.List<T>) -> 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<T>, /*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
|
||||||
|
}
|
||||||
Generated
+6
@@ -8342,6 +8342,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/delegatedProperty/useTypeParameterOfExtensionProperty.kt");
|
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
|
@Test
|
||||||
@TestMetadata("useTypeParameterOfExtensionProperty_Disabled.kt")
|
@TestMetadata("useTypeParameterOfExtensionProperty_Disabled.kt")
|
||||||
public void testUseTypeParameterOfExtensionProperty_Disabled() throws Exception {
|
public void testUseTypeParameterOfExtensionProperty_Disabled() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user