Resolve calls using the builder inference despite the presence of the annotation if there are uninferred type variables

^KT-48194 Fixed
This commit is contained in:
Victor Petukhov
2021-08-19 09:08:39 +03:00
committed by TeamCityServer
parent 55811c8851
commit bf1e68a53f
17 changed files with 104 additions and 9 deletions
@@ -13404,6 +13404,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithLambdas.kt");
}
@Test
@TestMetadata("withoutAnnotationDisabledFeature.kt")
public void testWithoutAnnotationDisabledFeature() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/builderInference/withoutAnnotationDisabledFeature.kt");
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/inference/builderInference/constraints")
@TestDataPath("$PROJECT_ROOT")
@@ -13404,6 +13404,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithLambdas.kt");
}
@Test
@TestMetadata("withoutAnnotationDisabledFeature.kt")
public void testWithoutAnnotationDisabledFeature() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/builderInference/withoutAnnotationDisabledFeature.kt");
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/inference/builderInference/constraints")
@TestDataPath("$PROJECT_ROOT")
@@ -18234,12 +18234,6 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
public void testWithoutAnnotation() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/withoutAnnotation.kt");
}
@Test
@TestMetadata("withoutAnnotationDisabledFeature.kt")
public void testWithoutAnnotationDisabledFeature() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/withoutAnnotationDisabledFeature.kt");
}
}
}
@@ -9,6 +9,8 @@ import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.builtins.getReceiverTypeFromFunctionType
import org.jetbrains.kotlin.builtins.getValueParameterTypesFromFunctionType
import org.jetbrains.kotlin.builtins.isBuiltinFunctionalType
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.annotations.FilteredAnnotations
import org.jetbrains.kotlin.resolve.calls.inference.addSubsystemFromArgument
@@ -23,7 +25,8 @@ import org.jetbrains.kotlin.types.typeUtil.builtIns
import org.jetbrains.kotlin.utils.addToStdlib.cast
class PostponedArgumentsAnalyzer(
private val callableReferenceResolver: CallableReferenceResolver
private val callableReferenceResolver: CallableReferenceResolver,
private val languageVersionSettings: LanguageVersionSettings
) {
fun analyze(
@@ -180,7 +183,10 @@ class PostponedArgumentsAnalyzer(
lambda.setAnalyzedResults(returnArgumentsInfo, subResolvedKtPrimitives)
if (inferenceSession != null && lambda.atom.hasBuilderInferenceAnnotation) {
val shouldUseBuilderInference = lambda.atom.hasBuilderInferenceAnnotation
|| languageVersionSettings.supportsFeature(LanguageFeature.UseBuilderInferenceWithoutAnnotation)
if (inferenceSession != null && shouldUseBuilderInference) {
val storageSnapshot = c.getBuilder().currentStorage()
val postponedVariables = inferenceSession.inferPostponedVariables(
@@ -176,9 +176,11 @@ class KotlinConstraintSystemCompleter(
if (!useBuilderInferenceOnlyIfNeeded) return false
val lambdaArguments = postponedArguments.filterIsInstance<ResolvedLambdaAtom>().takeIf { it.isNotEmpty() } ?: return false
val useBuilderInferenceWithoutAnnotation =
languageVersionSettings.supportsFeature(LanguageFeature.UseBuilderInferenceWithoutAnnotation)
return lambdaArguments.any { argument ->
if (!argument.atom.hasBuilderInferenceAnnotation)
if (!argument.atom.hasBuilderInferenceAnnotation && !useBuilderInferenceWithoutAnnotation)
return@any false
val notFixedInputTypeVariables = argument.inputTypes
@@ -0,0 +1,13 @@
// WITH_RUNTIME
// DONT_TARGET_EXACT_BACKEND: WASM
// IGNORE_BACKEND_FIR: JVM_IR
// !LANGUAGE: +UseBuilderInferenceWithoutAnnotation
fun <K, V> buildMap(builderAction: MutableMap<K, V>.() -> Unit): Map<K, V> = mapOf()
fun box(): String {
val x = buildMap {
put("", "")
}
return "OK"
}
@@ -0,0 +1,12 @@
// WITH_RUNTIME
// DONT_TARGET_EXACT_BACKEND: WASM
// !LANGUAGE: -UseBuilderInferenceWithoutAnnotation
fun <K, V> buildMap(builderAction: MutableMap<K, V>.() -> Unit): Map<K, V> = mapOf()
fun box(): String {
val x = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>buildMap<!> {
put("", "")
}
return "OK"
}
@@ -0,0 +1,12 @@
// WITH_RUNTIME
// DONT_TARGET_EXACT_BACKEND: WASM
// !LANGUAGE: -UseBuilderInferenceWithoutAnnotation
fun <K, V> buildMap(builderAction: MutableMap<K, V>.() -> Unit): Map<K, V> = mapOf()
fun box(): String {
val x = <!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>buildMap<!> {
put("", "")
}
return "OK"
}
@@ -0,0 +1,5 @@
package
public fun box(): kotlin.String
public fun </*0*/ K, /*1*/ V> buildMap(/*0*/ builderAction: kotlin.collections.MutableMap<K, V>.() -> kotlin.Unit): kotlin.collections.Map<K, V>
@@ -13410,6 +13410,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/inference/builderInference/specialCallsWithLambdas.kt");
}
@Test
@TestMetadata("withoutAnnotationDisabledFeature.kt")
public void testWithoutAnnotationDisabledFeature() throws Exception {
runTest("compiler/testData/diagnostics/tests/inference/builderInference/withoutAnnotationDisabledFeature.kt");
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/inference/builderInference/constraints")
@TestDataPath("$PROJECT_ROOT")
@@ -18078,6 +18078,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
public void testWithExpectedType() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/withExpectedType.kt");
}
@Test
@TestMetadata("withoutAnnotation.kt")
public void testWithoutAnnotation() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/withoutAnnotation.kt");
}
}
}
@@ -18222,6 +18222,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
public void testWithExpectedType() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/withExpectedType.kt");
}
@Test
@TestMetadata("withoutAnnotation.kt")
public void testWithoutAnnotation() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/withoutAnnotation.kt");
}
}
}
@@ -14979,6 +14979,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
public void testWithExpectedType() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/withExpectedType.kt");
}
@TestMetadata("withoutAnnotation.kt")
public void testWithoutAnnotation() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/withoutAnnotation.kt");
}
}
}
@@ -226,6 +226,7 @@ enum class LanguageFeature(
OptInRelease(KOTLIN_1_7),
ProhibitNonExhaustiveWhenOnAlgebraicTypes(KOTLIN_1_7, kind = BUG_FIX),
UseBuilderInferenceWithoutAnnotation(KOTLIN_1_7),
// Temporarily disabled, see KT-27084/KT-22379
SoundSmartcastFromLoopConditionForLoopAssignedVariables(sinceVersion = null, kind = BUG_FIX),
@@ -13058,6 +13058,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
public void testWithExpectedType() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/withExpectedType.kt");
}
@TestMetadata("withoutAnnotation.kt")
public void testWithoutAnnotation() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/withoutAnnotation.kt");
}
}
}
@@ -12464,6 +12464,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
public void testWithExpectedType() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/withExpectedType.kt");
}
@TestMetadata("withoutAnnotation.kt")
public void testWithoutAnnotation() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/withoutAnnotation.kt");
}
}
}
@@ -12529,6 +12529,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
public void testWithExpectedType() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/withExpectedType.kt");
}
@TestMetadata("withoutAnnotation.kt")
public void testWithoutAnnotation() throws Exception {
runTest("compiler/testData/codegen/box/inference/builderInference/withoutAnnotation.kt");
}
}
}