Disallow arrays as upper bounds of type parameters
#KT-9189 Fixed
This commit is contained in:
+2
-2
@@ -24,8 +24,6 @@ import org.jetbrains.kotlin.diagnostics.rendering.Renderers;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
import org.jetbrains.kotlin.renderer.Renderer;
|
||||
|
||||
import static org.jetbrains.kotlin.diagnostics.rendering.Renderers.STRING;
|
||||
|
||||
public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
|
||||
|
||||
private static final Renderer<ConflictingJvmDeclarationsData> CONFLICTING_JVM_DECLARATIONS_DATA = new Renderer<ConflictingJvmDeclarationsData>() {
|
||||
@@ -86,6 +84,8 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
|
||||
"Java type mismatch expected {1} but found {0}. Use explicit cast", Renderers.RENDER_TYPE, Renderers.RENDER_TYPE);
|
||||
|
||||
MAP.put(ErrorsJvm.DUPLICATE_CLASS_NAMES, "Duplicate JVM class name ''{0}'' generated from: {1}", Renderers.TO_STRING, Renderers.TO_STRING);
|
||||
|
||||
MAP.put(ErrorsJvm.UPPER_BOUND_CANNOT_BE_ARRAY, "Upper bound of a type parameter cannot be an array");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -71,6 +71,8 @@ public interface ErrorsJvm {
|
||||
|
||||
DiagnosticFactory2<PsiElement, String, String> DUPLICATE_CLASS_NAMES = DiagnosticFactory2.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<PsiElement> UPPER_BOUND_CANNOT_BE_ARRAY = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
enum NullabilityInformationSource {
|
||||
KOTLIN {
|
||||
@NotNull
|
||||
|
||||
+24
-1
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.resolve.jvm.platform
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns.isArray
|
||||
import org.jetbrains.kotlin.cfg.WhenChecker
|
||||
import org.jetbrains.kotlin.container.StorageComponentContainer
|
||||
import org.jetbrains.kotlin.container.useImpl
|
||||
@@ -70,7 +72,8 @@ public object JvmPlatformConfigurator : PlatformConfigurator(
|
||||
ReifiedTypeParameterAnnotationChecker(),
|
||||
NativeFunChecker(),
|
||||
OverloadsAnnotationChecker(),
|
||||
PublicFieldAnnotationChecker()
|
||||
PublicFieldAnnotationChecker(),
|
||||
TypeParameterBoundIsNotArrayChecker()
|
||||
),
|
||||
|
||||
additionalCallCheckers = listOf(
|
||||
@@ -268,6 +271,26 @@ public class PublicFieldAnnotationChecker: DeclarationChecker {
|
||||
}
|
||||
}
|
||||
|
||||
public class TypeParameterBoundIsNotArrayChecker : DeclarationChecker {
|
||||
override fun check(
|
||||
declaration: JetDeclaration,
|
||||
descriptor: DeclarationDescriptor,
|
||||
diagnosticHolder: DiagnosticSink,
|
||||
bindingContext: BindingContext
|
||||
) {
|
||||
val typeParameters = (descriptor as? CallableDescriptor)?.typeParameters
|
||||
?: (descriptor as? ClassDescriptor)?.typeConstructor?.parameters
|
||||
?: return
|
||||
|
||||
for (typeParameter in typeParameters) {
|
||||
if (typeParameter.upperBounds.any { KotlinBuiltIns.isArray(it) || KotlinBuiltIns.isPrimitiveArray(it) }) {
|
||||
val element = DescriptorToSourceUtils.descriptorToDeclaration(typeParameter) ?: declaration
|
||||
diagnosticHolder.report(ErrorsJvm.UPPER_BOUND_CANNOT_BE_ARRAY.on(element))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ReifiedTypeParameterAnnotationChecker : DeclarationChecker {
|
||||
|
||||
override fun check(
|
||||
|
||||
Reference in New Issue
Block a user