Report incomplete hierarchy error
This is the case when you reference a Java class in Kotlin whose superclass is not resolved. Previously this fact was swallowed by LazyJavaClassDescriptor leading to mysterious compilation errors #KT-5129 Fixed
This commit is contained in:
+5
@@ -19,11 +19,16 @@ package org.jetbrains.kotlin.load.java.components;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ErrorReporter {
|
||||
void reportIncompatibleAbiVersion(@NotNull KotlinJvmBinaryClass kotlinClass, int actualVersion);
|
||||
|
||||
void reportIncompleteHierarchy(@NotNull ClassDescriptor descriptor, @NotNull List<String> unresolvedSuperClasses);
|
||||
|
||||
void reportCannotInferVisibility(@NotNull CallableMemberDescriptor descriptor);
|
||||
|
||||
void reportLoadingError(@NotNull String message, @Nullable Exception exception);
|
||||
|
||||
+27
-12
@@ -30,10 +30,13 @@ import org.jetbrains.kotlin.load.java.lazy.resolveAnnotations
|
||||
import org.jetbrains.kotlin.load.java.lazy.types.toAttributes
|
||||
import org.jetbrains.kotlin.resolve.scopes.InnerClassesScopeWrapper
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.utils.*
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.types.AbstractClassTypeConstructor
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.kotlin.utils.toReadOnlyList
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaType
|
||||
import org.jetbrains.kotlin.load.java.structure.JavaClassifierType
|
||||
|
||||
class LazyJavaClassDescriptor(
|
||||
private val outerC: LazyJavaResolverContext,
|
||||
@@ -106,23 +109,35 @@ class LazyJavaClassDescriptor(
|
||||
jClass.getTypeParameters().map {
|
||||
p ->
|
||||
c.typeParameterResolver.resolveTypeParameter(p)
|
||||
?: throw AssertionError("Parameter $p surely belongs to class ${jClass}, so it must be resolved")
|
||||
?: throw AssertionError("Parameter $p surely belongs to class $jClass, so it must be resolved")
|
||||
}
|
||||
}
|
||||
|
||||
override fun getParameters(): List<TypeParameterDescriptor> = parameters()
|
||||
|
||||
private val supertypes = c.storageManager.createLazyValue<Collection<JetType>> {
|
||||
jClass.getSupertypes().stream()
|
||||
.map {
|
||||
supertype ->
|
||||
c.typeResolver.transformJavaType(supertype, TypeUsage.SUPERTYPE.toAttributes())
|
||||
}
|
||||
.filter { supertype -> !supertype.isError() && !KotlinBuiltIns.isAnyOrNullableAny(supertype) }
|
||||
.toList()
|
||||
.ifEmpty {
|
||||
listOf(KotlinBuiltIns.getInstance().getAnyType())
|
||||
}
|
||||
val javaTypes = jClass.getSupertypes()
|
||||
val result = ArrayList<JetType>(javaTypes.size())
|
||||
val incomplete = ArrayList<JavaType>(0)
|
||||
|
||||
for (javaType in javaTypes) {
|
||||
val jetType = c.typeResolver.transformJavaType(javaType, TypeUsage.SUPERTYPE.toAttributes())
|
||||
if (jetType.isError()) {
|
||||
incomplete.add(javaType)
|
||||
continue
|
||||
}
|
||||
if (!KotlinBuiltIns.isAnyOrNullableAny(jetType)) {
|
||||
result.add(jetType)
|
||||
}
|
||||
}
|
||||
|
||||
if (incomplete.isNotEmpty()) {
|
||||
c.errorReporter.reportIncompleteHierarchy(getDeclarationDescriptor(), incomplete.map { javaType ->
|
||||
(javaType as JavaClassifierType).getPresentableText()
|
||||
})
|
||||
}
|
||||
|
||||
if (result.isNotEmpty()) result.toReadOnlyList() else listOf(KotlinBuiltIns.getInstance().getAnyType())
|
||||
}
|
||||
|
||||
override fun getSupertypes(): Collection<JetType> = supertypes()
|
||||
|
||||
Reference in New Issue
Block a user