Move DeclarationDescriptor.substitute to separate interface Substitutable
To get rid of pointless/confusing implementations in ModuleDescriptor, PackageViewDescriptor, TypeParameterDescriptor and others. Note that there are still implementations that do not make sense, for example in those subclasses of VariableDescriptor which are not also subclasses of CallableMemberDescriptor (e.g. ValueParameterDescriptor). Those can be removed by making CallableMemberDescriptor (instead of CallableDescriptor) inherit from Substitutable. However, that would require more changes in the compiler because CallableDescriptor is used rather often in places where in fact only CallableMemberDescriptor instances can appear. Explicit return types and casts are required in some places now because there's no single non-trivial supertype for ClassifierDescriptorWithTypeParameters and CallableDescriptor. Previously it was DeclarationDescriptorWithVisibility, now it's both that and Substitutable<...>
This commit is contained in:
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorVisitor;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor;
|
||||
|
||||
public class RootContext extends CodegenContext<RootContext.FakeDescriptor> {
|
||||
private final GenerationState state;
|
||||
@@ -56,11 +55,6 @@ public class RootContext extends CodegenContext<RootContext.FakeDescriptor> {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeclarationDescriptor substitute(@NotNull TypeSubstitutor substitutor) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||
throw new IllegalStateException();
|
||||
|
||||
@@ -91,7 +91,7 @@ class OverloadResolver(
|
||||
|
||||
collectModulePackageMembersWithSameName(
|
||||
packageMembersByName,
|
||||
c.functions.values + c.declaredClasses.values + c.typeAliases.values,
|
||||
(c.functions.values as Collection<DeclarationDescriptor>) + c.declaredClasses.values + c.typeAliases.values,
|
||||
overloadFilter
|
||||
) {
|
||||
scope, name ->
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ object UnderscoreUsageChecker : CallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
|
||||
if (resolvedCall is VariableAsFunctionResolvedCall) return
|
||||
val descriptor = resolvedCall.resultingDescriptor
|
||||
val namedDescriptor = if (descriptor is ConstructorDescriptor) descriptor.containingDeclaration else descriptor
|
||||
val namedDescriptor: DeclarationDescriptor = (descriptor as? ConstructorDescriptor)?.containingDeclaration ?: descriptor
|
||||
if (!namedDescriptor.name.asString().isUnderscoreOnlyName()) return
|
||||
checkCallElement(resolvedCall.call.callElement, context)
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@ import org.jetbrains.kotlin.resolve.source.KotlinSourceElement
|
||||
import org.jetbrains.kotlin.script.getScriptExternalDependencies
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.storage.getValue
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
|
||||
data class FileScopes(val lexicalScope: LexicalScope, val importingScope: ImportingScope, val importResolver: ImportResolver)
|
||||
@@ -236,7 +235,6 @@ class FileScopeFactory(
|
||||
|
||||
override fun getOriginal() = this
|
||||
override val annotations: Annotations get() = Annotations.EMPTY
|
||||
override fun substitute(substitutor: TypeSubstitutor) = this
|
||||
|
||||
override fun <R : Any?, D : Any?> accept(visitor: DeclarationDescriptorVisitor<R, D>?, data: D): R {
|
||||
throw UnsupportedOperationException()
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.resolve.lazy.LazyEntity
|
||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.source.toSourceElement
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
|
||||
abstract class LazyAnnotationsContext(
|
||||
val annotationResolver: AnnotationResolver,
|
||||
@@ -172,7 +171,6 @@ class LazyAnnotationDescriptor(
|
||||
override fun getName() = Name.special("< file descriptor for annotation resolution >")
|
||||
|
||||
private fun error(): Nothing = error("This method should not be called")
|
||||
override fun substitute(substitutor: TypeSubstitutor): DeclarationDescriptor? = error()
|
||||
override fun <R : Any?, D : Any?> accept(visitor: DeclarationDescriptorVisitor<R, D>?, data: D): R = error()
|
||||
override fun acceptVoid(visitor: DeclarationDescriptorVisitor<Void, Void>?) = error()
|
||||
|
||||
|
||||
-4
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
|
||||
interface IrBuiltinsPackageFragmentDescriptor : PackageFragmentDescriptor
|
||||
|
||||
@@ -40,7 +39,6 @@ class IrBuiltinsPackageFragmentDescriptorImpl(
|
||||
override fun getOriginal(): DeclarationDescriptorWithSource = this
|
||||
override fun getSource(): SourceElement = SourceElement.NO_SOURCE
|
||||
override val annotations: Annotations = Annotations.EMPTY
|
||||
override fun substitute(substitutor: TypeSubstitutor): DeclarationDescriptor = throw UnsupportedOperationException()
|
||||
|
||||
override fun <R : Any?, D : Any?> accept(visitor: DeclarationDescriptorVisitor<R, D>, data: D): R {
|
||||
return visitor.visitPackageFragmentDescriptor(this, data)
|
||||
@@ -50,5 +48,3 @@ class IrBuiltinsPackageFragmentDescriptorImpl(
|
||||
visitor.visitPackageFragmentDescriptor(this, null)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
-2
@@ -45,7 +45,6 @@ import org.jetbrains.kotlin.test.KotlinTestUtils.TestFileFactoryNoModules
|
||||
import org.jetbrains.kotlin.test.util.DescriptorValidator.ValidationVisitor.errorTypesForbidden
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator
|
||||
import org.jetbrains.kotlin.test.util.RecursiveDescriptorComparator.Configuration
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
import java.io.File
|
||||
@@ -221,7 +220,6 @@ abstract class AbstractJvmRuntimeDescriptorLoaderTest : TestCaseWithTmpdir() {
|
||||
|
||||
override fun getContainingDeclaration() = null
|
||||
override fun getOriginal() = throw UnsupportedOperationException()
|
||||
override fun substitute(substitutor: TypeSubstitutor) = throw UnsupportedOperationException()
|
||||
override fun acceptVoid(visitor: DeclarationDescriptorVisitor<Void, Void>?) = throw UnsupportedOperationException()
|
||||
override fun getName() = throw UnsupportedOperationException()
|
||||
override val annotations: Annotations
|
||||
|
||||
Reference in New Issue
Block a user