K2: expand type before isSomeType checks properly
Related to KT-60229
This commit is contained in:
committed by
Space Team
parent
51e8a72f47
commit
00b4ae6ae9
+1
-1
@@ -165,7 +165,7 @@ object FirRepeatableAnnotationChecker : FirBasicDeclarationChecker() {
|
||||
val valueParameterSymbols = containerCtor.valueParameterSymbols
|
||||
val parameterName = StandardClassIds.Annotations.ParameterNames.value
|
||||
val value = valueParameterSymbols.find { it.name == parameterName }
|
||||
if (value == null || !value.resolvedReturnTypeRef.isArrayType ||
|
||||
if (value == null || !value.resolvedReturnTypeRef.coneType.fullyExpandedType(context.session).isArrayType ||
|
||||
value.resolvedReturnTypeRef.type.typeArguments.single().type != annotationClass.defaultType()
|
||||
) {
|
||||
reporter.reportOn(
|
||||
|
||||
+2
-2
@@ -13,10 +13,10 @@ import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.isEquals
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.hasBody
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isInterface
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isOverride
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.isEquals
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions.TO_STRING
|
||||
|
||||
@@ -43,7 +43,7 @@ object FirMethodOfAnyImplementedInInterfaceChecker : FirRegularClassChecker(), F
|
||||
(function.name == HASHCODE_NAME || function.name == TO_STRING)
|
||||
) {
|
||||
methodOfAny = true
|
||||
} else if (function.isEquals()) {
|
||||
} else if (function.isEquals(context.session)) {
|
||||
methodOfAny = true
|
||||
}
|
||||
|
||||
|
||||
+4
-5
@@ -24,7 +24,6 @@ import org.jetbrains.kotlin.fir.resolve.defaultType
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.resolve.lookupSuperTypes
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirValueParameterSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.isEquals
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.impl.FirImplicitAnyTypeRef
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
@@ -192,7 +191,7 @@ object FirValueClassDeclarationChecker : FirRegularClassChecker() {
|
||||
)
|
||||
}
|
||||
|
||||
primaryConstructorParameter.returnTypeRef.isInapplicableParameterType() -> {
|
||||
primaryConstructorParameter.returnTypeRef.isInapplicableParameterType(context.session) -> {
|
||||
reporter.reportOn(
|
||||
primaryConstructorParameter.returnTypeRef.source,
|
||||
FirErrors.VALUE_CLASS_HAS_INAPPLICABLE_PARAMETER_TYPE,
|
||||
@@ -227,7 +226,7 @@ object FirValueClassDeclarationChecker : FirRegularClassChecker() {
|
||||
if (it !is FirSimpleFunction) {
|
||||
return@forEach
|
||||
}
|
||||
if (it.isEquals()) equalsFromAnyOverriding = it
|
||||
if (it.isEquals(context.session)) equalsFromAnyOverriding = it
|
||||
if (it.isTypedEqualsInValueClass(context.session)) typedEquals = it
|
||||
}
|
||||
equalsFromAnyOverriding to typedEquals
|
||||
@@ -268,8 +267,8 @@ object FirValueClassDeclarationChecker : FirRegularClassChecker() {
|
||||
return isVararg || !primaryConstructorProperty.isVal || isOpen
|
||||
}
|
||||
|
||||
private fun FirTypeRef.isInapplicableParameterType() =
|
||||
isUnit || isNothing
|
||||
private fun FirTypeRef.isInapplicableParameterType(session: FirSession): Boolean =
|
||||
coneType.fullyExpandedType(session).let { it.isUnit || it.isNothing }
|
||||
|
||||
private fun ConeKotlinType.isGenericArrayOfTypeParameter(): Boolean {
|
||||
if (this.typeArguments.firstOrNull() is ConeStarProjection || !isPotentiallyArray())
|
||||
|
||||
+3
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.fir.languageVersionSettings
|
||||
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.FirErrorTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.UnexpandedTypeCheck
|
||||
import org.jetbrains.kotlin.fir.types.coneType
|
||||
import org.jetbrains.kotlin.fir.types.isArrayType
|
||||
|
||||
@@ -50,6 +51,8 @@ object FirNamedVarargChecker : FirCallChecker() {
|
||||
val typeRef = argument.expression.typeRef
|
||||
if (typeRef is FirErrorTypeRef) return
|
||||
if (argument.expression is FirArrayOfCall) return
|
||||
|
||||
@OptIn(UnexpandedTypeCheck::class)
|
||||
if (allowAssignArray && typeRef.isArrayType) return
|
||||
|
||||
if (isAnnotation) {
|
||||
|
||||
+1
@@ -30,6 +30,7 @@ object FirNotNullAssertionChecker : FirCheckNotNullCallChecker() {
|
||||
}
|
||||
// TODO: use of Unit is subject to change.
|
||||
// See BodyResolveComponents.typeForQualifier in ResolveUtils.kt which returns Unit for no value type.
|
||||
@OptIn(UnexpandedTypeCheck::class)
|
||||
if (argument is FirResolvedQualifier && argument.typeRef.isUnit) {
|
||||
// Would be reported as NO_COMPANION_OBJECT
|
||||
return
|
||||
|
||||
+5
-1
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol
|
||||
import org.jetbrains.kotlin.fir.types.UnexpandedTypeCheck
|
||||
import org.jetbrains.kotlin.fir.types.isUnit
|
||||
|
||||
object FirStandaloneQualifierChecker : FirResolvedQualifierChecker() {
|
||||
@@ -26,8 +27,11 @@ object FirStandaloneQualifierChecker : FirResolvedQualifierChecker() {
|
||||
if (lastQualifiedAccess?.explicitReceiver === expression || lastQualifiedAccess?.dispatchReceiver === expression) return
|
||||
val lastGetClass = context.getClassCalls.lastOrNull()
|
||||
if (lastGetClass?.argument === expression) return
|
||||
// Note: if it's real Unit, it will be filtered by ClassKind.OBJECT check below
|
||||
|
||||
// Note: if it's real Unit, it will be filtered by ClassKind.OBJECT check below in reportErrorOn
|
||||
@OptIn(UnexpandedTypeCheck::class)
|
||||
if (!expression.typeRef.isUnit) return
|
||||
|
||||
expression.symbol.reportErrorOn(expression.source, context, reporter)
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -13,6 +13,8 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirSingleExpressionBlock
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.types.coneType
|
||||
import org.jetbrains.kotlin.fir.types.isUnit
|
||||
|
||||
object RedundantReturnUnitType : FirSimpleFunctionChecker() {
|
||||
@@ -23,7 +25,7 @@ object RedundantReturnUnitType : FirSimpleFunctionChecker() {
|
||||
if (declaration.source?.kind is KtFakeSourceElementKind) return
|
||||
if (returnType.annotations.isNotEmpty()) return
|
||||
|
||||
if (returnType.isUnit) {
|
||||
if (returnType.coneType.fullyExpandedType(context.session).isUnit) {
|
||||
reporter.reportOn(declaration.returnTypeRef.source, FirErrors.REDUNDANT_RETURN_UNIT_TYPE, context)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user