[NI] Fix shouldRunCompletion for builder inference session
#KT-41308 Fixed #KT-41363
This commit is contained in:
+10
@@ -1966,6 +1966,11 @@ public class FirOldFrontendDiagnosticsTestWithStdlibGenerated extends AbstractFi
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/builderInferenceForMaterializeWithExpectedType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferenceAndCoercionToUnit.kt")
|
||||
public void testCallableReferenceAndCoercionToUnit() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/callableReferenceAndCoercionToUnit.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferenceToASuspendFunction.kt")
|
||||
public void testCallableReferenceToASuspendFunction() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/callableReferenceToASuspendFunction.kt");
|
||||
@@ -2101,6 +2106,11 @@ public class FirOldFrontendDiagnosticsTestWithStdlibGenerated extends AbstractFi
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt41164.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt41308.kt")
|
||||
public void testKt41308() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt41308.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nestedLambdaInferenceWithListMap.kt")
|
||||
public void testNestedLambdaInferenceWithListMap() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/nestedLambdaInferenceWithListMap.kt");
|
||||
|
||||
Generated
+5
@@ -1708,6 +1708,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferenceAndCoercionToUnit.kt")
|
||||
public void testCallableReferenceAndCoercionToUnit() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builderInference/callableReferenceAndCoercionToUnit.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt41164.kt")
|
||||
public void testKt41164() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builderInference/kt41164.kt");
|
||||
|
||||
+29
@@ -18,6 +18,7 @@ import org.jetbrains.kotlin.resolve.calls.ArgumentTypeResolver
|
||||
import org.jetbrains.kotlin.resolve.calls.components.CompletedCallInfo
|
||||
import org.jetbrains.kotlin.resolve.calls.components.NewConstraintSystemImpl
|
||||
import org.jetbrains.kotlin.resolve.calls.components.PostponedArgumentsAnalyzer
|
||||
import org.jetbrains.kotlin.resolve.calls.components.stableType
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintSystemCompleter
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
|
||||
@@ -27,6 +28,7 @@ import org.jetbrains.kotlin.resolve.calls.model.*
|
||||
import org.jetbrains.kotlin.resolve.calls.tower.*
|
||||
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.hasBuilderInferenceAnnotation
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.expressions.DoubleColonExpressionResolver
|
||||
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices
|
||||
@@ -72,6 +74,10 @@ class CoroutineInferenceSession(
|
||||
return subResolvedAtoms?.any { it.hasPostponed() } == true
|
||||
}
|
||||
|
||||
if (!candidate.isSuitableForBuilderInference()) {
|
||||
return true
|
||||
}
|
||||
|
||||
return !storage.notFixedTypeVariables.keys.any {
|
||||
val variable = storage.allTypeVariables[it]
|
||||
val isPostponed = variable != null && variable in storage.postponedTypeVariables
|
||||
@@ -79,6 +85,29 @@ class CoroutineInferenceSession(
|
||||
} || candidate.getSubResolvedAtoms().any { it.hasPostponed() }
|
||||
}
|
||||
|
||||
private fun KotlinResolutionCandidate.isSuitableForBuilderInference(): Boolean {
|
||||
val extensionReceiver = resolvedCall.extensionReceiverArgument
|
||||
val dispatchReceiver = resolvedCall.dispatchReceiverArgument
|
||||
return when {
|
||||
extensionReceiver == null && dispatchReceiver == null -> false
|
||||
extensionReceiver == null -> true
|
||||
extensionReceiver.receiver.stableType.containsStubType() -> resolvedCall.candidateDescriptor.hasBuilderInferenceAnnotation()
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
|
||||
private fun KotlinType.containsNotFixedTypeVariable(storage: ConstraintStorage): Boolean {
|
||||
return this.contains {
|
||||
it.constructor in storage.notFixedTypeVariables
|
||||
}
|
||||
}
|
||||
|
||||
private fun KotlinType.containsStubType(): Boolean {
|
||||
return this.contains {
|
||||
it is StubType
|
||||
}
|
||||
}
|
||||
|
||||
fun addSimpleCall(callExpression: KtExpression) {
|
||||
simpleCommonCalls.add(callExpression)
|
||||
}
|
||||
|
||||
+2
-1
@@ -332,7 +332,7 @@ class ResolvedAtomCompleter(
|
||||
resolvedAtom: ResolvedCallableReferenceAtom
|
||||
) {
|
||||
val callableCandidate = resolvedAtom.candidate
|
||||
if (callableCandidate == null) {
|
||||
if (callableCandidate == null || resolvedAtom.completed) {
|
||||
// todo report meanfull diagnostic here
|
||||
return
|
||||
}
|
||||
@@ -420,6 +420,7 @@ class ResolvedAtomCompleter(
|
||||
)
|
||||
|
||||
kotlinToResolvedCallTransformer.runCallCheckers(resolvedCall, topLevelCallCheckerContext)
|
||||
resolvedAtom.completed = true
|
||||
}
|
||||
|
||||
private fun ReceiverValue.updateReceiverValue(substitutor: TypeSubstitutor): ReceiverValue {
|
||||
|
||||
@@ -168,6 +168,8 @@ abstract class ResolvedCallableReferenceAtom(
|
||||
var candidate: CallableReferenceCandidate? = null
|
||||
private set
|
||||
|
||||
var completed: Boolean = false
|
||||
|
||||
fun setAnalyzedResults(
|
||||
candidate: CallableReferenceCandidate?,
|
||||
subResolvedAtoms: List<ResolvedAtom>
|
||||
@@ -299,4 +301,4 @@ class PartialCallContainer(val result: PartialCallResolutionResult?) {
|
||||
*/
|
||||
class StubResolvedAtom(val typeVariable: TypeConstructor) : ResolvedAtom() {
|
||||
override val atom: ResolutionAtom? get() = null
|
||||
}
|
||||
}
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// !LANGUAGE: +NewInference
|
||||
// !DIAGNOSTICS: -EXPERIMENTAL_API_USAGE_ERROR -UNUSED_EXPRESSION
|
||||
// WITH_RUNTIME
|
||||
|
||||
@OptIn(ExperimentalStdlibApi::class)
|
||||
fun test(s: String?): Int {
|
||||
val list = buildList {
|
||||
s?.let(::add)
|
||||
}
|
||||
return list.size
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
return when (test("hello")) {
|
||||
1 -> "OK"
|
||||
else -> "Error"
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// FIR_IDENTICAL
|
||||
// !DIAGNOSTICS: -EXPERIMENTAL_API_USAGE_ERROR -UNUSED_EXPRESSION
|
||||
|
||||
fun test(s: String?) {
|
||||
val list = buildList {
|
||||
s?.let(::add)
|
||||
}
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.List<kotlin.String>")!>list<!>
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
public fun test(/*0*/ s: kotlin.String?): kotlin.Unit
|
||||
+2
-2
@@ -21,7 +21,7 @@ fun test_2() {
|
||||
fun test_3() {
|
||||
sequence {
|
||||
yield(materialize<Int>())
|
||||
<!TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH, TYPE_MISMATCH!>materialize()<!>
|
||||
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>materialize<!>()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,4 +32,4 @@ interface Inv<T> {
|
||||
fun yield(element: T)
|
||||
}
|
||||
|
||||
fun <K> materialize(): Inv<K> = TODO()
|
||||
fun <K> materialize(): Inv<K> = TODO()
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
Failures detected in FirBodyResolveTransformerAdapter, file: /kt41308.fir.kt
|
||||
Cause: java.lang.RuntimeException: While resolving call R?C|kotlin/sequences/sequence|(<L> = sequence@fun R|kotlin/sequences/SequenceScope<Stub: TypeVariable(T)>|.<anonymous>(): R|kotlin/Unit| {
|
||||
lval list: R|kotlin/collections/List<kotlin/String>?| = Null(null)
|
||||
lval outputList: R|TypeVariable(K)| = R|<local>/list| ?: R?C|kotlin/collections/listOf|()
|
||||
yieldAll#(R|<local>/outputList|)
|
||||
}
|
||||
)
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// ISSUE: KT-41308
|
||||
|
||||
fun main() {
|
||||
sequence {
|
||||
val list: List<String>? = null
|
||||
val outputList = <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.List<kotlin.String>")!>list ?: listOf()<!>
|
||||
yieldAll(outputList)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
// ISSUE: KT-41308
|
||||
|
||||
fun main() {
|
||||
sequence {
|
||||
val list: List<String>? = null
|
||||
val outputList = <!DEBUG_INFO_EXPRESSION_TYPE("kotlin.collections.List<kotlin.String>")!>list ?: listOf()<!>
|
||||
yieldAll(outputList)
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
public fun main(): kotlin.Unit
|
||||
@@ -21,4 +21,4 @@ fun main() {
|
||||
}
|
||||
}
|
||||
|
||||
class Foo(val notNullProp: String)
|
||||
class Foo(val notNullProp: String)
|
||||
|
||||
+10
@@ -2006,6 +2006,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/builderInferenceForMaterializeWithExpectedType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferenceAndCoercionToUnit.kt")
|
||||
public void testCallableReferenceAndCoercionToUnit() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/callableReferenceAndCoercionToUnit.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferenceToASuspendFunction.kt")
|
||||
public void testCallableReferenceToASuspendFunction() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/callableReferenceToASuspendFunction.kt");
|
||||
@@ -2141,6 +2146,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt41164.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt41308.kt")
|
||||
public void testKt41308() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt41308.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nestedLambdaInferenceWithListMap.kt")
|
||||
public void testNestedLambdaInferenceWithListMap() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/nestedLambdaInferenceWithListMap.kt");
|
||||
|
||||
compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java
Generated
+10
@@ -2006,6 +2006,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/builderInferenceForMaterializeWithExpectedType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferenceAndCoercionToUnit.kt")
|
||||
public void testCallableReferenceAndCoercionToUnit() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/callableReferenceAndCoercionToUnit.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferenceToASuspendFunction.kt")
|
||||
public void testCallableReferenceToASuspendFunction() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/callableReferenceToASuspendFunction.kt");
|
||||
@@ -2141,6 +2146,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt41164.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt41308.kt")
|
||||
public void testKt41308() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/kt41308.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nestedLambdaInferenceWithListMap.kt")
|
||||
public void testNestedLambdaInferenceWithListMap() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/nestedLambdaInferenceWithListMap.kt");
|
||||
|
||||
+5
@@ -1728,6 +1728,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferenceAndCoercionToUnit.kt")
|
||||
public void testCallableReferenceAndCoercionToUnit() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builderInference/callableReferenceAndCoercionToUnit.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt41164.kt")
|
||||
public void testKt41164() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builderInference/kt41164.kt");
|
||||
|
||||
+5
@@ -1728,6 +1728,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferenceAndCoercionToUnit.kt")
|
||||
public void testCallableReferenceAndCoercionToUnit() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builderInference/callableReferenceAndCoercionToUnit.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt41164.kt")
|
||||
public void testKt41164() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builderInference/kt41164.kt");
|
||||
|
||||
+5
@@ -1708,6 +1708,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferenceAndCoercionToUnit.kt")
|
||||
public void testCallableReferenceAndCoercionToUnit() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builderInference/callableReferenceAndCoercionToUnit.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt41164.kt")
|
||||
public void testKt41164() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builderInference/kt41164.kt");
|
||||
|
||||
Generated
+5
@@ -1328,6 +1328,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferenceAndCoercionToUnit.kt")
|
||||
public void testCallableReferenceAndCoercionToUnit() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builderInference/callableReferenceAndCoercionToUnit.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt41164.kt")
|
||||
public void testKt41164() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builderInference/kt41164.kt");
|
||||
|
||||
Generated
+5
@@ -1328,6 +1328,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferenceAndCoercionToUnit.kt")
|
||||
public void testCallableReferenceAndCoercionToUnit() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builderInference/callableReferenceAndCoercionToUnit.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt41164.kt")
|
||||
public void testKt41164() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builderInference/kt41164.kt");
|
||||
|
||||
+5
@@ -1328,6 +1328,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/builderInference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
|
||||
}
|
||||
|
||||
@TestMetadata("callableReferenceAndCoercionToUnit.kt")
|
||||
public void testCallableReferenceAndCoercionToUnit() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builderInference/callableReferenceAndCoercionToUnit.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt41164.kt")
|
||||
public void testKt41164() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/builderInference/kt41164.kt");
|
||||
|
||||
Reference in New Issue
Block a user