Check if the class is special by FQ name
This is needed because our built-ins can be loaded with two different mechanisms (deserialization and lazy resolve) and, when that happens, corresponding descriptors aren't equal to each other, so one of two resolved descriptors for Any (or the same with Nothing) was never considered to be a "special class" with no supertypes
This commit is contained in:
@@ -43,6 +43,7 @@ import org.jetbrains.jet.di.InjectorForJavaDescriptorResolverUtil
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||
|
||||
public class BuiltInsSerializer(val out: PrintStream?) {
|
||||
private var totalSize = 0
|
||||
@@ -96,11 +97,8 @@ public class BuiltInsSerializer(val out: PrintStream?) {
|
||||
// DescriptorValidator.validate(packageView)
|
||||
|
||||
val serializer = DescriptorSerializer(object : SerializerExtension() {
|
||||
private val set = setOf("Any", "Nothing")
|
||||
|
||||
override fun hasSupertypes(descriptor: ClassDescriptor): Boolean {
|
||||
return descriptor.getName().asString() !in set
|
||||
}
|
||||
override fun hasSupertypes(descriptor: ClassDescriptor): Boolean =
|
||||
!KotlinBuiltIns.isSpecialClassWithNoSupertypes(descriptor)
|
||||
})
|
||||
|
||||
val classNames = ArrayList<Name>()
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.lazy;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -37,7 +35,6 @@ import org.jetbrains.jet.lang.resolve.lazy.declarations.PackageMemberDeclaration
|
||||
import org.jetbrains.jet.lang.resolve.lazy.descriptors.LazyClassDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.descriptors.LazyPackageDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.name.SpecialNames;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
@@ -70,8 +67,6 @@ public class ResolveSession implements KotlinCodeAnalyzer {
|
||||
private final BindingTrace trace;
|
||||
private final DeclarationProviderFactory declarationProviderFactory;
|
||||
|
||||
private final Predicate<FqNameUnsafe> specialClasses;
|
||||
|
||||
private final Function<FqName, Name> classifierAliases;
|
||||
|
||||
private final MemoizedFunctionToNullable<FqName, LazyPackageDescriptor> packages;
|
||||
@@ -131,7 +126,6 @@ public class ResolveSession implements KotlinCodeAnalyzer {
|
||||
this.module = rootDescriptor;
|
||||
|
||||
this.classifierAliases = NO_ALIASES;
|
||||
this.specialClasses = Predicates.alwaysFalse();
|
||||
|
||||
this.packages = storageManager.createMemoizedFunctionWithNullableValues(new MemoizedFunctionToNullable<FqName, LazyPackageDescriptor>() {
|
||||
@Nullable
|
||||
@@ -187,10 +181,6 @@ public class ResolveSession implements KotlinCodeAnalyzer {
|
||||
return new LazyPackageDescriptor(module, fqName, this, provider);
|
||||
}
|
||||
|
||||
public boolean isClassSpecial(@NotNull FqNameUnsafe fqName) {
|
||||
return specialClasses.apply(fqName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleDescriptor getModuleDescriptor() {
|
||||
return module;
|
||||
|
||||
+1
-1
@@ -364,7 +364,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyEnti
|
||||
new Function0<Collection<JetType>>() {
|
||||
@Override
|
||||
public Collection<JetType> invoke() {
|
||||
if (resolveSession.isClassSpecial(DescriptorUtils.getFqName(LazyClassDescriptor.this))) {
|
||||
if (KotlinBuiltIns.isSpecialClassWithNoSupertypes(LazyClassDescriptor.this)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
@@ -235,8 +235,7 @@ public class DescriptorValidator {
|
||||
|
||||
Collection<JetType> supertypes = descriptor.getTypeConstructor().getSupertypes();
|
||||
if (supertypes.isEmpty() && descriptor.getKind() != ClassKind.TRAIT
|
||||
&& KotlinBuiltIns.getInstance().getAny() != descriptor
|
||||
&& KotlinBuiltIns.getInstance().getNothing() != descriptor) {
|
||||
&& !KotlinBuiltIns.isSpecialClassWithNoSupertypes(descriptor)) {
|
||||
report(collector, descriptor, "No supertypes for non-trait");
|
||||
}
|
||||
validateTypes(descriptor, collector, supertypes);
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.descriptors.impl.ValueParameterDescriptorImpl;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
@@ -893,6 +894,12 @@ public class KotlinBuiltIns {
|
||||
|
||||
// Recognized & special
|
||||
|
||||
public static boolean isSpecialClassWithNoSupertypes(@NotNull ClassDescriptor descriptor) {
|
||||
FqNameUnsafe fqName = DescriptorUtils.getFqName(descriptor);
|
||||
return BUILT_INS_PACKAGE_FQ_NAME.child(Name.identifier("Any")).toUnsafe().equals(fqName) ||
|
||||
BUILT_INS_PACKAGE_FQ_NAME.child(Name.identifier("Nothing")).toUnsafe().equals(fqName);
|
||||
}
|
||||
|
||||
public boolean isNothing(@NotNull JetType type) {
|
||||
return isNothingOrNullableNothing(type)
|
||||
&& !type.isNullable();
|
||||
|
||||
Reference in New Issue
Block a user