FIR IDE: fix CCE in getKtExpressionType on loops
This commit is contained in:
+5
-4
@@ -9,6 +9,7 @@ import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.FirFunctionCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirLoop
|
||||
import org.jetbrains.kotlin.fir.expressions.argumentMapping
|
||||
import org.jetbrains.kotlin.fir.psi
|
||||
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
|
||||
@@ -40,12 +41,12 @@ internal class KtFirExpressionTypeProvider(
|
||||
}
|
||||
|
||||
override fun getKtExpressionType(expression: KtExpression): KtType = withValidityAssertion {
|
||||
val coneType = when (val fir = expression.getOrBuildFir(firResolveState)) {
|
||||
is FirExpression -> fir.typeRef.coneType
|
||||
is FirNamedReference -> fir.getReferencedElementType()
|
||||
when (val fir = expression.getOrBuildFir(firResolveState)) {
|
||||
is FirExpression -> fir.typeRef.coneType.asKtType()
|
||||
is FirNamedReference -> fir.getReferencedElementType().asKtType()
|
||||
is FirLoop -> with(analysisSession) { builtinTypes.UNIT }
|
||||
else -> error("Unexpected ${fir::class}")
|
||||
}
|
||||
coneType.asKtType()
|
||||
}
|
||||
|
||||
private fun FirNamedReference.getReferencedElementType(): ConeKotlinType {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fun x(): Int {
|
||||
<expr>for(i in 1..2) {}</expr>
|
||||
}
|
||||
// RESULT
|
||||
|
||||
// expression: for(i in 1..2) {}
|
||||
// type: kotlin.Unit
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fun x(): Int {
|
||||
<expr>while(true) {}</expr>
|
||||
}
|
||||
// RESULT
|
||||
|
||||
// expression: while(true) {}
|
||||
// type: kotlin.Unit
|
||||
|
||||
+11
@@ -33,4 +33,15 @@ public class HLExpressionTypeTestGenerated extends AbstractHLExpressionTypeTest
|
||||
public void testAssignmentExpressionTarget() throws Exception {
|
||||
runTest("idea/idea-frontend-fir/testData/components/expressionType/assignmentExpressionTarget.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("forExpression.kt")
|
||||
public void testForExpression() throws Exception {
|
||||
runTest("idea/idea-frontend-fir/testData/components/expressionType/forExpression.kt");
|
||||
}
|
||||
|
||||
|
||||
@TestMetadata("whileExpression.kt")
|
||||
public void testWhileExpression() throws Exception {
|
||||
runTest("idea/idea-frontend-fir/testData/components/expressionType/whileExpression.kt");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user