Don't try to infer postponed variables on lambdas without BuilderInference annotation
^KT-39618 Fixed
This commit is contained in:
+5
@@ -10434,6 +10434,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
||||
runTest("compiler/testData/diagnostics/tests/inference/returningLambdaInSuspendContext.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt")
|
||||
public void testSimpleLambdaInCallWithAnotherLambdaWithBuilderInference() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("skipedUnresolvedInBuilderInferenceWithStubReceiverType.kt")
|
||||
public void testSkipedUnresolvedInBuilderInferenceWithStubReceiverType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/skipedUnresolvedInBuilderInferenceWithStubReceiverType.kt");
|
||||
|
||||
@@ -110,6 +110,12 @@ class LambdaKotlinCallArgumentImpl(
|
||||
) : PSIFunctionKotlinCallArgument(outerCallContext, valueArgument, dataFlowInfoBeforeThisArgument, argumentName) {
|
||||
override val ktFunction get() = ktLambdaExpression.functionLiteral
|
||||
override val expression get() = containingBlockForLambda
|
||||
|
||||
override var hasBuilderInferenceAnnotation = false
|
||||
set(value) {
|
||||
assert(!field)
|
||||
field = value
|
||||
}
|
||||
}
|
||||
|
||||
class FunctionExpressionImpl(
|
||||
|
||||
+1
-1
@@ -187,7 +187,7 @@ class PostponedArgumentsAnalyzer(
|
||||
|
||||
lambda.setAnalyzedResults(returnArgumentsInfo, subResolvedKtPrimitives)
|
||||
|
||||
if (inferenceSession != null) {
|
||||
if (inferenceSession != null && lambda.atom.hasBuilderInferenceAnnotation) {
|
||||
val storageSnapshot = c.getBuilder().currentStorage()
|
||||
|
||||
val postponedVariables = inferenceSession.inferPostponedVariables(lambda, storageSnapshot, diagnosticHolder)
|
||||
|
||||
+4
@@ -238,6 +238,10 @@ internal object PostponedVariablesInitializerResolutionPart : ResolutionPart() {
|
||||
if (!callComponents.statelessCallbacks.isCoroutineCall(argument, parameter)) continue
|
||||
val receiverType = parameter.type.getReceiverTypeFromFunctionType() ?: continue
|
||||
|
||||
if (argument is LambdaKotlinCallArgument && !argument.hasBuilderInferenceAnnotation) {
|
||||
argument.hasBuilderInferenceAnnotation = true
|
||||
}
|
||||
|
||||
for (freshVariable in resolvedCall.freshVariablesSubstitutor.freshVariables) {
|
||||
if (resolvedCall.typeArgumentMappingByOriginal.getTypeArgument(freshVariable.originalTypeParameter) is SimpleTypeArgument)
|
||||
continue
|
||||
|
||||
+8
@@ -52,6 +52,14 @@ interface LambdaKotlinCallArgument : PostponableKotlinCallArgument {
|
||||
override val isSpread: Boolean
|
||||
get() = false
|
||||
|
||||
/*
|
||||
* Builder inference is supported only for lambdas (so it's implemented only in `LambdaKotlinCallArgumentImpl`),
|
||||
* anonymous functions aren't supported
|
||||
*/
|
||||
var hasBuilderInferenceAnnotation: Boolean
|
||||
get() = false
|
||||
set(value) {}
|
||||
|
||||
/**
|
||||
* parametersTypes == null means, that there is no declared arguments
|
||||
* null inside array means that this type is not declared explicitly
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R> combined(
|
||||
check: () -> Unit,
|
||||
@BuilderInference block: TestInterface<R>.() -> Unit
|
||||
): R = TODO()
|
||||
|
||||
interface TestInterface<R> {
|
||||
fun emit(r: R)
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val ret = combined({ }) {
|
||||
<!INAPPLICABLE_CANDIDATE!>emit<!>(1)
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -DEPRECATION -EXPERIMENTAL_IS_NOT_ENABLED -UNUSED_VARIABLE
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.experimental.ExperimentalTypeInference
|
||||
|
||||
@UseExperimental(ExperimentalTypeInference::class)
|
||||
fun <R> combined(
|
||||
check: () -> Unit,
|
||||
@BuilderInference block: TestInterface<R>.() -> Unit
|
||||
): R = TODO()
|
||||
|
||||
interface TestInterface<R> {
|
||||
fun emit(r: R)
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val ret = combined({ }) {
|
||||
emit(1)
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package
|
||||
|
||||
@kotlin.UseExperimental(markerClass = {kotlin.experimental.ExperimentalTypeInference::class}) public fun </*0*/ R> combined(/*0*/ check: () -> kotlin.Unit, /*1*/ @kotlin.BuilderInference block: TestInterface<R>.() -> kotlin.Unit): R
|
||||
public fun test(): kotlin.Unit
|
||||
|
||||
public interface TestInterface</*0*/ R> {
|
||||
public abstract fun emit(/*0*/ r: R): 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
|
||||
}
|
||||
@@ -10441,6 +10441,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
|
||||
runTest("compiler/testData/diagnostics/tests/inference/returningLambdaInSuspendContext.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt")
|
||||
public void testSimpleLambdaInCallWithAnotherLambdaWithBuilderInference() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("skipedUnresolvedInBuilderInferenceWithStubReceiverType.kt")
|
||||
public void testSkipedUnresolvedInBuilderInferenceWithStubReceiverType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/skipedUnresolvedInBuilderInferenceWithStubReceiverType.kt");
|
||||
|
||||
Generated
+5
@@ -10436,6 +10436,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/inference/returningLambdaInSuspendContext.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt")
|
||||
public void testSimpleLambdaInCallWithAnotherLambdaWithBuilderInference() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/simpleLambdaInCallWithAnotherLambdaWithBuilderInference.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("skipedUnresolvedInBuilderInferenceWithStubReceiverType.kt")
|
||||
public void testSkipedUnresolvedInBuilderInferenceWithStubReceiverType() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inference/skipedUnresolvedInBuilderInferenceWithStubReceiverType.kt");
|
||||
|
||||
Reference in New Issue
Block a user