Fix race in IDE: inject proper storage manager for type parameters
With NO_LOCKS strategy we can easily end up in a situation when constraint system for a generic call is built incorrectly, producing flaky errors (or don't produce errors at all) Now proper storage manager is injected for all cases except: - IR - Codegen - Serialization plugin - Fake local objects Most likely, NO_LOCKS strategy for these cases is fine as at that point the compiler works in one thread #KT-34786 Fixed
This commit is contained in:
+3
-3
@@ -21,8 +21,6 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import java.util.*
|
||||
|
||||
open class AbstractAccessorForFunctionDescriptor(
|
||||
containingDeclaration: DeclarationDescriptor,
|
||||
@@ -34,7 +32,9 @@ open class AbstractAccessorForFunctionDescriptor(
|
||||
val copy = TypeParameterDescriptorImpl.createForFurtherModification(
|
||||
this, it.annotations, it.isReified,
|
||||
it.variance, it.name,
|
||||
it.index, SourceElement.NO_SOURCE)
|
||||
it.index, SourceElement.NO_SOURCE,
|
||||
it.storageManager
|
||||
)
|
||||
for (upperBound in it.upperBounds) {
|
||||
copy.addUpperBound(upperBound)
|
||||
}
|
||||
|
||||
@@ -76,7 +76,8 @@ fun CallableMemberDescriptor.createTypeParameterWithNewName(
|
||||
descriptor.variance,
|
||||
Name.identifier(newName),
|
||||
descriptor.index,
|
||||
descriptor.source
|
||||
descriptor.source,
|
||||
descriptor.storageManager
|
||||
)
|
||||
descriptor.upperBounds.forEach {
|
||||
newDescriptor.addUpperBound(it)
|
||||
|
||||
@@ -51,7 +51,8 @@ public class JavaResolverUtils {
|
||||
typeParameter.getVariance(),
|
||||
typeParameter.getName(),
|
||||
typeParameter.getIndex(),
|
||||
SourceElement.NO_SOURCE
|
||||
SourceElement.NO_SOURCE,
|
||||
typeParameter.getStorageManager()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -472,7 +472,8 @@ public class DescriptorResolver {
|
||||
}
|
||||
return null;
|
||||
},
|
||||
supertypeLoopsResolver
|
||||
supertypeLoopsResolver,
|
||||
storageManager
|
||||
);
|
||||
trace.record(BindingContext.TYPE_PARAMETER, typeParameter, typeParameterDescriptor);
|
||||
return typeParameterDescriptor;
|
||||
|
||||
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.types.expressions.OperatorConventions
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import java.util.*
|
||||
|
||||
class DynamicCallableDescriptors(storageManager: StorageManager, builtIns: KotlinBuiltIns) {
|
||||
class DynamicCallableDescriptors(private val storageManager: StorageManager, builtIns: KotlinBuiltIns) {
|
||||
|
||||
val dynamicType by storageManager.createLazyValue {
|
||||
createDynamicType(builtIns)
|
||||
@@ -150,7 +150,8 @@ class DynamicCallableDescriptors(storageManager: StorageManager, builtIns: Kotli
|
||||
false,
|
||||
Variance.INVARIANT,
|
||||
Name.identifier("T$index"),
|
||||
index
|
||||
index,
|
||||
storageManager
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -55,6 +55,7 @@ import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy;
|
||||
import org.jetbrains.kotlin.resolve.calls.util.CallMaker;
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.AnnotationsForResolveKt;
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
|
||||
import org.jetbrains.kotlin.storage.StorageManager;
|
||||
import org.jetbrains.kotlin.types.*;
|
||||
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
|
||||
|
||||
@@ -97,15 +98,18 @@ public class ControlStructureTypingUtils {
|
||||
private final CallResolver callResolver;
|
||||
private final DataFlowAnalyzer dataFlowAnalyzer;
|
||||
private final ModuleDescriptor moduleDescriptor;
|
||||
private final StorageManager storageManager;
|
||||
|
||||
public ControlStructureTypingUtils(
|
||||
@NotNull CallResolver callResolver,
|
||||
@NotNull DataFlowAnalyzer dataFlowAnalyzer,
|
||||
@NotNull ModuleDescriptor moduleDescriptor
|
||||
@NotNull ModuleDescriptor moduleDescriptor,
|
||||
@NotNull StorageManager storageManager
|
||||
) {
|
||||
this.callResolver = callResolver;
|
||||
this.dataFlowAnalyzer = dataFlowAnalyzer;
|
||||
this.moduleDescriptor = moduleDescriptor;
|
||||
this.storageManager = storageManager;
|
||||
}
|
||||
|
||||
/*package*/ ResolvedCall<FunctionDescriptor> resolveSpecialConstructionAsCall(
|
||||
@@ -202,7 +206,7 @@ public class ControlStructureTypingUtils {
|
||||
|
||||
TypeParameterDescriptor typeParameter = TypeParameterDescriptorImpl.createWithDefaultBound(
|
||||
function, Annotations.Companion.getEMPTY(), false, Variance.INVARIANT,
|
||||
construct.getSpecialTypeParameterName(), 0);
|
||||
construct.getSpecialTypeParameterName(), 0, storageManager);
|
||||
|
||||
KotlinType type = typeParameter.getDefaultType();
|
||||
KotlinType nullableType = TypeUtils.makeNullable(type);
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.types.*
|
||||
|
||||
class IrBuiltIns(
|
||||
@@ -91,7 +92,7 @@ class IrBuiltIns(
|
||||
SourceElement.NO_SOURCE
|
||||
).apply {
|
||||
typeParameterDescriptor = TypeParameterDescriptorImpl.createWithDefaultBound(
|
||||
this, Annotations.EMPTY, true, Variance.INVARIANT, Name.identifier("T0"), 0
|
||||
this, Annotations.EMPTY, true, Variance.INVARIANT, Name.identifier("T0"), 0, LockBasedStorageManager.NO_LOCKS
|
||||
)
|
||||
|
||||
valueParameterDescriptor = ValueParameterDescriptorImpl(
|
||||
@@ -153,7 +154,8 @@ class IrBuiltIns(
|
||||
SourceElement.NO_SOURCE
|
||||
).apply {
|
||||
typeParameterDescriptor = TypeParameterDescriptorImpl.createForFurtherModification(
|
||||
this, Annotations.EMPTY, false, Variance.INVARIANT, Name.identifier("T0"), 0, SourceElement.NO_SOURCE
|
||||
this, Annotations.EMPTY, false, Variance.INVARIANT, Name.identifier("T0"),
|
||||
0, SourceElement.NO_SOURCE, LockBasedStorageManager.NO_LOCKS
|
||||
).apply {
|
||||
addUpperBound(any)
|
||||
setInitialized()
|
||||
|
||||
@@ -288,6 +288,7 @@ open class WrappedTypeParameterDescriptor(
|
||||
|
||||
override fun getDefaultType() = _defaultType
|
||||
|
||||
override fun getStorageManager() = LockBasedStorageManager.NO_LOCKS
|
||||
|
||||
override fun getContainingDeclaration() = (owner.parent as IrDeclaration).descriptor
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.jetbrains.kotlin.resolve.TypeResolver;
|
||||
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
|
||||
import org.jetbrains.kotlin.resolve.scopes.*;
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.ScopeUtilsKt;
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
||||
import org.jetbrains.kotlin.test.DummyTraces;
|
||||
import org.jetbrains.kotlin.test.KotlinTestWithEnvironment;
|
||||
@@ -77,7 +78,8 @@ public class TypeUnifierTest extends KotlinTestWithEnvironment {
|
||||
|
||||
private TypeParameterDescriptor createTypeVariable(String name) {
|
||||
return TypeParameterDescriptorImpl.createWithDefaultBound(
|
||||
module, Annotations.Companion.getEMPTY(), false, Variance.INVARIANT, Name.identifier(name), 0
|
||||
module, Annotations.Companion.getEMPTY(), false, Variance.INVARIANT,
|
||||
Name.identifier(name), 0, LockBasedStorageManager.NO_LOCKS
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ class FunctionClassDescriptor(
|
||||
|
||||
fun typeParameter(variance: Variance, name: String) {
|
||||
result.add(TypeParameterDescriptorImpl.createWithDefaultBound(
|
||||
this@FunctionClassDescriptor, Annotations.EMPTY, false, variance, Name.identifier(name), result.size
|
||||
this@FunctionClassDescriptor, Annotations.EMPTY, false, variance, Name.identifier(name), result.size, storageManager
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ private val FAKE_CONTINUATION_CLASS_DESCRIPTOR_EXPERIMENTAL =
|
||||
visibility = Visibilities.PUBLIC
|
||||
setTypeParameterDescriptors(
|
||||
TypeParameterDescriptorImpl.createWithDefaultBound(
|
||||
this, Annotations.EMPTY, false, Variance.IN_VARIANCE, Name.identifier("T"), 0
|
||||
this, Annotations.EMPTY, false, Variance.IN_VARIANCE, Name.identifier("T"), 0, LockBasedStorageManager.NO_LOCKS
|
||||
).let(::listOf)
|
||||
)
|
||||
createTypeConstructor()
|
||||
@@ -47,7 +47,7 @@ private val FAKE_CONTINUATION_CLASS_DESCRIPTOR_RELEASE =
|
||||
visibility = Visibilities.PUBLIC
|
||||
setTypeParameterDescriptors(
|
||||
TypeParameterDescriptorImpl.createWithDefaultBound(
|
||||
this, Annotations.EMPTY, false, Variance.IN_VARIANCE, Name.identifier("T"), 0
|
||||
this, Annotations.EMPTY, false, Variance.IN_VARIANCE, Name.identifier("T"), 0, LockBasedStorageManager.NO_LOCKS
|
||||
).let(::listOf)
|
||||
)
|
||||
createTypeConstructor()
|
||||
|
||||
@@ -53,7 +53,7 @@ class NotFoundClasses(private val storageManager: StorageManager, private val mo
|
||||
) : ClassDescriptorBase(storageManager, container, name, SourceElement.NO_SOURCE, /* isExternal = */ false) {
|
||||
private val typeParameters = (0 until numberOfDeclaredTypeParameters).map { index ->
|
||||
TypeParameterDescriptorImpl.createWithDefaultBound(
|
||||
this, Annotations.EMPTY, false, Variance.INVARIANT, Name.identifier("T$index"), index
|
||||
this, Annotations.EMPTY, false, Variance.INVARIANT, Name.identifier("T$index"), index, storageManager
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.descriptors;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.storage.StorageManager;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeConstructor;
|
||||
import org.jetbrains.kotlin.types.Variance;
|
||||
@@ -53,4 +54,7 @@ public interface TypeParameterDescriptor extends ClassifierDescriptor, TypeParam
|
||||
* 3. 'getTypeConstructor' is the same as for original declaration (at least in means of 'equals')
|
||||
*/
|
||||
boolean isCapturedFromOuterDeclaration();
|
||||
|
||||
@NotNull
|
||||
StorageManager getStorageManager();
|
||||
}
|
||||
|
||||
+8
@@ -42,6 +42,7 @@ public abstract class AbstractTypeParameterDescriptor extends DeclarationDescrip
|
||||
|
||||
private final NotNullLazyValue<TypeConstructor> typeConstructor;
|
||||
private final NotNullLazyValue<SimpleType> defaultType;
|
||||
private final StorageManager storageManager;
|
||||
|
||||
protected AbstractTypeParameterDescriptor(
|
||||
@NotNull final StorageManager storageManager,
|
||||
@@ -82,6 +83,7 @@ public abstract class AbstractTypeParameterDescriptor extends DeclarationDescrip
|
||||
);
|
||||
}
|
||||
});
|
||||
this.storageManager = storageManager;
|
||||
}
|
||||
|
||||
protected abstract void reportSupertypeLoopError(@NotNull KotlinType type);
|
||||
@@ -139,6 +141,12 @@ public abstract class AbstractTypeParameterDescriptor extends DeclarationDescrip
|
||||
return visitor.visitTypeParameterDescriptor(this, data);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public StorageManager getStorageManager() {
|
||||
return storageManager;
|
||||
}
|
||||
|
||||
private class TypeParameterTypeConstructor extends AbstractTypeConstructor {
|
||||
|
||||
private final SupertypeLoopChecker supertypeLoopChecker;
|
||||
|
||||
+21
-13
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
|
||||
import org.jetbrains.kotlin.storage.StorageManager;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.KotlinTypeKt;
|
||||
import org.jetbrains.kotlin.types.Variance;
|
||||
@@ -47,10 +47,12 @@ public class TypeParameterDescriptorImpl extends AbstractTypeParameterDescriptor
|
||||
boolean reified,
|
||||
@NotNull Variance variance,
|
||||
@NotNull Name name,
|
||||
int index
|
||||
int index,
|
||||
@NotNull StorageManager storageManager
|
||||
) {
|
||||
TypeParameterDescriptorImpl typeParameterDescriptor =
|
||||
createForFurtherModification(containingDeclaration, annotations, reified, variance, name, index, SourceElement.NO_SOURCE);
|
||||
TypeParameterDescriptorImpl typeParameterDescriptor = createForFurtherModification(
|
||||
containingDeclaration, annotations, reified, variance, name, index, SourceElement.NO_SOURCE, storageManager
|
||||
);
|
||||
typeParameterDescriptor.addUpperBound(getBuiltIns(containingDeclaration).getDefaultBound());
|
||||
typeParameterDescriptor.setInitialized();
|
||||
return typeParameterDescriptor;
|
||||
@@ -63,10 +65,13 @@ public class TypeParameterDescriptorImpl extends AbstractTypeParameterDescriptor
|
||||
@NotNull Variance variance,
|
||||
@NotNull Name name,
|
||||
int index,
|
||||
@NotNull SourceElement source
|
||||
@NotNull SourceElement source,
|
||||
@NotNull StorageManager storageManager
|
||||
) {
|
||||
return createForFurtherModification(containingDeclaration, annotations, reified, variance, name, index, source,
|
||||
/* reportSupertypeLoopError = */ null, SupertypeLoopChecker.EMPTY.INSTANCE);
|
||||
return createForFurtherModification(
|
||||
containingDeclaration, annotations, reified, variance, name, index, source,
|
||||
null, SupertypeLoopChecker.EMPTY.INSTANCE, storageManager
|
||||
);
|
||||
}
|
||||
|
||||
public static TypeParameterDescriptorImpl createForFurtherModification(
|
||||
@@ -78,10 +83,13 @@ public class TypeParameterDescriptorImpl extends AbstractTypeParameterDescriptor
|
||||
int index,
|
||||
@NotNull SourceElement source,
|
||||
@Nullable Function1<KotlinType, Void> reportCycleError,
|
||||
@NotNull SupertypeLoopChecker supertypeLoopsResolver
|
||||
@NotNull SupertypeLoopChecker supertypeLoopsResolver,
|
||||
@NotNull StorageManager storageManager
|
||||
) {
|
||||
return new TypeParameterDescriptorImpl(containingDeclaration, annotations, reified, variance, name, index, source, reportCycleError,
|
||||
supertypeLoopsResolver);
|
||||
return new TypeParameterDescriptorImpl(
|
||||
containingDeclaration, annotations, reified, variance, name,
|
||||
index, source, reportCycleError, supertypeLoopsResolver, storageManager
|
||||
);
|
||||
}
|
||||
|
||||
private final List<KotlinType> upperBounds = new ArrayList<KotlinType>(1);
|
||||
@@ -96,10 +104,10 @@ public class TypeParameterDescriptorImpl extends AbstractTypeParameterDescriptor
|
||||
int index,
|
||||
@NotNull SourceElement source,
|
||||
@Nullable Function1<KotlinType, Void> reportCycleError,
|
||||
@NotNull SupertypeLoopChecker supertypeLoopsChecker
|
||||
@NotNull SupertypeLoopChecker supertypeLoopsChecker,
|
||||
@NotNull StorageManager storageManager
|
||||
) {
|
||||
super(LockBasedStorageManager.NO_LOCKS, containingDeclaration, annotations, name, variance, reified, index, source,
|
||||
supertypeLoopsChecker);
|
||||
super(storageManager, containingDeclaration, annotations, name, variance, reified, index, source, supertypeLoopsChecker);
|
||||
this.reportCycleError = reportCycleError;
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,9 @@ public class DescriptorSubstitutor {
|
||||
@NotNull DeclarationDescriptor newContainingDeclaration,
|
||||
@NotNull @Mutable List<TypeParameterDescriptor> result
|
||||
) {
|
||||
TypeSubstitutor substitutor = substituteTypeParameters(typeParameters, originalSubstitution, newContainingDeclaration, result, null);
|
||||
TypeSubstitutor substitutor = substituteTypeParameters(
|
||||
typeParameters, originalSubstitution, newContainingDeclaration, result, null
|
||||
);
|
||||
if (substitutor == null) throw new AssertionError("Substitution failed");
|
||||
return substitutor;
|
||||
}
|
||||
@@ -65,7 +67,8 @@ public class DescriptorSubstitutor {
|
||||
descriptor.getVariance(),
|
||||
descriptor.getName(),
|
||||
index++,
|
||||
SourceElement.NO_SOURCE
|
||||
SourceElement.NO_SOURCE,
|
||||
descriptor.getStorageManager()
|
||||
);
|
||||
|
||||
mutableSubstitution.put(descriptor.getTypeConstructor(), new TypeProjectionImpl(substituted.getDefaultType()));
|
||||
|
||||
+4
-1
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithAllCompilerChecks
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyzeWithContent
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.util.getJavaClassDescriptor
|
||||
import org.jetbrains.kotlin.idea.core.*
|
||||
@@ -51,6 +52,7 @@ import org.jetbrains.kotlin.idea.core.util.isMultiLine
|
||||
import org.jetbrains.kotlin.idea.imports.importableFqName
|
||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createClass.ClassKind
|
||||
import org.jetbrains.kotlin.idea.refactoring.*
|
||||
import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
import org.jetbrains.kotlin.idea.util.DialogWithEditor
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
|
||||
@@ -416,7 +418,8 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
||||
false,
|
||||
Variance.INVARIANT,
|
||||
Name.identifier(parameterNames[it]),
|
||||
it
|
||||
it,
|
||||
jetFileToEdit.getResolutionFacade().frontendService()
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+17
-3
@@ -23,15 +23,19 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptorIfAny
|
||||
import org.jetbrains.kotlin.idea.quickfix.KotlinIntentionActionFactoryWithDelegate
|
||||
import org.jetbrains.kotlin.idea.quickfix.QuickFixWithDelegateFactory
|
||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createClass.getUnsubstitutedTypeConstraintInfo
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.isObjectOrNonInnerClass
|
||||
import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch
|
||||
import org.jetbrains.kotlin.psi.psiUtil.parents
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.TypeProjectionImpl
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
@@ -63,7 +67,9 @@ object CreateTypeParameterByUnresolvedRefActionFactory : KotlinIntentionActionFa
|
||||
it is KtProperty || it is KtNamedFunction || it is KtClass
|
||||
} as? KtTypeParameterListOwner ?: return null
|
||||
val containingDescriptor = declaration.resolveToDescriptorIfAny() ?: return null
|
||||
val fakeTypeParameter = createFakeTypeParameterDescriptor(containingDescriptor, newName)
|
||||
val fakeTypeParameter = createFakeTypeParameterDescriptor(
|
||||
containingDescriptor, newName, declaration.getResolutionFacade().frontendService<StorageManager>()
|
||||
)
|
||||
val upperBoundType = getUnsubstitutedTypeConstraintInfo(element)?.let {
|
||||
it.performSubstitution(it.typeParameter.typeConstructor to TypeProjectionImpl(fakeTypeParameter.defaultType))?.upperBound
|
||||
}
|
||||
@@ -98,9 +104,17 @@ object CreateTypeParameterByUnresolvedRefActionFactory : KotlinIntentionActionFa
|
||||
}
|
||||
}
|
||||
|
||||
fun createFakeTypeParameterDescriptor(containingDescriptor: DeclarationDescriptor, name: String): TypeParameterDescriptor {
|
||||
fun createFakeTypeParameterDescriptor(
|
||||
containingDescriptor: DeclarationDescriptor,
|
||||
name: String,
|
||||
storageManager: StorageManager
|
||||
): TypeParameterDescriptor {
|
||||
return TypeParameterDescriptorImpl
|
||||
.createWithDefaultBound(containingDescriptor, Annotations.EMPTY, false, Variance.INVARIANT, Name.identifier(name), -1)
|
||||
.createWithDefaultBound(
|
||||
containingDescriptor, Annotations.EMPTY, false,
|
||||
Variance.INVARIANT, Name.identifier(name), -1,
|
||||
storageManager
|
||||
)
|
||||
}
|
||||
|
||||
fun getPossibleTypeParameterContainers(startFrom: PsiElement): List<KtTypeParameterListOwner> {
|
||||
|
||||
+6
-1
@@ -24,12 +24,14 @@ import com.intellij.psi.search.searches.ReferencesSearch
|
||||
import com.intellij.usageView.UsageViewTypeLocation
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
||||
import org.jetbrains.kotlin.idea.core.addTypeParameter
|
||||
import org.jetbrains.kotlin.idea.core.replaced
|
||||
import org.jetbrains.kotlin.idea.core.util.runSynchronouslyWithProgress
|
||||
import org.jetbrains.kotlin.idea.intentions.InsertExplicitTypeArgumentsIntention
|
||||
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.CreateFromUsageFixBase
|
||||
import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.idea.util.application.runReadAction
|
||||
import org.jetbrains.kotlin.idea.util.application.runWriteAction
|
||||
@@ -37,6 +39,7 @@ import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch
|
||||
import org.jetbrains.kotlin.psi.psiUtil.quoteIfNeeded
|
||||
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import org.jetbrains.kotlin.types.TypeProjectionImpl
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
@@ -104,7 +107,9 @@ class CreateTypeParameterFromUsageFix(
|
||||
?: error("Couldn't create type parameter from '$newTypeParameterText' for '$declaration'")
|
||||
elementsToShorten += newTypeParameter
|
||||
|
||||
val anonymizedTypeParameter = createFakeTypeParameterDescriptor(typeParameter.fakeTypeParameter.containingDeclaration, "_")
|
||||
val anonymizedTypeParameter = createFakeTypeParameterDescriptor(
|
||||
typeParameter.fakeTypeParameter.containingDeclaration, "_", typeParameter.fakeTypeParameter.storageManager
|
||||
)
|
||||
val anonymizedUpperBoundText = upperBoundType?.let {
|
||||
TypeSubstitutor
|
||||
.create(mapOf(typeParameter.fakeTypeParameter.typeConstructor to TypeProjectionImpl(anonymizedTypeParameter.defaultType)))
|
||||
|
||||
+5
-1
@@ -19,11 +19,13 @@ package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createTypeParameter
|
||||
import com.intellij.psi.SmartPsiElementPointer
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
|
||||
import org.jetbrains.kotlin.idea.core.CollectingNameValidator
|
||||
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||
import org.jetbrains.kotlin.idea.quickfix.KotlinIntentionActionFactoryWithDelegate
|
||||
import org.jetbrains.kotlin.idea.quickfix.QuickFixWithDelegateFactory
|
||||
import org.jetbrains.kotlin.idea.resolve.frontendService
|
||||
import org.jetbrains.kotlin.idea.util.getResolutionScope
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -34,6 +36,7 @@ import org.jetbrains.kotlin.psi.KtUserType
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
|
||||
object CreateTypeParameterUnmatchedTypeArgumentActionFactory :
|
||||
KotlinIntentionActionFactoryWithDelegate<KtTypeArgumentList, CreateTypeParameterData>() {
|
||||
@@ -61,11 +64,12 @@ object CreateTypeParameterUnmatchedTypeArgumentActionFactory :
|
||||
scope.findClassifier(Name.identifier(it), NoLookupLocation.FROM_IDE) == null
|
||||
}
|
||||
)
|
||||
val storageManager = element.getResolutionFacade().frontendService<StorageManager>()
|
||||
val typeParameterInfos = suggestedNames.map { name ->
|
||||
TypeParameterInfo(
|
||||
name,
|
||||
null,
|
||||
createFakeTypeParameterDescriptor(referencedDescriptor, name)
|
||||
createFakeTypeParameterDescriptor(referencedDescriptor, name, storageManager)
|
||||
)
|
||||
}
|
||||
return CreateTypeParameterData(referencedDeclaration, typeParameterInfos)
|
||||
|
||||
+3
-2
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
import org.jetbrains.kotlin.resolve.lazy.LazyClassContext
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProvider
|
||||
import org.jetbrains.kotlin.resolve.lazy.descriptors.LazyClassDescriptor
|
||||
import org.jetbrains.kotlin.storage.LockBasedStorageManager
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.KotlinTypeFactory
|
||||
import org.jetbrains.kotlin.types.TypeProjectionImpl
|
||||
@@ -130,7 +131,7 @@ object KSerializerDescriptorResolver {
|
||||
thisDescriptor.declaredTypeParameters.mapIndexed { index, param ->
|
||||
TypeParameterDescriptorImpl.createWithDefaultBound(
|
||||
serializerDescriptor, Annotations.EMPTY, false, Variance.INVARIANT,
|
||||
param.name, index
|
||||
param.name, index, LockBasedStorageManager.NO_LOCKS
|
||||
)
|
||||
}
|
||||
serializerDescriptor.initialize(typeParameters)
|
||||
@@ -378,7 +379,7 @@ object KSerializerDescriptorResolver {
|
||||
serializableClass.declaredTypeParameters.forEach { _ ->
|
||||
val targ = TypeParameterDescriptorImpl.createWithDefaultBound(
|
||||
parentFunction, Annotations.EMPTY, false, Variance.INVARIANT,
|
||||
Name.identifier("T$i"), i
|
||||
Name.identifier("T$i"), i, LockBasedStorageManager.NO_LOCKS
|
||||
)
|
||||
|
||||
val pType =
|
||||
|
||||
Reference in New Issue
Block a user