From 0b37b2be6af85ee1046597ec04084347aaf4c76d Mon Sep 17 00:00:00 2001 From: Victor Petukhov Date: Tue, 11 May 2021 17:17:49 +0300 Subject: [PATCH] Add addtional tests for builder inference --- ...irOldFrontendDiagnosticsTestGenerated.java | 78 +++++++++++------ ...DiagnosticsWithLightTreeTestGenerated.java | 78 +++++++++++------ .../constraints/violating.fir.kt | 33 ++++++++ .../builderInference/constraints/violating.kt | 33 ++++++++ .../constraints/violating.txt | 11 +++ .../constraints/withExpectedType.fir.kt | 84 +++++++++++++------ .../constraints/withExpectedType.kt | 32 +------ .../constraints/withExpectedType.txt | 7 +- .../specialCallsWithCallableReferences.fir.kt | 40 ++++----- .../specialCallsWithCallableReferences.kt | 20 ++--- .../stubTypes/capturedTypes.fir.kt | 3 +- .../stubTypes/capturedTypes.kt | 3 +- .../stubTypes/commonSuperType.fir.kt | 1 + .../stubTypes/commonSuperType.kt | 1 + .../commonSuperTypeContravariant.fir.kt | 1 + .../stubTypes/commonSuperTypeContravariant.kt | 1 + .../stubTypes/commonSuperTypeCovariant.fir.kt | 1 + .../stubTypes/commonSuperTypeCovariant.kt | 1 + .../stubTypes/commonSuperTypeInvariant.fir.kt | 1 + .../stubTypes/commonSuperTypeInvariant.kt | 1 + .../stubTypes/commonSuperTypeNullable.fir.kt | 1 + .../stubTypes/commonSuperTypeNullable.kt | 1 + .../stubTypes/intersect.fir.kt | 1 + .../builderInference/stubTypes/intersect.kt | 1 + .../stubTypes/memberScope.fir.kt | 73 ++++++++++++++++ .../builderInference/stubTypes/memberScope.kt | 73 ++++++++++++++++ .../stubTypes/memberScope.txt | 14 ++++ .../stubTypes/nullability.fir.kt | 62 ++++++++++++++ .../builderInference/stubTypes/nullability.kt | 62 ++++++++++++++ .../stubTypes/nullability.txt | 15 ++++ .../stubTypes/renderingStubTypes.fir.kt | 1 + .../stubTypes/renderingStubTypes.kt | 1 + .../builderInference/incorrectCalls.fir.kt | 37 ++++++++ .../incorrectCalls.kt | 1 + .../incorrectCalls.txt | 0 .../incorrectCallsWithRestrictions.fir.kt} | 0 .../incorrectCallsWithRestrictions.kt | 36 ++++++++ .../incorrectCallsWithRestrictions.txt | 24 ++++++ .../inferCoroutineTypeInOldVersion.fir.kt | 2 +- .../inferCoroutineTypeInOldVersion.kt | 6 +- .../inferCoroutineTypeInOldVersion.txt | 12 ++- ...esolveUsualCallWithBuilderInference.fir.kt | 1 + .../resolveUsualCallWithBuilderInference.kt | 1 + .../resolveUsualCallWithBuilderInference.txt | 0 ...ithBuilderInferenceWithRestrictions.fir.kt | 37 ++++++++ ...allWithBuilderInferenceWithRestrictions.kt | 37 ++++++++ ...llWithBuilderInferenceWithRestrictions.txt | 32 +++++++ ...seInferenceInformationFromExtension.fir.kt | 34 ++++++++ .../useInferenceInformationFromExtension.kt | 1 + .../useInferenceInformationFromExtension.txt | 0 ...ationFromExtensionWithRestrictions.fir.kt} | 0 ...nformationFromExtensionWithRestrictions.kt | 33 ++++++++ ...formationFromExtensionWithRestrictions.txt | 28 +++++++ .../test/runners/DiagnosticTestGenerated.java | 78 +++++++++++------ 54 files changed, 962 insertions(+), 173 deletions(-) create mode 100644 compiler/testData/diagnostics/tests/inference/builderInference/constraints/violating.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/builderInference/constraints/violating.txt create mode 100644 compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.kt create mode 100644 compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.txt create mode 100644 compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/nullability.fir.kt create mode 100644 compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/nullability.kt create mode 100644 compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/nullability.txt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCalls.fir.kt rename compiler/testData/diagnostics/testsWithStdLib/{coroutines/inference => builderInference}/incorrectCalls.kt (95%) rename compiler/testData/diagnostics/testsWithStdLib/{coroutines/inference => builderInference}/incorrectCalls.txt (100%) rename compiler/testData/diagnostics/testsWithStdLib/{coroutines/inference/incorrectCalls.fir.kt => builderInference/incorrectCallsWithRestrictions.fir.kt} (100%) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCallsWithRestrictions.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCallsWithRestrictions.txt rename compiler/testData/diagnostics/testsWithStdLib/{coroutines/inference => builderInference}/inferCoroutineTypeInOldVersion.fir.kt (93%) rename compiler/testData/diagnostics/testsWithStdLib/{coroutines/inference => builderInference}/inferCoroutineTypeInOldVersion.kt (76%) rename compiler/testData/diagnostics/testsWithStdLib/{coroutines/inference => builderInference}/inferCoroutineTypeInOldVersion.txt (79%) rename compiler/testData/diagnostics/testsWithStdLib/{coroutines/inference => builderInference}/resolveUsualCallWithBuilderInference.fir.kt (94%) rename compiler/testData/diagnostics/testsWithStdLib/{coroutines/inference => builderInference}/resolveUsualCallWithBuilderInference.kt (94%) rename compiler/testData/diagnostics/testsWithStdLib/{coroutines/inference => builderInference}/resolveUsualCallWithBuilderInference.txt (100%) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInferenceWithRestrictions.fir.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInferenceWithRestrictions.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInferenceWithRestrictions.txt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtension.fir.kt rename compiler/testData/diagnostics/testsWithStdLib/{coroutines/inference => builderInference}/useInferenceInformationFromExtension.kt (94%) rename compiler/testData/diagnostics/testsWithStdLib/{coroutines/inference => builderInference}/useInferenceInformationFromExtension.txt (100%) rename compiler/testData/diagnostics/testsWithStdLib/{coroutines/inference/useInferenceInformationFromExtension.fir.kt => builderInference/useInferenceInformationFromExtensionWithRestrictions.fir.kt} (100%) create mode 100644 compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtensionWithRestrictions.kt create mode 100644 compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtensionWithRestrictions.txt 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 be4e19c01f3..250878d0c82 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 @@ -12765,6 +12765,18 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/intersect.kt"); } + @Test + @TestMetadata("memberScope.kt") + public void testMemberScope() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.kt"); + } + + @Test + @TestMetadata("nullability.kt") + public void testNullability() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/nullability.kt"); + } + @Test @TestMetadata("renderingStubTypes.kt") public void testRenderingStubTypes() throws Exception { @@ -32322,6 +32334,48 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti public void testCompleteIrrelevantCalls() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/completeIrrelevantCalls.kt"); } + + @Test + @TestMetadata("incorrectCalls.kt") + public void testIncorrectCalls() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCalls.kt"); + } + + @Test + @TestMetadata("incorrectCallsWithRestrictions.kt") + public void testIncorrectCallsWithRestrictions() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCallsWithRestrictions.kt"); + } + + @Test + @TestMetadata("inferCoroutineTypeInOldVersion.kt") + public void testInferCoroutineTypeInOldVersion() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inferCoroutineTypeInOldVersion.kt"); + } + + @Test + @TestMetadata("resolveUsualCallWithBuilderInference.kt") + public void testResolveUsualCallWithBuilderInference() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInference.kt"); + } + + @Test + @TestMetadata("resolveUsualCallWithBuilderInferenceWithRestrictions.kt") + public void testResolveUsualCallWithBuilderInferenceWithRestrictions() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInferenceWithRestrictions.kt"); + } + + @Test + @TestMetadata("useInferenceInformationFromExtension.kt") + public void testUseInferenceInformationFromExtension() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtension.kt"); + } + + @Test + @TestMetadata("useInferenceInformationFromExtensionWithRestrictions.kt") + public void testUseInferenceInformationFromExtensionWithRestrictions() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtensionWithRestrictions.kt"); + } } @Nested @@ -33512,18 +33566,6 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionsWithNonValuableConstraints_1_2.kt"); } - @Test - @TestMetadata("incorrectCalls.kt") - public void testIncorrectCalls() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/incorrectCalls.kt"); - } - - @Test - @TestMetadata("inferCoroutineTypeInOldVersion.kt") - public void testInferCoroutineTypeInOldVersion() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/inferCoroutineTypeInOldVersion.kt"); - } - @Test @TestMetadata("inferenceFromMethodInsideLocalVariable.kt") public void testInferenceFromMethodInsideLocalVariable() throws Exception { @@ -33668,12 +33710,6 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/recursiveGenerators2.kt"); } - @Test - @TestMetadata("resolveUsualCallWithBuilderInference.kt") - public void testResolveUsualCallWithBuilderInference() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/resolveUsualCallWithBuilderInference.kt"); - } - @Test @TestMetadata("returnTypeInference.kt") public void testReturnTypeInference() throws Exception { @@ -33722,12 +33758,6 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/typeFromReceiver.kt"); } - @Test - @TestMetadata("useInferenceInformationFromExtension.kt") - public void testUseInferenceInformationFromExtension() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/useInferenceInformationFromExtension.kt"); - } - @Test @TestMetadata("variableCallInsideBuilderFunction.kt") public void testVariableCallInsideBuilderFunction() 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 5acf8f7f5ad..682b3cb20e8 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 @@ -12765,6 +12765,18 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/intersect.kt"); } + @Test + @TestMetadata("memberScope.kt") + public void testMemberScope() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.kt"); + } + + @Test + @TestMetadata("nullability.kt") + public void testNullability() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/nullability.kt"); + } + @Test @TestMetadata("renderingStubTypes.kt") public void testRenderingStubTypes() throws Exception { @@ -32322,6 +32334,48 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac public void testCompleteIrrelevantCalls() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/completeIrrelevantCalls.kt"); } + + @Test + @TestMetadata("incorrectCalls.kt") + public void testIncorrectCalls() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCalls.kt"); + } + + @Test + @TestMetadata("incorrectCallsWithRestrictions.kt") + public void testIncorrectCallsWithRestrictions() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCallsWithRestrictions.kt"); + } + + @Test + @TestMetadata("inferCoroutineTypeInOldVersion.kt") + public void testInferCoroutineTypeInOldVersion() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inferCoroutineTypeInOldVersion.kt"); + } + + @Test + @TestMetadata("resolveUsualCallWithBuilderInference.kt") + public void testResolveUsualCallWithBuilderInference() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInference.kt"); + } + + @Test + @TestMetadata("resolveUsualCallWithBuilderInferenceWithRestrictions.kt") + public void testResolveUsualCallWithBuilderInferenceWithRestrictions() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInferenceWithRestrictions.kt"); + } + + @Test + @TestMetadata("useInferenceInformationFromExtension.kt") + public void testUseInferenceInformationFromExtension() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtension.kt"); + } + + @Test + @TestMetadata("useInferenceInformationFromExtensionWithRestrictions.kt") + public void testUseInferenceInformationFromExtensionWithRestrictions() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtensionWithRestrictions.kt"); + } } @Nested @@ -33512,18 +33566,6 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionsWithNonValuableConstraints_1_2.kt"); } - @Test - @TestMetadata("incorrectCalls.kt") - public void testIncorrectCalls() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/incorrectCalls.kt"); - } - - @Test - @TestMetadata("inferCoroutineTypeInOldVersion.kt") - public void testInferCoroutineTypeInOldVersion() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/inferCoroutineTypeInOldVersion.kt"); - } - @Test @TestMetadata("inferenceFromMethodInsideLocalVariable.kt") public void testInferenceFromMethodInsideLocalVariable() throws Exception { @@ -33668,12 +33710,6 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/recursiveGenerators2.kt"); } - @Test - @TestMetadata("resolveUsualCallWithBuilderInference.kt") - public void testResolveUsualCallWithBuilderInference() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/resolveUsualCallWithBuilderInference.kt"); - } - @Test @TestMetadata("returnTypeInference.kt") public void testReturnTypeInference() throws Exception { @@ -33722,12 +33758,6 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/typeFromReceiver.kt"); } - @Test - @TestMetadata("useInferenceInformationFromExtension.kt") - public void testUseInferenceInformationFromExtension() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/useInferenceInformationFromExtension.kt"); - } - @Test @TestMetadata("variableCallInsideBuilderFunction.kt") public void testVariableCallInsideBuilderFunction() throws Exception { diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/constraints/violating.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/constraints/violating.fir.kt new file mode 100644 index 00000000000..f58e2f745da --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/constraints/violating.fir.kt @@ -0,0 +1,33 @@ +// !LANGUAGE: +StableBuilderInference +// WITH_RUNTIME + +interface A { + fun foo(): MutableList +} + +@ExperimentalStdlibApi +fun main() { + buildList { + add(3) + object : A { + override fun foo(): MutableList = this@buildList + } + } + buildList { + add(3) + val x: String = get(0) + } + buildList { + add("3") + val x: MutableList = this@buildList + } + buildList { + val y: CharSequence = "" + add(y) + val x: MutableList = this@buildList + } + buildList { + add("") + val x: StringBuilder = get(0) + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/constraints/violating.kt b/compiler/testData/diagnostics/tests/inference/builderInference/constraints/violating.kt index e69de29bb2d..5fb7f59b4c2 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/constraints/violating.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/constraints/violating.kt @@ -0,0 +1,33 @@ +// !LANGUAGE: +StableBuilderInference +// WITH_RUNTIME + +interface A { + fun foo(): MutableList +} + +@ExperimentalStdlibApi +fun main() { + buildList { + add(3) + object : A { + override fun foo(): MutableList = this@buildList + } + } + buildList { + add(3) + val x: String = get(0) + } + buildList { + add("3") + val x: MutableList = this@buildList + } + buildList { + val y: CharSequence = "" + add(y) + val x: MutableList = this@buildList + } + buildList { + add("") + val x: StringBuilder = get(0) + } +} diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/constraints/violating.txt b/compiler/testData/diagnostics/tests/inference/builderInference/constraints/violating.txt new file mode 100644 index 00000000000..b4bfed59df5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/constraints/violating.txt @@ -0,0 +1,11 @@ +package + +@kotlin.ExperimentalStdlibApi public fun main(): kotlin.Unit + +public interface A { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun foo(): kotlin.collections.MutableList + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/constraints/withExpectedType.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/constraints/withExpectedType.fir.kt index 5de75a7c432..76633086c28 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/constraints/withExpectedType.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/constraints/withExpectedType.fir.kt @@ -1,39 +1,69 @@ +// !LANGUAGE: +StableBuilderInference // WITH_RUNTIME +// !DIAGNOSTICS: -EXPERIMENTAL_API_USAGE_ERROR -CAST_NEVER_SUCCEEDS -interface A { - fun foo(): MutableList -} +fun id(x: K): K = x + +fun build(@BuilderInference builderAction: MutableMap.() -> V) {} + +fun build2(@BuilderInference builderAction: MutableMap.() -> K) {} + +fun build3(@BuilderInference builderAction: MutableMap.(K) -> Unit) {} + +fun build4(@BuilderInference builderAction: MutableMap.() -> MutableMap) {} + +fun build5(@BuilderInference builderAction: MutableMap.() -> MutableMap) {} + +fun build6(@BuilderInference builderAction: MutableMap.() -> MutableMap) {} + +fun build7(@BuilderInference builderAction: MutableMap.() -> MutableMap) = null as MutableMap @ExperimentalStdlibApi fun main() { - buildList { - add(3) - object : A { - override fun foo(): MutableList = this@buildList - } - } - buildList { - add(3) - val x: String = get(0) - } - buildList { - add("3") - val x: MutableList = this@buildList - } - buildList { - val y: CharSequence = "" - add(y) - val x: MutableList = this@buildList - } buildList { add("") val x: MutableList = this@buildList } - buildList { - add("") - val x: StringBuilder = get(0) - } buildMap { val x: Function2 = ::put } -} \ No newline at end of file + + build { + get("") + "" + } + + build2 { + val x: String = this.values.first() + 1 + } + + build2 { + take(this.values.first()) + 1 + } + + build3 { key: String -> + take(this.values.first()) + } + + build3 { this.foo() } + + build4 { this } + + build4 { this.run { this } } + + build4 { run { this } } + build4 { id(run { this }) } + + build5 { id(run { this }) } + build6 { id(run { this }) } + + val x: MutableMap = build7 { + id(run { this }) + } +} + +fun MutableMap.foo() {} + +fun take(x: String) {} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/constraints/withExpectedType.kt b/compiler/testData/diagnostics/tests/inference/builderInference/constraints/withExpectedType.kt index 63fae382639..a80c68794d2 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/constraints/withExpectedType.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/constraints/withExpectedType.kt @@ -1,9 +1,6 @@ +// !LANGUAGE: +StableBuilderInference // WITH_RUNTIME -// !DIAGNOSTICS: -EXPERIMENTAL_API_USAGE_ERROR - -interface A { - fun foo(): MutableList -} +// !DIAGNOSTICS: -EXPERIMENTAL_API_USAGE_ERROR -CAST_NEVER_SUCCEEDS fun id(x: K): K = x @@ -19,37 +16,14 @@ fun build5(@BuilderInference builderAction: MutableMap fun build6(@BuilderInference builderAction: MutableMap.() -> MutableMap) {} -fun build7(@BuilderInference builderAction: MutableMap.() -> MutableMap): MutableMap {} +fun build7(@BuilderInference builderAction: MutableMap.() -> MutableMap) = null as MutableMap @ExperimentalStdlibApi fun main() { - buildList { - add(3) - object : A { - override fun foo(): MutableList = this@buildList - } - } - buildList { - add(3) - val x: String = get(0) - } - buildList { - add("3") - val x: MutableList = this@buildList - } - buildList { - val y: CharSequence = "" - add(y) - val x: MutableList = this@buildList - } buildList { add("") val x: MutableList = this@buildList } - buildList { - add("") - val x: StringBuilder = get(0) - } buildMap { val x: Function2 = ::put } diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/constraints/withExpectedType.txt b/compiler/testData/diagnostics/tests/inference/builderInference/constraints/withExpectedType.txt index 9bf9150d1f6..cdd02794752 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/constraints/withExpectedType.txt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/constraints/withExpectedType.txt @@ -6,14 +6,9 @@ public fun build3(/*0*/ @kotlin.BuilderInference builderActio public fun build4(/*0*/ @kotlin.BuilderInference builderAction: kotlin.collections.MutableMap.() -> kotlin.collections.MutableMap): kotlin.Unit public fun build5(/*0*/ @kotlin.BuilderInference builderAction: kotlin.collections.MutableMap.() -> kotlin.collections.MutableMap): kotlin.Unit public fun build6(/*0*/ @kotlin.BuilderInference builderAction: kotlin.collections.MutableMap.() -> kotlin.collections.MutableMap): kotlin.Unit +public fun build7(/*0*/ @kotlin.BuilderInference builderAction: kotlin.collections.MutableMap.() -> kotlin.collections.MutableMap): kotlin.collections.MutableMap public fun id(/*0*/ x: K): K @kotlin.ExperimentalStdlibApi public fun main(): kotlin.Unit public fun take(/*0*/ x: kotlin.String): kotlin.Unit public fun kotlin.collections.MutableMap.foo(): kotlin.Unit -public interface A { - public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean - public abstract fun foo(): kotlin.collections.MutableList - public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int - public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String -} diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferences.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferences.fir.kt index 5c82eb525fd..d0cb9901101 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferences.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferences.fir.kt @@ -30,7 +30,7 @@ fun foo7() = null as Foo7 interface FlowCollector {} -fun flow(@BuilderInference block: suspend FlowCollector.() -> Unit) = Flow(block) +fun flow(@BuilderInference block: suspend FlowCollector.() -> Unit): Flow = Flow(block) class Flow(private val block: suspend FlowCollector.() -> Unit) @@ -39,7 +39,7 @@ fun select(vararg x: R) = x[0] fun poll0(): Flow { return flow { val inv = select(::bar, ::foo) - inv() + inv() } } @@ -123,7 +123,7 @@ fun poll14(flag: Boolean): Flow { fun poll15(flag: Boolean): Flow { return flow { val inv = if (flag) { ::bar5 } else { ::foo5 } - inv() + inv() } } @@ -144,7 +144,7 @@ fun poll17(flag: Boolean): Flow { fun poll2(flag: Boolean): Flow { return flow { val inv = when (flag) { true -> ::bar else -> ::foo } - inv() + inv() } } @@ -193,7 +193,7 @@ fun poll26(flag: Boolean): Flow { fun poll3(flag: Boolean): Flow { return flow { val inv = when (flag) { true -> ::bar false -> ::foo } - inv() + inv() } } @@ -242,7 +242,7 @@ fun poll36(flag: Boolean): Flow { fun poll4(): Flow { return flow { val inv = try { ::bar } finally { ::foo } - inv() + inv() } } @@ -270,7 +270,7 @@ fun poll43(): Flow { fun poll44(): Flow { return flow { val inv = try { ::bar5 } finally { ::foo5 } - inv() + inv() } } @@ -291,7 +291,7 @@ fun poll46(): Flow { fun poll5(): Flow { return flow { val inv = try { ::bar } catch (e: Exception) { ::foo } finally { ::foo } - inv() + inv() } } @@ -319,7 +319,7 @@ fun poll53(): Flow { fun poll54(): Flow { return flow { val inv = try { ::bar5 } catch (e: Exception) { ::foo5 } finally { ::foo5 } - inv() + inv() } } @@ -388,49 +388,49 @@ fun poll66(): Flow { fun poll7(): Flow { return flow { - val inv = ::bar!! - inv() + val inv = ::bar!! + inv() } } fun poll71(): Flow { return flow { - val inv = ::bar2!! + val inv = ::bar2!! inv() } } fun poll72(): Flow { return flow { - val inv = ::bar3!! + val inv = ::bar3!! inv() } } fun poll73(): Flow { return flow { - val inv = ::bar4!! + val inv = ::bar4!! inv } } fun poll74(): Flow { return flow { - val inv = ::bar5!! + val inv = ::bar5!! inv } } fun poll75(): Flow { return flow { - val inv = ::Foo6!! + val inv = ::Foo6!! inv } } fun poll76(): Flow { return flow { - val inv = ::Foo7!! + val inv = ::Foo7!! inv } } @@ -438,21 +438,21 @@ fun poll76(): Flow { fun poll8(): Flow { return flow { val inv = ::bar in setOf(::foo) - inv() + inv() } } fun poll81(): Flow { return flow { val inv = ::bar2 in setOf(::foo2) - inv() + inv() } } fun poll82(): Flow { return flow { val inv = ::bar3 in setOf(::foo3) - inv() + inv() } } diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferences.kt b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferences.kt index 5a36cdeb617..da4759bb918 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferences.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithCallableReferences.kt @@ -30,7 +30,7 @@ fun foo7() = null as Foo7 interface FlowCollector {} -fun flow(@BuilderInference block: suspend FlowCollector.() -> Unit) = Flow(block) +fun flow(@BuilderInference block: suspend FlowCollector.() -> Unit): Flow = Flow(block) class Flow(private val block: suspend FlowCollector.() -> Unit) @@ -38,7 +38,7 @@ fun select(vararg x: R) = x[0] fun poll0(): Flow { return flow { - val inv = select(::bar, ::foo) + val inv = select(::bar, ::foo) inv() } } @@ -52,7 +52,7 @@ fun poll01(): Flow { fun poll02(): Flow { return flow { - val inv = select(::bar3, ::foo3) + val inv = select(::bar3, ::foo3) inv() } } @@ -66,7 +66,7 @@ fun poll03(): Flow { fun poll04(): Flow { return flow { - val inv = select(::bar5, ::foo5) + val inv = select(::bar5, ::foo5) inv } } @@ -143,7 +143,7 @@ fun poll17(flag: Boolean): Flow { fun poll2(flag: Boolean): Flow { return flow { - val inv = when (flag) { true -> ::bar else -> ::foo } + val inv = when (flag) { true -> ::bar else -> ::foo } inv() } } @@ -157,7 +157,7 @@ fun poll21(flag: Boolean): Flow { fun poll22(flag: Boolean): Flow { return flow { - val inv = when (flag) { true -> ::bar3 else -> ::foo3 } + val inv = when (flag) { true -> ::bar3 else -> ::foo3 } inv() } } @@ -171,7 +171,7 @@ fun poll23(flag: Boolean): Flow { fun poll24(flag: Boolean): Flow { return flow { - val inv = when (flag) { true -> ::bar5 else -> ::foo5 } + val inv = when (flag) { true -> ::bar5 else -> ::foo5 } inv } } @@ -192,7 +192,7 @@ fun poll26(flag: Boolean): Flow { fun poll3(flag: Boolean): Flow { return flow { - val inv = when (flag) { true -> ::bar false -> ::foo } + val inv = when (flag) { true -> ::bar false -> ::foo } inv() } } @@ -206,7 +206,7 @@ fun poll31(flag: Boolean): Flow { fun poll32(flag: Boolean): Flow { return flow { - val inv = when (flag) { true -> ::bar3 false -> ::foo3 } + val inv = when (flag) { true -> ::bar3 false -> ::foo3 } inv() } } @@ -220,7 +220,7 @@ fun poll33(flag: Boolean): Flow { fun poll34(flag: Boolean): Flow { return flow { - val inv = when (flag) { true -> ::bar5 false -> ::foo5 } + val inv = when (flag) { true -> ::bar5 false -> ::foo5 } inv } } diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypes.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypes.fir.kt index 1200f7a5985..059332a5984 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypes.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypes.fir.kt @@ -1,4 +1,5 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -UNCHECKED_CAST -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE +// !LANGUAGE: +UnrestrictedBuilderInference +// !DIAGNOSTICS: -DEPRECATION -UNCHECKED_CAST -EXPERIMENTAL_IS_NOT_ENABLED // WITH_RUNTIME // FILE: main.kt diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypes.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypes.kt index 77499321355..16013c8d0a9 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypes.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/capturedTypes.kt @@ -1,4 +1,5 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -UNCHECKED_CAST -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE +// !LANGUAGE: +UnrestrictedBuilderInference +// !DIAGNOSTICS: -DEPRECATION -UNCHECKED_CAST -EXPERIMENTAL_IS_NOT_ENABLED // WITH_RUNTIME // FILE: main.kt diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperType.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperType.fir.kt index cc5f6ce7d99..de0a08b3b08 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperType.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperType.fir.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +StableBuilderInference // !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE // WITH_RUNTIME diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperType.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperType.kt index 84005ec4c2e..e2411e5cfa0 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperType.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperType.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +StableBuilderInference // !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE // WITH_RUNTIME diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeContravariant.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeContravariant.fir.kt index 6b77f81ebe9..f1dd708bf7c 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeContravariant.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeContravariant.fir.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +StableBuilderInference // !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE // WITH_RUNTIME diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeContravariant.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeContravariant.kt index 831ce4c760d..2c791455049 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeContravariant.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeContravariant.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +StableBuilderInference // !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE // WITH_RUNTIME diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeCovariant.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeCovariant.fir.kt index 94e80b833a1..bee76e9179c 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeCovariant.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeCovariant.fir.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +StableBuilderInference // !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE // WITH_RUNTIME diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeCovariant.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeCovariant.kt index 4a349459ee5..b509e17052f 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeCovariant.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeCovariant.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +StableBuilderInference // !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE // WITH_RUNTIME diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeInvariant.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeInvariant.fir.kt index d9638659a73..8cfc75c61ef 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeInvariant.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeInvariant.fir.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +StableBuilderInference // !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE // WITH_RUNTIME diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeInvariant.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeInvariant.kt index dbeb6a091ab..a63fc8d2106 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeInvariant.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeInvariant.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +StableBuilderInference // !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE // WITH_RUNTIME diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeNullable.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeNullable.fir.kt index 10efcd9533a..3937ba0b316 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeNullable.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeNullable.fir.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +StableBuilderInference // !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE // WITH_RUNTIME diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeNullable.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeNullable.kt index 0366c6643fc..50d6abbc8a9 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeNullable.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/commonSuperTypeNullable.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +StableBuilderInference // !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE // WITH_RUNTIME diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/intersect.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/intersect.fir.kt index 45544e47842..84fb81b5441 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/intersect.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/intersect.fir.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +StableBuilderInference // !DIAGNOSTICS: -UNUSED_PARAMETER -UNCHECKED_CAST -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE // WITH_RUNTIME diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/intersect.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/intersect.kt index 1177ced0883..a59e9a74c23 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/intersect.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/intersect.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +StableBuilderInference // !DIAGNOSTICS: -UNUSED_PARAMETER -UNCHECKED_CAST -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE // WITH_RUNTIME diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.fir.kt new file mode 100644 index 00000000000..a008f5736dd --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.fir.kt @@ -0,0 +1,73 @@ +// !LANGUAGE: +StableBuilderInference +// !DIAGNOSTICS: -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED +// WITH_RUNTIME + +// FILE: main.kt +import kotlin.experimental.ExperimentalTypeInference + +interface TestInterface { + fun emit(r: R) + fun get(): R +} + +@UseExperimental(ExperimentalTypeInference::class) +fun build(@BuilderInference block: TestInterface.() -> Unit): R1 = TODO() + +fun Any.test() {} +fun Any?.test2() {} + +fun test() { + val ret = build { + emit(1) + emit(null) + get()?.test() + get()?.test2() + get().test2() + get()?.hashCode() + get()?.equals(1) + // there is `String?.equals` extension + get().equals("") + val x = get() + x?.hashCode() + x?.equals(1) + x.equals("") + + if (get() == null) {} + if (get() === null) {} + + if (x != null) { + x?.hashCode() + x?.equals(1) + x.equals("") + x.hashCode() + x.toString() + x.test() + x?.test2() + x.test2() + } + + if (x == null) { + x?.hashCode() + x?.equals(1) + x.equals("") + x.hashCode() + x.toString() + x.test() + x?.test2() + x.test2() + } + + if (x === null) { + x?.hashCode() + x?.equals(1) + x.equals("") + x.hashCode() + x.toString() + x.test() + x?.test2() + x.test2() + } + + "" + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.kt new file mode 100644 index 00000000000..2e50aada8e9 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.kt @@ -0,0 +1,73 @@ +// !LANGUAGE: +StableBuilderInference +// !DIAGNOSTICS: -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED +// WITH_RUNTIME + +// FILE: main.kt +import kotlin.experimental.ExperimentalTypeInference + +interface TestInterface { + fun emit(r: R) + fun get(): R +} + +@UseExperimental(ExperimentalTypeInference::class) +fun build(@BuilderInference block: TestInterface.() -> Unit): R1 = TODO() + +fun Any.test() {} +fun Any?.test2() {} + +fun test() { + val ret = build { + emit(1) + emit(null) + get()?.test() + get()?.test2() + get().test2() + get()?.hashCode() + get()?.equals(1) + // there is `String?.equals` extension + get().equals("") + val x = get() + x?.hashCode() + x?.equals(1) + x.equals("") + + if (get() == null) {} + if (get() === null) {} + + if (x != null) { + x?.hashCode() + x?.equals(1) + x.equals("") + x.hashCode() + x.toString() + x.test() + x?.test2() + x.test2() + } + + if (x == null) { + x?.hashCode() + x?.equals(1) + x.equals("") + x.hashCode() + x.toString() + x.test() + x?.test2() + x.test2() + } + + if (x === null) { + x?.hashCode() + x?.equals(1) + x.equals("") + x.hashCode() + x.toString() + x.test() + x?.test2() + x.test2() + } + + "" + } +} diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.txt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.txt new file mode 100644 index 00000000000..919b61fb191 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.txt @@ -0,0 +1,14 @@ +package + +@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun build(/*0*/ @kotlin.BuilderInference block: TestInterface.() -> kotlin.Unit): R1 +public fun test(): kotlin.Unit +public fun kotlin.Any.test(): kotlin.Unit +public fun kotlin.Any?.test2(): kotlin.Unit + +public interface TestInterface { + public abstract fun emit(/*0*/ r: R): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun get(): R + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/nullability.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/nullability.fir.kt new file mode 100644 index 00000000000..af2f0cf308c --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/nullability.fir.kt @@ -0,0 +1,62 @@ +// !LANGUAGE: +StableBuilderInference +// !DIAGNOSTICS: -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED +// WITH_RUNTIME + +// FILE: main.kt +import kotlin.experimental.ExperimentalTypeInference + +interface TestInterface { + fun emit(r: R) + fun get(): R +} + +@UseExperimental(ExperimentalTypeInference::class) +fun build(@BuilderInference block: TestInterface.() -> Unit): R1 = TODO() + +@UseExperimental(ExperimentalTypeInference::class) +fun build2(@BuilderInference block: TestInterface.() -> Unit): R1 = TODO() + +@UseExperimental(ExperimentalTypeInference::class) +fun build3(@BuilderInference block: TestInterface.() -> Unit): R1 = TODO() + +@UseExperimental(ExperimentalTypeInference::class) +fun build4(x: R2, @BuilderInference block: TestInterface.() -> Unit): R1 = TODO() + +fun test(a: String?) { + val ret1 = build { + emit(1) + get()?.equals("") + val x = get() + x?.equals("") + x ?: 1 + x!! + "" + } + val ret2 = build2 { + emit(1) + get()?.equals("") + val x = get() + x?.equals("") + x ?: 1 + x!! + "" + } + val ret3 = build3 { + emit(1) + get()?.equals("") + val x = get() + x?.equals("") + x ?: 1 + x!! + "" + } + val ret4 = build4(1) { + emit(1) + get()?.equals("") + val x = get() + x?.equals("") + x ?: 1 + x!! + "" + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/nullability.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/nullability.kt new file mode 100644 index 00000000000..85c1fc42fe5 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/nullability.kt @@ -0,0 +1,62 @@ +// !LANGUAGE: +StableBuilderInference +// !DIAGNOSTICS: -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED +// WITH_RUNTIME + +// FILE: main.kt +import kotlin.experimental.ExperimentalTypeInference + +interface TestInterface { + fun emit(r: R) + fun get(): R +} + +@UseExperimental(ExperimentalTypeInference::class) +fun build(@BuilderInference block: TestInterface.() -> Unit): R1 = TODO() + +@UseExperimental(ExperimentalTypeInference::class) +fun build2(@BuilderInference block: TestInterface.() -> Unit): R1 = TODO() + +@UseExperimental(ExperimentalTypeInference::class) +fun build3(@BuilderInference block: TestInterface.() -> Unit): R1 = TODO() + +@UseExperimental(ExperimentalTypeInference::class) +fun build4(x: R2, @BuilderInference block: TestInterface.() -> Unit): R1 = TODO() + +fun test(a: String?) { + val ret1 = build { + emit(1) + get()?.equals("") + val x = get() + x?.equals("") + x ?: 1 + x!! + "" + } + val ret2 = build2 { + emit(1) + get()?.equals("") + val x = get() + x?.equals("") + x ?: 1 + x!! + "" + } + val ret3 = build3 { + emit(1) + get()?.equals("") + val x = get() + x?.equals("") + x ?: 1 + x!! + "" + } + val ret4 = build4(1) { + emit(1) + get()?.equals("") + val x = get() + x?.equals("") + x ?: 1 + x!! + "" + } +} diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/nullability.txt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/nullability.txt new file mode 100644 index 00000000000..968e28c5210 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/nullability.txt @@ -0,0 +1,15 @@ +package + +@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun build(/*0*/ @kotlin.BuilderInference block: TestInterface.() -> kotlin.Unit): R1 +@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun build2(/*0*/ @kotlin.BuilderInference block: TestInterface.() -> kotlin.Unit): R1 +@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun build3(/*0*/ @kotlin.BuilderInference block: TestInterface.() -> kotlin.Unit): R1 +@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun build4(/*0*/ x: R2, /*1*/ @kotlin.BuilderInference block: TestInterface.() -> kotlin.Unit): R1 +public fun test(/*0*/ a: kotlin.String?): kotlin.Unit + +public interface TestInterface { + public abstract fun emit(/*0*/ r: R): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun get(): R + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/renderingStubTypes.fir.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/renderingStubTypes.fir.kt index 5f7d1848552..91537f723e8 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/renderingStubTypes.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/renderingStubTypes.fir.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +StableBuilderInference // !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE // WITH_RUNTIME diff --git a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/renderingStubTypes.kt b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/renderingStubTypes.kt index 6be25403904..31cf37f3dae 100644 --- a/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/renderingStubTypes.kt +++ b/compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/renderingStubTypes.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +StableBuilderInference // !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE // WITH_RUNTIME diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCalls.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCalls.fir.kt new file mode 100644 index 00000000000..f6d4f6f7c2c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCalls.fir.kt @@ -0,0 +1,37 @@ +// !LANGUAGE: +StableBuilderInference +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE + +@file:OptIn(ExperimentalTypeInference::class) + +import kotlin.experimental.ExperimentalTypeInference + +class GenericController { + suspend fun yield(t: T) {} + fun notYield(t: T) {} + + suspend fun yieldBarReturnType(t: T) = t + fun barReturnType(): T = TODO() +} + +fun generate(@BuilderInference g: suspend GenericController.() -> Unit): List = TODO() + +val test1 = generate { + yield(3) +} + +val test2 = generate { + yield(3) + notYield(3) +} + +val test3 = generate { + yield(3) + yieldBarReturnType(3) +} + +val test4 = generate { + yield(3) + barReturnType() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/incorrectCalls.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCalls.kt similarity index 95% rename from compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/incorrectCalls.kt rename to compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCalls.kt index 634ec01b919..00cab60f3a0 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/incorrectCalls.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCalls.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +StableBuilderInference // !USE_EXPERIMENTAL: kotlin.RequiresOptIn // !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/incorrectCalls.txt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCalls.txt similarity index 100% rename from compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/incorrectCalls.txt rename to compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCalls.txt diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/incorrectCalls.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCallsWithRestrictions.fir.kt similarity index 100% rename from compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/incorrectCalls.fir.kt rename to compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCallsWithRestrictions.fir.kt diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCallsWithRestrictions.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCallsWithRestrictions.kt new file mode 100644 index 00000000000..8a3a022d122 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCallsWithRestrictions.kt @@ -0,0 +1,36 @@ +// !USE_EXPERIMENTAL: kotlin.RequiresOptIn +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE +// !WITH_NEW_INFERENCE + +@file:OptIn(ExperimentalTypeInference::class) + +import kotlin.experimental.ExperimentalTypeInference + +class GenericController { + suspend fun yield(t: T) {} + fun notYield(t: T) {} + + suspend fun yieldBarReturnType(t: T) = t + fun barReturnType(): T = TODO() +} + +fun generate(@BuilderInference g: suspend GenericController.() -> Unit): List = TODO() + +val test1 = generate { + yield(3) +} + +val test2 = generate { + yield(3) + notYield(3) +} + +val test3 = generate { + yield(3) + yieldBarReturnType(3) +} + +val test4 = generate { + yield(3) + barReturnType() +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCallsWithRestrictions.txt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCallsWithRestrictions.txt new file mode 100644 index 00000000000..a72fa6593da --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCallsWithRestrictions.txt @@ -0,0 +1,24 @@ +package + +public val test1: kotlin.collections.List +public val test2: kotlin.collections.List +public val test3: [ERROR : Type for generate { + yield(3) + yieldBarReturnType(3) +}] +public val test4: [ERROR : Type for generate { + yield(3) + barReturnType() +}] +public fun generate(/*0*/ @kotlin.BuilderInference g: suspend GenericController.() -> kotlin.Unit): kotlin.collections.List + +public final class GenericController { + public constructor GenericController() + public final fun barReturnType(): T + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public final fun notYield(/*0*/ t: T): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + public final suspend fun yield(/*0*/ t: T): kotlin.Unit + public final suspend fun yieldBarReturnType(/*0*/ t: T): T +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/inferCoroutineTypeInOldVersion.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inferCoroutineTypeInOldVersion.fir.kt similarity index 93% rename from compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/inferCoroutineTypeInOldVersion.fir.kt rename to compiler/testData/diagnostics/testsWithStdLib/builderInference/inferCoroutineTypeInOldVersion.fir.kt index 8a07eff2f12..1772fd86f64 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/inferCoroutineTypeInOldVersion.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inferCoroutineTypeInOldVersion.fir.kt @@ -1,4 +1,4 @@ -// !LANGUAGE: -ExperimentalBuilderInference +// !LANGUAGE: +StableBuilderInference // !DIAGNOSTICS: -UNUSED_PARAMETER class Builder { diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/inferCoroutineTypeInOldVersion.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inferCoroutineTypeInOldVersion.kt similarity index 76% rename from compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/inferCoroutineTypeInOldVersion.kt rename to compiler/testData/diagnostics/testsWithStdLib/builderInference/inferCoroutineTypeInOldVersion.kt index d755acd8578..9ee76c60b2f 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/inferCoroutineTypeInOldVersion.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inferCoroutineTypeInOldVersion.kt @@ -1,4 +1,4 @@ -// !LANGUAGE: -ExperimentalBuilderInference +// !LANGUAGE: +StableBuilderInference // !DIAGNOSTICS: -UNUSED_PARAMETER class Builder { @@ -12,7 +12,7 @@ fun Builder.extensionAdd(s: S) {} suspend fun Builder.safeExtensionAdd(s: S) {} -val member = build { +val member = build { add(42) } @@ -24,6 +24,6 @@ val extension = build { extensionAdd("foo") } -val safeExtension = build { +val safeExtension = build { safeExtensionAdd("foo") } diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/inferCoroutineTypeInOldVersion.txt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inferCoroutineTypeInOldVersion.txt similarity index 79% rename from compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/inferCoroutineTypeInOldVersion.txt rename to compiler/testData/diagnostics/testsWithStdLib/builderInference/inferCoroutineTypeInOldVersion.txt index efde51d672d..021aa4b6685 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/inferCoroutineTypeInOldVersion.txt +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/inferCoroutineTypeInOldVersion.txt @@ -1,11 +1,17 @@ package -public val extension: kotlin.collections.List -public val member: kotlin.collections.List +public val extension: [ERROR : Type for build { + extensionAdd("foo") +}] +public val member: [ERROR : Type for build { + add(42) +}] public val memberWithoutAnn: [ERROR : Type for wrongBuild { add(42) }] -public val safeExtension: kotlin.collections.List +public val safeExtension: [ERROR : Type for build { + safeExtensionAdd("foo") +}] public fun build(/*0*/ g: suspend Builder.() -> kotlin.Unit): kotlin.collections.List public fun wrongBuild(/*0*/ g: Builder.() -> kotlin.Unit): kotlin.collections.List public fun Builder.extensionAdd(/*0*/ s: S): kotlin.Unit diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/resolveUsualCallWithBuilderInference.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInference.fir.kt similarity index 94% rename from compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/resolveUsualCallWithBuilderInference.fir.kt rename to compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInference.fir.kt index b0e7f1eb751..de86984800b 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/resolveUsualCallWithBuilderInference.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInference.fir.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +StableBuilderInference // !DIAGNOSTICS: -UNUSED_PARAMETER // FILE: annotation.kt diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/resolveUsualCallWithBuilderInference.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInference.kt similarity index 94% rename from compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/resolveUsualCallWithBuilderInference.kt rename to compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInference.kt index ce06fb70c99..9b8ccd3d8e3 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/resolveUsualCallWithBuilderInference.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInference.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +StableBuilderInference // !DIAGNOSTICS: -UNUSED_PARAMETER // FILE: annotation.kt diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/resolveUsualCallWithBuilderInference.txt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInference.txt similarity index 100% rename from compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/resolveUsualCallWithBuilderInference.txt rename to compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInference.txt diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInferenceWithRestrictions.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInferenceWithRestrictions.fir.kt new file mode 100644 index 00000000000..d9c5c473fad --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInferenceWithRestrictions.fir.kt @@ -0,0 +1,37 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE +// FILE: annotation.kt + +package kotlin + +annotation class BuilderInference + +// FILE: test.kt + +class Builder { + fun add(t: T) {} +} + +fun build(@BuilderInference g: Builder.() -> Unit): List = TODO() +fun wrongBuild(g: Builder.() -> Unit): List = TODO() + +fun Builder.extensionAdd(s: S) {} + +@BuilderInference +fun Builder.safeExtensionAdd(s: S) {} + +val member = build { + add(42) +} + +val memberWithoutAnn = wrongBuild { + add(42) +} + +val extension = build { + extensionAdd("foo") +} + +val safeExtension = build { + safeExtensionAdd("foo") +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInferenceWithRestrictions.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInferenceWithRestrictions.kt new file mode 100644 index 00000000000..8405228535c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInferenceWithRestrictions.kt @@ -0,0 +1,37 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE +// FILE: annotation.kt + +package kotlin + +annotation class BuilderInference + +// FILE: test.kt + +class Builder { + fun add(t: T) {} +} + +fun build(@BuilderInference g: Builder.() -> Unit): List = TODO() +fun wrongBuild(g: Builder.() -> Unit): List = TODO() + +fun Builder.extensionAdd(s: S) {} + +@BuilderInference +fun Builder.safeExtensionAdd(s: S) {} + +val member = build { + add(42) +} + +val memberWithoutAnn = wrongBuild { + add(42) +} + +val extension = build { + extensionAdd("foo") +} + +val safeExtension = build { + safeExtensionAdd("foo") +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInferenceWithRestrictions.txt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInferenceWithRestrictions.txt new file mode 100644 index 00000000000..09f79370be6 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInferenceWithRestrictions.txt @@ -0,0 +1,32 @@ +package + +public val extension: [ERROR : Type for build { + extensionAdd("foo") +}] +public val member: kotlin.collections.List +public val memberWithoutAnn: [ERROR : Type for wrongBuild { + add(42) +}] +public val safeExtension: kotlin.collections.List +public fun build(/*0*/ @kotlin.BuilderInference g: Builder.() -> kotlin.Unit): kotlin.collections.List +public fun wrongBuild(/*0*/ g: Builder.() -> kotlin.Unit): kotlin.collections.List +public fun Builder.extensionAdd(/*0*/ s: S): kotlin.Unit +@kotlin.BuilderInference public fun Builder.safeExtensionAdd(/*0*/ s: S): kotlin.Unit + +public final class Builder { + public constructor Builder() + public final fun add(/*0*/ t: T): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +package kotlin { + + public final annotation class BuilderInference : kotlin.Annotation { + public constructor BuilderInference() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtension.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtension.fir.kt new file mode 100644 index 00000000000..050ca6ddb3a --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtension.fir.kt @@ -0,0 +1,34 @@ +// !LANGUAGE: +StableBuilderInference +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE + +// FILE: annotation.kt + +package kotlin + +annotation class BuilderInference + +// FILE: test.kt + +class GenericController { + suspend fun yield(t: T) {} +} + +suspend fun GenericController.extensionYield(s: S) {} + +@BuilderInference +suspend fun GenericController.safeExtensionYield(s: S) {} + +fun generate(@BuilderInference g: suspend GenericController.() -> Unit): List = TODO() + +val normal = generate { + yield(42) +} + +val extension = generate { + extensionYield("foo") +} + +val safeExtension = generate { + safeExtensionYield("foo") +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/useInferenceInformationFromExtension.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtension.kt similarity index 94% rename from compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/useInferenceInformationFromExtension.kt rename to compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtension.kt index 86d13bf0ff0..a89632281d3 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/useInferenceInformationFromExtension.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtension.kt @@ -1,3 +1,4 @@ +// !LANGUAGE: +StableBuilderInference // !DIAGNOSTICS: -UNUSED_PARAMETER // FILE: annotation.kt diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/useInferenceInformationFromExtension.txt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtension.txt similarity index 100% rename from compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/useInferenceInformationFromExtension.txt rename to compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtension.txt diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/useInferenceInformationFromExtension.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtensionWithRestrictions.fir.kt similarity index 100% rename from compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/useInferenceInformationFromExtension.fir.kt rename to compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtensionWithRestrictions.fir.kt diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtensionWithRestrictions.kt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtensionWithRestrictions.kt new file mode 100644 index 00000000000..c307234989f --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtensionWithRestrictions.kt @@ -0,0 +1,33 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +// !WITH_NEW_INFERENCE + +// FILE: annotation.kt + +package kotlin + +annotation class BuilderInference + +// FILE: test.kt + +class GenericController { + suspend fun yield(t: T) {} +} + +suspend fun GenericController.extensionYield(s: S) {} + +@BuilderInference +suspend fun GenericController.safeExtensionYield(s: S) {} + +fun generate(@BuilderInference g: suspend GenericController.() -> Unit): List = TODO() + +val normal = generate { + yield(42) +} + +val extension = generate { + extensionYield("foo") +} + +val safeExtension = generate { + safeExtensionYield("foo") +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtensionWithRestrictions.txt b/compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtensionWithRestrictions.txt new file mode 100644 index 00000000000..bdb5071930e --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtensionWithRestrictions.txt @@ -0,0 +1,28 @@ +package + +public val extension: [ERROR : Type for generate { + extensionYield("foo") +}] +public val normal: kotlin.collections.List +public val safeExtension: kotlin.collections.List +public fun generate(/*0*/ @kotlin.BuilderInference g: suspend GenericController.() -> kotlin.Unit): kotlin.collections.List +public suspend fun GenericController.extensionYield(/*0*/ s: S): kotlin.Unit +@kotlin.BuilderInference public suspend fun GenericController.safeExtensionYield(/*0*/ s: S): kotlin.Unit + +public final class GenericController { + public constructor GenericController() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + public final suspend fun yield(/*0*/ t: T): kotlin.Unit +} + +package kotlin { + + public final annotation class BuilderInference : kotlin.Annotation { + public constructor BuilderInference() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + 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 911c0443a5a..9d47ab3e32b 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 @@ -12771,6 +12771,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/intersect.kt"); } + @Test + @TestMetadata("memberScope.kt") + public void testMemberScope() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/memberScope.kt"); + } + + @Test + @TestMetadata("nullability.kt") + public void testNullability() throws Exception { + runTest("compiler/testData/diagnostics/tests/inference/builderInference/stubTypes/nullability.kt"); + } + @Test @TestMetadata("renderingStubTypes.kt") public void testRenderingStubTypes() throws Exception { @@ -32418,6 +32430,48 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { public void testCompleteIrrelevantCalls() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/completeIrrelevantCalls.kt"); } + + @Test + @TestMetadata("incorrectCalls.kt") + public void testIncorrectCalls() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCalls.kt"); + } + + @Test + @TestMetadata("incorrectCallsWithRestrictions.kt") + public void testIncorrectCallsWithRestrictions() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/incorrectCallsWithRestrictions.kt"); + } + + @Test + @TestMetadata("inferCoroutineTypeInOldVersion.kt") + public void testInferCoroutineTypeInOldVersion() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/inferCoroutineTypeInOldVersion.kt"); + } + + @Test + @TestMetadata("resolveUsualCallWithBuilderInference.kt") + public void testResolveUsualCallWithBuilderInference() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInference.kt"); + } + + @Test + @TestMetadata("resolveUsualCallWithBuilderInferenceWithRestrictions.kt") + public void testResolveUsualCallWithBuilderInferenceWithRestrictions() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/resolveUsualCallWithBuilderInferenceWithRestrictions.kt"); + } + + @Test + @TestMetadata("useInferenceInformationFromExtension.kt") + public void testUseInferenceInformationFromExtension() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtension.kt"); + } + + @Test + @TestMetadata("useInferenceInformationFromExtensionWithRestrictions.kt") + public void testUseInferenceInformationFromExtensionWithRestrictions() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/builderInference/useInferenceInformationFromExtensionWithRestrictions.kt"); + } } @Nested @@ -33608,18 +33662,6 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/extensionsWithNonValuableConstraints_1_2.kt"); } - @Test - @TestMetadata("incorrectCalls.kt") - public void testIncorrectCalls() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/incorrectCalls.kt"); - } - - @Test - @TestMetadata("inferCoroutineTypeInOldVersion.kt") - public void testInferCoroutineTypeInOldVersion() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/inferCoroutineTypeInOldVersion.kt"); - } - @Test @TestMetadata("inferenceFromMethodInsideLocalVariable.kt") public void testInferenceFromMethodInsideLocalVariable() throws Exception { @@ -33764,12 +33806,6 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/recursiveGenerators2.kt"); } - @Test - @TestMetadata("resolveUsualCallWithBuilderInference.kt") - public void testResolveUsualCallWithBuilderInference() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/resolveUsualCallWithBuilderInference.kt"); - } - @Test @TestMetadata("returnTypeInference.kt") public void testReturnTypeInference() throws Exception { @@ -33818,12 +33854,6 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/typeFromReceiver.kt"); } - @Test - @TestMetadata("useInferenceInformationFromExtension.kt") - public void testUseInferenceInformationFromExtension() throws Exception { - runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/useInferenceInformationFromExtension.kt"); - } - @Test @TestMetadata("variableCallInsideBuilderFunction.kt") public void testVariableCallInsideBuilderFunction() throws Exception {