[FIR] Transform when conditions with boolean expected type
#KT-42130 Fixed
This commit is contained in:
Generated
+5
@@ -13179,6 +13179,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/inference/kt39824.kt");
|
runTest("compiler/testData/codegen/box/inference/kt39824.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt42130.kt")
|
||||||
|
public void testKt42130() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inference/kt42130.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("lambdasWithExtensionFunctionType.kt")
|
@TestMetadata("lambdasWithExtensionFunctionType.kt")
|
||||||
public void testLambdasWithExtensionFunctionType() throws Exception {
|
public void testLambdasWithExtensionFunctionType() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt");
|
runTest("compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt");
|
||||||
|
|||||||
@@ -6,8 +6,10 @@
|
|||||||
package org.jetbrains.kotlin.fir.resolve
|
package org.jetbrains.kotlin.fir.resolve
|
||||||
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirDeclarationStatus
|
import org.jetbrains.kotlin.fir.declarations.FirDeclarationStatus
|
||||||
|
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||||
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
||||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||||
|
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||||
|
|
||||||
sealed class ResolutionMode {
|
sealed class ResolutionMode {
|
||||||
object ContextDependent : ResolutionMode()
|
object ContextDependent : ResolutionMode()
|
||||||
@@ -23,5 +25,12 @@ sealed class ResolutionMode {
|
|||||||
fun withExpectedType(expectedTypeRef: FirTypeRef?): ResolutionMode =
|
fun withExpectedType(expectedTypeRef: FirTypeRef?): ResolutionMode =
|
||||||
expectedTypeRef?.let { ResolutionMode.WithExpectedType(it) } ?: ResolutionMode.ContextDependent
|
expectedTypeRef?.let { ResolutionMode.WithExpectedType(it) } ?: ResolutionMode.ContextDependent
|
||||||
|
|
||||||
|
fun withExpectedType(coneType: ConeKotlinType): ResolutionMode {
|
||||||
|
val typeRef = buildResolvedTypeRef {
|
||||||
|
type = coneType
|
||||||
|
}
|
||||||
|
return ResolutionMode.WithExpectedType(typeRef)
|
||||||
|
}
|
||||||
|
|
||||||
fun FirDeclarationStatus.mode(): ResolutionMode =
|
fun FirDeclarationStatus.mode(): ResolutionMode =
|
||||||
ResolutionMode.WithStatus(this)
|
ResolutionMode.WithStatus(this)
|
||||||
|
|||||||
+5
-2
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
|||||||
import org.jetbrains.kotlin.fir.resolve.ResolutionMode
|
import org.jetbrains.kotlin.fir.resolve.ResolutionMode
|
||||||
import org.jetbrains.kotlin.fir.resolve.transformers.FirSyntheticCallGenerator
|
import org.jetbrains.kotlin.fir.resolve.transformers.FirSyntheticCallGenerator
|
||||||
import org.jetbrains.kotlin.fir.resolve.transformers.FirWhenExhaustivenessTransformer
|
import org.jetbrains.kotlin.fir.resolve.transformers.FirWhenExhaustivenessTransformer
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.withExpectedType
|
||||||
import org.jetbrains.kotlin.fir.resolvedTypeFromPrototype
|
import org.jetbrains.kotlin.fir.resolvedTypeFromPrototype
|
||||||
import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef
|
import org.jetbrains.kotlin.fir.types.FirImplicitTypeRef
|
||||||
import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef
|
import org.jetbrains.kotlin.fir.types.builder.buildErrorTypeRef
|
||||||
@@ -114,8 +115,10 @@ class FirControlFlowStatementsResolveTransformer(transformer: FirBodyResolveTran
|
|||||||
|
|
||||||
override fun transformWhenBranch(whenBranch: FirWhenBranch, data: ResolutionMode): CompositeTransformResult<FirWhenBranch> {
|
override fun transformWhenBranch(whenBranch: FirWhenBranch, data: ResolutionMode): CompositeTransformResult<FirWhenBranch> {
|
||||||
return whenBranch.also { dataFlowAnalyzer.enterWhenBranchCondition(whenBranch) }
|
return whenBranch.also { dataFlowAnalyzer.enterWhenBranchCondition(whenBranch) }
|
||||||
.transformCondition(transformer, data).also { dataFlowAnalyzer.exitWhenBranchCondition(it) }
|
.transformCondition(transformer, withExpectedType(session.builtinTypes.booleanType))
|
||||||
.transformResult(transformer, data).also { dataFlowAnalyzer.exitWhenBranchResult(it) }
|
.also { dataFlowAnalyzer.exitWhenBranchCondition(it) }
|
||||||
|
.transformResult(transformer, data)
|
||||||
|
.also { dataFlowAnalyzer.exitWhenBranchResult(it) }
|
||||||
.compose()
|
.compose()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
// ISSUE: KT-42130
|
||||||
|
|
||||||
|
interface A
|
||||||
|
interface B : A
|
||||||
|
|
||||||
|
fun B.foo(): Boolean = true
|
||||||
|
fun <T> run(action: () -> T): T = action()
|
||||||
|
|
||||||
|
fun foo(a: A): String {
|
||||||
|
return when (a) {
|
||||||
|
is B -> when {
|
||||||
|
run { a.foo() } -> "OK"
|
||||||
|
else -> "Fail 1"
|
||||||
|
}
|
||||||
|
else -> "Fail 2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class C : B
|
||||||
|
|
||||||
|
fun box(): String = foo(C())
|
||||||
+5
@@ -14574,6 +14574,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/inference/kt39824.kt");
|
runTest("compiler/testData/codegen/box/inference/kt39824.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt42130.kt")
|
||||||
|
public void testKt42130() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inference/kt42130.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("lambdasWithExtensionFunctionType.kt")
|
@TestMetadata("lambdasWithExtensionFunctionType.kt")
|
||||||
public void testLambdasWithExtensionFunctionType() throws Exception {
|
public void testLambdasWithExtensionFunctionType() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt");
|
runTest("compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt");
|
||||||
|
|||||||
+5
@@ -14574,6 +14574,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/inference/kt39824.kt");
|
runTest("compiler/testData/codegen/box/inference/kt39824.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt42130.kt")
|
||||||
|
public void testKt42130() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inference/kt42130.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("lambdasWithExtensionFunctionType.kt")
|
@TestMetadata("lambdasWithExtensionFunctionType.kt")
|
||||||
public void testLambdasWithExtensionFunctionType() throws Exception {
|
public void testLambdasWithExtensionFunctionType() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt");
|
runTest("compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt");
|
||||||
|
|||||||
+5
@@ -13179,6 +13179,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/inference/kt39824.kt");
|
runTest("compiler/testData/codegen/box/inference/kt39824.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt42130.kt")
|
||||||
|
public void testKt42130() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inference/kt42130.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("lambdasWithExtensionFunctionType.kt")
|
@TestMetadata("lambdasWithExtensionFunctionType.kt")
|
||||||
public void testLambdasWithExtensionFunctionType() throws Exception {
|
public void testLambdasWithExtensionFunctionType() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt");
|
runTest("compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt");
|
||||||
|
|||||||
Generated
+5
@@ -11319,6 +11319,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes
|
|||||||
runTest("compiler/testData/codegen/box/inference/kt39824.kt");
|
runTest("compiler/testData/codegen/box/inference/kt39824.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt42130.kt")
|
||||||
|
public void testKt42130() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inference/kt42130.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("lambdasWithExtensionFunctionType.kt")
|
@TestMetadata("lambdasWithExtensionFunctionType.kt")
|
||||||
public void testLambdasWithExtensionFunctionType() throws Exception {
|
public void testLambdasWithExtensionFunctionType() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt");
|
runTest("compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt");
|
||||||
|
|||||||
Generated
+5
@@ -11319,6 +11319,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/inference/kt39824.kt");
|
runTest("compiler/testData/codegen/box/inference/kt39824.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt42130.kt")
|
||||||
|
public void testKt42130() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inference/kt42130.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("lambdasWithExtensionFunctionType.kt")
|
@TestMetadata("lambdasWithExtensionFunctionType.kt")
|
||||||
public void testLambdasWithExtensionFunctionType() throws Exception {
|
public void testLambdasWithExtensionFunctionType() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt");
|
runTest("compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt");
|
||||||
|
|||||||
+5
@@ -11384,6 +11384,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/inference/kt39824.kt");
|
runTest("compiler/testData/codegen/box/inference/kt39824.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt42130.kt")
|
||||||
|
public void testKt42130() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inference/kt42130.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("lambdasWithExtensionFunctionType.kt")
|
@TestMetadata("lambdasWithExtensionFunctionType.kt")
|
||||||
public void testLambdasWithExtensionFunctionType() throws Exception {
|
public void testLambdasWithExtensionFunctionType() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt");
|
runTest("compiler/testData/codegen/box/inference/lambdasWithExtensionFunctionType.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user