[tests] Add additional test data for KT-64222

This commit is contained in:
Stanislav Ruban
2024-01-25 21:23:27 +02:00
committed by Space Team
parent b87aa470dd
commit 9fb920874c
11 changed files with 576 additions and 0 deletions
@@ -3862,6 +3862,34 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia
runTest("compiler/testData/diagnostics/tests/builderInference/overloadResolutionByLambdaReturnType.kt");
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/builderInference/additional")
@TestDataPath("$PROJECT_ROOT")
public class Additional {
@Test
public void testAllFilesPresentInAdditional() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/builderInference/additional"), Pattern.compile("^(.+)\\.(kt|kts)$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
}
@Test
@TestMetadata("BuildeeSupertypeAsTypeVariableSourceInClassifiers.kt")
public void testBuildeeSupertypeAsTypeVariableSourceInClassifiers() throws Exception {
runTest("compiler/testData/diagnostics/tests/builderInference/additional/BuildeeSupertypeAsTypeVariableSourceInClassifiers.kt");
}
@Test
@TestMetadata("BuildeeSupertypeAsTypeVariableSourceInFunctions.kt")
public void testBuildeeSupertypeAsTypeVariableSourceInFunctions() throws Exception {
runTest("compiler/testData/diagnostics/tests/builderInference/additional/BuildeeSupertypeAsTypeVariableSourceInFunctions.kt");
}
@Test
@TestMetadata("BuildeeSupertypeAsTypeVariableSourceInProperties.kt")
public void testBuildeeSupertypeAsTypeVariableSourceInProperties() throws Exception {
runTest("compiler/testData/diagnostics/tests/builderInference/additional/BuildeeSupertypeAsTypeVariableSourceInProperties.kt");
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/builderInference/issues")
@TestDataPath("$PROJECT_ROOT")
@@ -3862,6 +3862,34 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated
runTest("compiler/testData/diagnostics/tests/builderInference/overloadResolutionByLambdaReturnType.kt");
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/builderInference/additional")
@TestDataPath("$PROJECT_ROOT")
public class Additional {
@Test
public void testAllFilesPresentInAdditional() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/builderInference/additional"), Pattern.compile("^(.+)\\.(kt|kts)$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
}
@Test
@TestMetadata("BuildeeSupertypeAsTypeVariableSourceInClassifiers.kt")
public void testBuildeeSupertypeAsTypeVariableSourceInClassifiers() throws Exception {
runTest("compiler/testData/diagnostics/tests/builderInference/additional/BuildeeSupertypeAsTypeVariableSourceInClassifiers.kt");
}
@Test
@TestMetadata("BuildeeSupertypeAsTypeVariableSourceInFunctions.kt")
public void testBuildeeSupertypeAsTypeVariableSourceInFunctions() throws Exception {
runTest("compiler/testData/diagnostics/tests/builderInference/additional/BuildeeSupertypeAsTypeVariableSourceInFunctions.kt");
}
@Test
@TestMetadata("BuildeeSupertypeAsTypeVariableSourceInProperties.kt")
public void testBuildeeSupertypeAsTypeVariableSourceInProperties() throws Exception {
runTest("compiler/testData/diagnostics/tests/builderInference/additional/BuildeeSupertypeAsTypeVariableSourceInProperties.kt");
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/builderInference/issues")
@TestDataPath("$PROJECT_ROOT")
@@ -3856,6 +3856,34 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir
runTest("compiler/testData/diagnostics/tests/builderInference/overloadResolutionByLambdaReturnType.kt");
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/builderInference/additional")
@TestDataPath("$PROJECT_ROOT")
public class Additional {
@Test
public void testAllFilesPresentInAdditional() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/builderInference/additional"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "multiplatform");
}
@Test
@TestMetadata("BuildeeSupertypeAsTypeVariableSourceInClassifiers.kt")
public void testBuildeeSupertypeAsTypeVariableSourceInClassifiers() throws Exception {
runTest("compiler/testData/diagnostics/tests/builderInference/additional/BuildeeSupertypeAsTypeVariableSourceInClassifiers.kt");
}
@Test
@TestMetadata("BuildeeSupertypeAsTypeVariableSourceInFunctions.kt")
public void testBuildeeSupertypeAsTypeVariableSourceInFunctions() throws Exception {
runTest("compiler/testData/diagnostics/tests/builderInference/additional/BuildeeSupertypeAsTypeVariableSourceInFunctions.kt");
}
@Test
@TestMetadata("BuildeeSupertypeAsTypeVariableSourceInProperties.kt")
public void testBuildeeSupertypeAsTypeVariableSourceInProperties() throws Exception {
runTest("compiler/testData/diagnostics/tests/builderInference/additional/BuildeeSupertypeAsTypeVariableSourceInProperties.kt");
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/builderInference/issues")
@TestDataPath("$PROJECT_ROOT")
@@ -3862,6 +3862,34 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia
runTest("compiler/testData/diagnostics/tests/builderInference/overloadResolutionByLambdaReturnType.kt");
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/builderInference/additional")
@TestDataPath("$PROJECT_ROOT")
public class Additional {
@Test
public void testAllFilesPresentInAdditional() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/builderInference/additional"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true, "multiplatform");
}
@Test
@TestMetadata("BuildeeSupertypeAsTypeVariableSourceInClassifiers.kt")
public void testBuildeeSupertypeAsTypeVariableSourceInClassifiers() throws Exception {
runTest("compiler/testData/diagnostics/tests/builderInference/additional/BuildeeSupertypeAsTypeVariableSourceInClassifiers.kt");
}
@Test
@TestMetadata("BuildeeSupertypeAsTypeVariableSourceInFunctions.kt")
public void testBuildeeSupertypeAsTypeVariableSourceInFunctions() throws Exception {
runTest("compiler/testData/diagnostics/tests/builderInference/additional/BuildeeSupertypeAsTypeVariableSourceInFunctions.kt");
}
@Test
@TestMetadata("BuildeeSupertypeAsTypeVariableSourceInProperties.kt")
public void testBuildeeSupertypeAsTypeVariableSourceInProperties() throws Exception {
runTest("compiler/testData/diagnostics/tests/builderInference/additional/BuildeeSupertypeAsTypeVariableSourceInProperties.kt");
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/builderInference/issues")
@TestDataPath("$PROJECT_ROOT")
@@ -0,0 +1,48 @@
fun test() {
// a primary constructor call
build {
KlassA(this)
}
// a secondary constructor call
build {
KlassB(this)
}
// delegation to a super-constructor from a primary constructor
build {
class KlassC constructor(): BaseKlassC(this@build)
}
// delegation to a super-constructor from a secondary constructor
build {
class KlassD: BaseKlassD {
constructor() : super(this@build)
}
}
// inheritance via delegation
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>build<!> {
class KlassE: BaseBuildee<TargetType> by this@build
}
}
interface BaseBuildee<BBTV>
class DerivedBuildee<DBTV>: BaseBuildee<DBTV>
fun <FTV> build(instructions: DerivedBuildee<FTV>.() -> Unit): DerivedBuildee<FTV> {
return DerivedBuildee<FTV>().apply(instructions)
}
class TargetType
class KlassA constructor(base: BaseBuildee<TargetType>)
class KlassB {
constructor(base: BaseBuildee<TargetType>)
}
open class BaseKlassC(base: BaseBuildee<TargetType>)
open class BaseKlassD(base: BaseBuildee<TargetType>)
@@ -0,0 +1,48 @@
fun test() {
// a primary constructor call
build {
KlassA(this)
}
// a secondary constructor call
build {
KlassB(this)
}
// delegation to a super-constructor from a primary constructor
build {
class KlassC constructor(): BaseKlassC(this@build)
}
// delegation to a super-constructor from a secondary constructor
build {
class KlassD: BaseKlassD {
constructor() : super(this@build)
}
}
// inheritance via delegation
build {
class KlassE: BaseBuildee<TargetType> by this@build
}
}
interface BaseBuildee<BBTV>
class DerivedBuildee<DBTV>: BaseBuildee<DBTV>
fun <FTV> build(instructions: DerivedBuildee<FTV>.() -> Unit): DerivedBuildee<FTV> {
return DerivedBuildee<FTV>().apply(instructions)
}
class TargetType
class KlassA constructor(base: BaseBuildee<TargetType>)
class KlassB {
constructor(base: BaseBuildee<TargetType>)
}
open class BaseKlassC(base: BaseBuildee<TargetType>)
open class BaseKlassD(base: BaseBuildee<TargetType>)
@@ -0,0 +1,60 @@
fun test() {
// simple function call
build {
consumeA(this)
}
// function call with a named argument
build {
consumeB(base = this)
}
// local function definition with a default parameter value
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>build<!> {
fun consumeC(base: BaseBuildee<TargetType> = this) {}
}
// local function definition with a return type and a block body
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>build<!> {
fun consumeD(): BaseBuildee<TargetType> { return this }
}
// local function definition with a return type and an expression body
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>build<!> {
fun consumeE(): BaseBuildee<TargetType> = this
}
// call of a function with a vararg parameter
build {
consumeF(this, this)
}
// call of an extension function
build {
this.consumeG()
}
// call of an infix function
build {
this consumeH this
}
}
open class BaseBuildee<BBTV>
class DerivedBuildee<DBTV>: BaseBuildee<DBTV>()
fun <FTV> build(instructions: DerivedBuildee<FTV>.() -> Unit): DerivedBuildee<FTV> {
return DerivedBuildee<FTV>().apply(instructions)
}
class TargetType
fun consumeA(base: BaseBuildee<TargetType>) {}
fun consumeB(base: BaseBuildee<TargetType>) {}
fun consumeF(vararg bases: BaseBuildee<TargetType>) {}
fun BaseBuildee<TargetType>.consumeG() {}
infix fun BaseBuildee<TargetType>.consumeH(base: BaseBuildee<TargetType>) {}
@@ -0,0 +1,60 @@
fun test() {
// simple function call
build {
consumeA(this)
}
// function call with a named argument
build {
consumeB(base = this)
}
// local function definition with a default parameter value
build {
fun consumeC(base: BaseBuildee<TargetType> = this) {}
}
// local function definition with a return type and a block body
build {
fun consumeD(): BaseBuildee<TargetType> { return this }
}
// local function definition with a return type and an expression body
build {
fun consumeE(): BaseBuildee<TargetType> = this
}
// call of a function with a vararg parameter
build {
consumeF(this, this)
}
// call of an extension function
build {
this.consumeG()
}
// call of an infix function
build {
this consumeH this
}
}
open class BaseBuildee<BBTV>
class DerivedBuildee<DBTV>: BaseBuildee<DBTV>()
fun <FTV> build(instructions: DerivedBuildee<FTV>.() -> Unit): DerivedBuildee<FTV> {
return DerivedBuildee<FTV>().apply(instructions)
}
class TargetType
fun consumeA(base: BaseBuildee<TargetType>) {}
fun consumeB(base: BaseBuildee<TargetType>) {}
fun consumeF(vararg bases: BaseBuildee<TargetType>) {}
fun BaseBuildee<TargetType>.consumeG() {}
infix fun BaseBuildee<TargetType>.consumeH(base: BaseBuildee<TargetType>) {}
@@ -0,0 +1,110 @@
// WITH_REFLECT
// DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE
import kotlin.reflect.KProperty
fun test() {
// initialization of an immutable local value
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>build<!> {
val baseA: BaseBuildee<TargetType> = this
}
// assignment to a mutable local variable
build {
var baseB = BaseBuildee<TargetType>()
baseB = this
}
// a destructuring declaration
build {
val (_: BaseBuildee<TargetType>, _: BaseBuildee<TargetType>) = this to this
}
// body of a getter of an immutable property
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>build<!> {
class LocalWrapper {
val baseC: BaseBuildee<TargetType>
get() = this@build
}
}
// initialization of a mutable property's backing field
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>build<!> {
class LocalWrapper {
var baseD: BaseBuildee<TargetType> = this@build
set(value) {
field = BaseBuildee()
}
}
}
// body of a setter of a mutable property
build {
class LocalWrapper {
var baseE: BaseBuildee<TargetType> = BaseBuildee()
set(value) {
field = this@build
}
}
}
// assignment via a mutable property's setter
build {
baseF = this
}
// declaration of a property delegated via getValue/setValue
build {
val baseG: BaseBuildee<TargetType> by Delegate(this)
}
// assignment to a property delegated via getValue/setValue
build {
baseH = this
}
// declaration of a property delegated via provideDelegate
build {
val baseI: BaseBuildee<TargetType> by DelegateProvider(this)
}
// assignment to a property delegated via provideDelegate
build {
baseJ = this
}
// an extension property
build {
this.baseK
}
}
open class BaseBuildee<BBTV>
class DerivedBuildee<DBTV>: BaseBuildee<DBTV>()
fun <FTV> build(instructions: DerivedBuildee<FTV>.() -> Unit): DerivedBuildee<FTV> {
return DerivedBuildee<FTV>().apply(instructions)
}
class TargetType
var baseF
get() = BaseBuildee<TargetType>()
set(value) {}
class Delegate<T>(private var arg: T) {
operator fun getValue(thisRef: Any?, property: KProperty<*>): T = arg
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
arg = value
}
}
var baseH by Delegate(BaseBuildee<TargetType>())
class DelegateProvider<T>(private val arg: T) {
operator fun provideDelegate(thisRef: Any?, property: KProperty<*>): Delegate<T> = Delegate(arg)
}
var baseJ by DelegateProvider(BaseBuildee<TargetType>())
val BaseBuildee<TargetType>.baseK get() = this
@@ -0,0 +1,110 @@
// WITH_REFLECT
// DIAGNOSTICS: -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE
import kotlin.reflect.KProperty
fun test() {
// initialization of an immutable local value
build {
val baseA: BaseBuildee<TargetType> = this
}
// assignment to a mutable local variable
build {
var baseB = BaseBuildee<TargetType>()
baseB = this
}
// a destructuring declaration
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>build<!> {
val (_: BaseBuildee<TargetType>, _: BaseBuildee<TargetType>) = this to this
}
// body of a getter of an immutable property
build {
class LocalWrapper {
val baseC: BaseBuildee<TargetType>
get() = this@build
}
}
// initialization of a mutable property's backing field
build {
class LocalWrapper {
var baseD: BaseBuildee<TargetType> = this@build
set(value) {
field = BaseBuildee()
}
}
}
// body of a setter of a mutable property
build {
class LocalWrapper {
var baseE: BaseBuildee<TargetType> = BaseBuildee()
set(value) {
field = this@build
}
}
}
// assignment via a mutable property's setter
build {
baseF = this
}
// declaration of a property delegated via getValue/setValue
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>build<!> {
val baseG: BaseBuildee<TargetType> by Delegate(this)
}
// assignment to a property delegated via getValue/setValue
build {
baseH = this
}
// declaration of a property delegated via provideDelegate
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>build<!> {
val baseI: BaseBuildee<TargetType> by DelegateProvider(this)
}
// assignment to a property delegated via provideDelegate
build {
baseJ = this
}
// an extension property
build {
this.baseK
}
}
open class BaseBuildee<BBTV>
class DerivedBuildee<DBTV>: BaseBuildee<DBTV>()
fun <FTV> build(instructions: DerivedBuildee<FTV>.() -> Unit): DerivedBuildee<FTV> {
return DerivedBuildee<FTV>().apply(instructions)
}
class TargetType
var baseF
get() = BaseBuildee<TargetType>()
set(value) {}
class Delegate<T>(private var arg: T) {
operator fun getValue(thisRef: Any?, property: KProperty<*>): T = arg
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
arg = value
}
}
var baseH by Delegate(BaseBuildee<TargetType>())
class DelegateProvider<T>(private val arg: T) {
operator fun provideDelegate(thisRef: Any?, property: KProperty<*>): Delegate<T> = Delegate(arg)
}
var baseJ by DelegateProvider(BaseBuildee<TargetType>())
val BaseBuildee<TargetType>.baseK get() = this
@@ -3862,6 +3862,34 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/builderInference/overloadResolutionByLambdaReturnType.kt");
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/builderInference/additional")
@TestDataPath("$PROJECT_ROOT")
public class Additional {
@Test
public void testAllFilesPresentInAdditional() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/builderInference/additional"), Pattern.compile("^(.*)\\.kts?$"), Pattern.compile("^(.+)\\.(reversed|fir|ll)\\.kts?$"), true);
}
@Test
@TestMetadata("BuildeeSupertypeAsTypeVariableSourceInClassifiers.kt")
public void testBuildeeSupertypeAsTypeVariableSourceInClassifiers() throws Exception {
runTest("compiler/testData/diagnostics/tests/builderInference/additional/BuildeeSupertypeAsTypeVariableSourceInClassifiers.kt");
}
@Test
@TestMetadata("BuildeeSupertypeAsTypeVariableSourceInFunctions.kt")
public void testBuildeeSupertypeAsTypeVariableSourceInFunctions() throws Exception {
runTest("compiler/testData/diagnostics/tests/builderInference/additional/BuildeeSupertypeAsTypeVariableSourceInFunctions.kt");
}
@Test
@TestMetadata("BuildeeSupertypeAsTypeVariableSourceInProperties.kt")
public void testBuildeeSupertypeAsTypeVariableSourceInProperties() throws Exception {
runTest("compiler/testData/diagnostics/tests/builderInference/additional/BuildeeSupertypeAsTypeVariableSourceInProperties.kt");
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/builderInference/issues")
@TestDataPath("$PROJECT_ROOT")