Add ability for DeclarationDescriptor validation
Not fully initialized DeclarationDescriptor could leak to bindingTrace. It is hard to detect the outcome of that kind of leakage due to possibility to have not fully initialized instances if PCE happens in the middle of publication and instance full initialization. #KT-56364 #KT-56388 #KT-54085 #KT-55150
This commit is contained in:
committed by
Space Team
parent
a049fda75b
commit
b04b3d389f
@@ -20,7 +20,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotated;
|
||||
|
||||
public interface DeclarationDescriptor extends Annotated, Named {
|
||||
public interface DeclarationDescriptor extends Annotated, Named, ValidateableDescriptor {
|
||||
/**
|
||||
* @return The descriptor that corresponds to the original declaration of this element.
|
||||
* A descriptor can be obtained from its original by substituting type arguments (of the declaring class
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.descriptors;
|
||||
|
||||
public interface ValidateableDescriptor {
|
||||
default void validate() {}
|
||||
}
|
||||
+6
-4
@@ -17,10 +17,7 @@
|
||||
package org.jetbrains.kotlin.descriptors.impl;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorNonRoot;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource;
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
|
||||
@@ -64,4 +61,9 @@ public abstract class DeclarationDescriptorNonRootImpl
|
||||
return source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() {
|
||||
containingDeclaration.validate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -306,6 +306,11 @@ public abstract class FunctionDescriptorImpl extends DeclarationDescriptorNonRoo
|
||||
return parameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() {
|
||||
getTypeParameters();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<ValueParameterDescriptor> getValueParameters() {
|
||||
|
||||
+6
-1
@@ -180,11 +180,16 @@ public class PropertyDescriptorImpl extends VariableDescriptorWithInitializerImp
|
||||
List<TypeParameterDescriptor> parameters = typeParameters;
|
||||
// Diagnostics for EA-212070
|
||||
if (parameters == null) {
|
||||
throw new IllegalStateException("typeParameters == null for " + this.toString());
|
||||
throw new IllegalStateException("typeParameters == null for " + this);
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate() {
|
||||
getTypeParameters();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<ReceiverParameterDescriptor> getContextReceiverParameters() {
|
||||
|
||||
Reference in New Issue
Block a user