[FIR] Fix completion of synthetic call arguments

This commit is contained in:
Mikhail Glukhikh
2020-12-28 13:10:20 +03:00
parent b7a382f097
commit a6534c4653
7 changed files with 33 additions and 4 deletions
@@ -75,7 +75,7 @@ FILE: RedundantExplicitTypeChecker.kt
public final fun test(boolean: R|kotlin/Boolean|): R|kotlin/Unit| {
lval expectedLong: R|kotlin/Long| = when () {
R|<local>/boolean| -> {
Int(42)
Long(42)
}
else -> {
^test Unit
@@ -0,0 +1,17 @@
FILE: SpecialCallsWithLambdas.kt
public final fun foo(): R|kotlin/Unit| {
lval inv: R|() -> kotlin/Function0<kotlin/Unit>| = fun <anonymous>(): R|() -> kotlin/Unit| {
^ fun <anonymous>(): R|kotlin/Unit| {
^ Unit
}
}
!!
lval bar: R|() -> kotlin/Function0<kotlin/Unit>| = fun <anonymous>(): R|() -> kotlin/Unit| {
^ fun <anonymous>(): R|kotlin/Unit| {
^ Unit
}
}
}
@@ -0,0 +1,4 @@
fun foo() {
val inv = {{}}!!
val bar = {{}}
}
@@ -4889,6 +4889,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/receiverResolutionInLambda.kt");
}
@Test
@TestMetadata("SpecialCallsWithLambdas.kt")
public void testSpecialCallsWithLambdas() throws Exception {
runTest("compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/SpecialCallsWithLambdas.kt");
}
@Test
@TestMetadata("TypesEligibleForSimpleVisit.kt")
public void testTypesEligibleForSimpleVisit() throws Exception {
@@ -534,13 +534,16 @@ class FirCallCompletionResultsWriterTransformer(
syntheticCall: D,
data: ExpectedArgumentType?,
): CompositeTransformResult<FirStatement> where D : FirResolvable, D : FirExpression {
syntheticCall.transformChildren(this, data?.getExpectedType(syntheticCall)?.toExpectedType())
val calleeReference = syntheticCall.calleeReference as? FirNamedReferenceWithCandidate ?: return syntheticCall.compose()
val declaration = calleeReference.candidate.symbol.fir as? FirSimpleFunction ?: return syntheticCall.compose()
val typeRef = typeCalculator.tryCalculateReturnType(declaration)
syntheticCall.replaceTypeRefWithSubstituted(calleeReference, typeRef)
syntheticCall.transformChildren(
this,
data = data?.getExpectedType(syntheticCall)?.toExpectedType() ?: syntheticCall.typeRef.coneType.toExpectedType()
)
return (syntheticCall.transformCalleeReference(
StoreCalleeReference,
@@ -1,5 +1,4 @@
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
// DONT_TARGET_EXACT_BACKEND: WASM
import kotlin.experimental.ExperimentalTypeInference
@@ -5,7 +5,7 @@ fun <M> materialize(): M = TODO()
fun test(b: Boolean) {
<!INAPPLICABLE_CANDIDATE!>id<!>(if (b) {
<!INAPPLICABLE_CANDIDATE!>id<!>(<!UNRESOLVED_REFERENCE!>unresolved<!>)
id(<!UNRESOLVED_REFERENCE!>unresolved<!>)
} else {
id(
materialize()