[FIR] Fix setting return type for when and try with non applicable candidates

This commit is contained in:
Dmitriy Novozhilov
2019-08-22 15:58:40 +03:00
parent 6e6ffa12a6
commit 4697822b5a
5 changed files with 49 additions and 3 deletions
@@ -400,7 +400,10 @@ open class FirBodyResolveTransformer(
tryExpression.transformCatches(this, null)
@Suppress("NAME_SHADOWING")
val tryExpression = syntheticCallGenerator.generateCalleeForTryExpression(tryExpression) ?: return tryExpression.compose()
val tryExpression = syntheticCallGenerator.generateCalleeForTryExpression(tryExpression) ?: run {
tryExpression.resultType = FirErrorTypeRefImpl(null, "Inapplicable when expression")
return tryExpression.compose()
}
val expectedTypeRef = data as FirTypeRef?
val result = callCompleter.completeCall(tryExpression, expectedTypeRef)
@@ -482,7 +485,7 @@ open class FirBodyResolveTransformer(
@Suppress("NAME_SHADOWING")
val whenExpression = syntheticCallGenerator.generateCalleeForWhenExpression(whenExpression) ?: run {
// TODO: bodies will be unresolved. Maybe run usual transform without completer?
whenExpression.resultType = FirErrorTypeRefImpl(null, "Inapplicable when expression")
return@with whenExpression.compose()
}
@@ -27,7 +27,7 @@ FILE: recursiveCallOnWhenWithSealedClass.kt
}
public final fun unwrap(): <ERROR TYPE REF: No type for block> {
public final fun unwrap(): <ERROR TYPE REF: Inapplicable when expression> {
^unwrap when (this#) {
($subj$ is R|Maybe.Nope|) -> {
throw R|java/lang/Exception.Exception|(String())
+12
View File
@@ -0,0 +1,12 @@
fun <T, R> T.also(block: () -> R): R {
null!!
}
fun foo(b: Boolean) {
val x = when (b) {
true -> a
else -> null
}?.also {
1
}
}
@@ -0,0 +1,26 @@
FILE: whenAsReceiver.kt
public final fun <T, R> R|T|.also(block: R|kotlin/Function0<R>|): R|R| {
when (lval <bangbang>: R|kotlin/Nothing?| = Null(null)) {
==($subj$, Null(null)) -> {
throw <Unresolved name: KotlinNullPointerException>#()
}
else -> {
R|<local>/<bangbang>|!
}
}
}
public final fun foo(b: R|kotlin/Boolean|): R|kotlin/Unit| {
lval x: <ERROR TYPE REF: Inapplicable(WRONG_RECEIVER): [/also]> = when (R|<local>/b|) {
==($subj$, Boolean(true)) -> {
<Unresolved name: a>#
}
else -> {
Null(null)
}
}
?.<Inapplicable(WRONG_RECEIVER): [/also]>#(<L> = also@fun <implicit>.<anonymous>(): <implicit> {
Int(1)
}
)
}
@@ -179,6 +179,11 @@ public class FirResolveTestCaseGenerated extends AbstractFirResolveTestCase {
runTest("compiler/fir/resolve/testData/resolve/typeParameterVsNested.kt");
}
@TestMetadata("whenAsReceiver.kt")
public void testWhenAsReceiver() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/whenAsReceiver.kt");
}
@TestMetadata("whenInference.kt")
public void testWhenInference() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/whenInference.kt");