FIR: use unsafe .coneType in type mismatch checkers when possible
This commit is contained in:
+3
-1
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.fir.FirRealSourceElementKind
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.isComponentCall
|
import org.jetbrains.kotlin.fir.analysis.checkers.isComponentCall
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.isDestructuringDeclaration
|
import org.jetbrains.kotlin.fir.analysis.checkers.isDestructuringDeclaration
|
||||||
@@ -22,7 +23,8 @@ object FirInitializerTypeMismatchChecker : FirPropertyChecker() {
|
|||||||
val initializer = declaration.initializer ?: return
|
val initializer = declaration.initializer ?: return
|
||||||
if (declaration.isDestructuringDeclaration) return
|
if (declaration.isDestructuringDeclaration) return
|
||||||
if (initializer.isComponentCall) return
|
if (initializer.isComponentCall) return
|
||||||
val propertyType = declaration.returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: return
|
if (declaration.returnTypeRef.source?.kind != FirRealSourceElementKind) return
|
||||||
|
val propertyType = declaration.returnTypeRef.coneType
|
||||||
val expressionType = initializer.typeRef.coneTypeSafe<ConeKotlinType>() ?: return
|
val expressionType = initializer.typeRef.coneTypeSafe<ConeKotlinType>() ?: return
|
||||||
val typeContext = context.session.typeContext
|
val typeContext = context.session.typeContext
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.fir.expressions.FirWhenExpression
|
|||||||
import org.jetbrains.kotlin.fir.expressions.isExhaustive
|
import org.jetbrains.kotlin.fir.expressions.isExhaustive
|
||||||
import org.jetbrains.kotlin.fir.typeContext
|
import org.jetbrains.kotlin.fir.typeContext
|
||||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||||
|
import org.jetbrains.kotlin.fir.types.coneType
|
||||||
import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
||||||
|
|
||||||
object FirFunctionReturnTypeMismatchChecker : FirReturnExpressionChecker() {
|
object FirFunctionReturnTypeMismatchChecker : FirReturnExpressionChecker() {
|
||||||
@@ -25,7 +26,7 @@ object FirFunctionReturnTypeMismatchChecker : FirReturnExpressionChecker() {
|
|||||||
val resultExpression = expression.result
|
val resultExpression = expression.result
|
||||||
if (resultExpression is FirWhenExpression && !resultExpression.isExhaustive) return
|
if (resultExpression is FirWhenExpression && !resultExpression.isExhaustive) return
|
||||||
|
|
||||||
val functionReturnType = targetElement.returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: return
|
val functionReturnType = targetElement.returnTypeRef.coneType
|
||||||
val typeContext = context.session.typeContext
|
val typeContext = context.session.typeContext
|
||||||
val returnExpressionType = resultExpression.typeRef.coneTypeSafe<ConeKotlinType>() ?: return
|
val returnExpressionType = resultExpression.typeRef.coneTypeSafe<ConeKotlinType>() ?: return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user