[FIR] Fix setting return type for when and try with non applicable candidates
This commit is contained in:
+5
-2
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -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())
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
)
|
||||
}
|
||||
+5
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user