Do not report KCLASS_WITH_NULLABLE_ARGUMENT_IN_SIGNATURE anymore
It was only reported in already erroneous cases
This commit is contained in:
@@ -421,8 +421,6 @@ public interface Errors {
|
||||
DiagnosticFactory1<KtDeclaration, Collection<KotlinType>> AMBIGUOUS_ANONYMOUS_TYPE_INFERRED =
|
||||
DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE);
|
||||
|
||||
DiagnosticFactory0<KtNamedDeclaration>
|
||||
KCLASS_WITH_NULLABLE_ARGUMENT_IN_SIGNATURE = DiagnosticFactory0.create(ERROR, PositioningStrategies.DECLARATION_NAME);
|
||||
DiagnosticFactory1<KtNamedDeclaration, TypeParameterDescriptor>
|
||||
KCLASS_WITH_NULLABLE_TYPE_PARAMETER_IN_SIGNATURE = DiagnosticFactory1.create(ERROR, PositioningStrategies.DECLARATION_NAME);
|
||||
|
||||
|
||||
+1
-2
@@ -865,9 +865,8 @@ public class DefaultErrorMessages {
|
||||
MAP.put(DATA_CLASS_NOT_PROPERTY_PARAMETER, "Data class primary constructor must have only property (val / var) parameters");
|
||||
|
||||
MAP.put(AMBIGUOUS_ANONYMOUS_TYPE_INFERRED, "Right-hand side has anonymous type. Please specify type explicitly", TO_STRING);
|
||||
MAP.put(KCLASS_WITH_NULLABLE_ARGUMENT_IN_SIGNATURE, "Please specify type explicitly");
|
||||
MAP.put(KCLASS_WITH_NULLABLE_TYPE_PARAMETER_IN_SIGNATURE,
|
||||
"Please add upper bound Any for type parameter ''{0}'' or specify return type explicitly", NAME);
|
||||
"Declaration has an inconsistent return type. Please add upper bound Any for type parameter ''{0}'' or specify return type explicitly", NAME);
|
||||
|
||||
MAP.put(EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED,
|
||||
"''{0}'' is a member and an extension at the same time. References to such elements are not allowed", NAME);
|
||||
|
||||
+7
-11
@@ -24,9 +24,9 @@ import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.types.UnwrappedType
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
|
||||
import org.jetbrains.kotlin.types.typeUtil.builtIns
|
||||
import org.jetbrains.kotlin.types.typeUtil.contains
|
||||
import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf
|
||||
|
||||
object KClassWithIncorrectTypeArgumentChecker : SimpleDeclarationChecker {
|
||||
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, diagnosticHolder: DiagnosticSink, bindingContext: BindingContext) {
|
||||
@@ -40,31 +40,27 @@ object KClassWithIncorrectTypeArgumentChecker : SimpleDeclarationChecker {
|
||||
val returnType = descriptor.returnType ?: return
|
||||
|
||||
var typeParameterWithoutNotNullableUpperBound: TypeParameterDescriptor? = null
|
||||
val thereIsBadKClassType = returnType.contains {
|
||||
val kClassWithBadArgument = it.isKClassWithBadArgument()
|
||||
returnType.contains { type ->
|
||||
val kClassWithBadArgument = type.isKClassWithBadArgument()
|
||||
if (kClassWithBadArgument) {
|
||||
it.arguments.singleOrNull()?.type?.constructor?.declarationDescriptor?.let {
|
||||
type.arguments.singleOrNull()?.type?.constructor?.declarationDescriptor?.let {
|
||||
if (it is TypeParameterDescriptor && it.containingDeclaration == descriptor) {
|
||||
typeParameterWithoutNotNullableUpperBound = it
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
kClassWithBadArgument
|
||||
}
|
||||
|
||||
if (typeParameterWithoutNotNullableUpperBound != null) {
|
||||
diagnosticHolder.report(Errors.KCLASS_WITH_NULLABLE_TYPE_PARAMETER_IN_SIGNATURE.on(declaration, typeParameterWithoutNotNullableUpperBound!!))
|
||||
}
|
||||
else if (thereIsBadKClassType) {
|
||||
diagnosticHolder.report(Errors.KCLASS_WITH_NULLABLE_ARGUMENT_IN_SIGNATURE.on(declaration))
|
||||
}
|
||||
}
|
||||
|
||||
private fun UnwrappedType.isKClassWithBadArgument(): Boolean {
|
||||
val argumentType = arguments.singleOrNull()?.let { if (it.isStarProjection) null else it.type.unwrap() } ?: return false
|
||||
val klass = (constructor.declarationDescriptor as? ClassDescriptor) ?: return false
|
||||
val klass = constructor.declarationDescriptor as? ClassDescriptor ?: return false
|
||||
|
||||
return KotlinBuiltIns.isKClass(klass) && !KotlinTypeChecker.DEFAULT.isSubtypeOf(argumentType, argumentType.builtIns.anyType)
|
||||
return KotlinBuiltIns.isKClass(klass) && !argumentType.isSubtypeOf(argumentType.builtIns.anyType)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user