Container of value parameter is always a callable
This commit is contained in:
@@ -46,6 +46,7 @@ import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
|
||||
import org.jetbrains.kotlin.codegen.when.SwitchCodegen;
|
||||
import org.jetbrains.kotlin.codegen.when.SwitchCodegenUtil;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ScriptCodeDescriptor;
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils;
|
||||
import org.jetbrains.kotlin.diagnostics.Errors;
|
||||
import org.jetbrains.kotlin.lexer.JetTokens;
|
||||
@@ -2036,11 +2037,14 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
return localOrCaptured;
|
||||
}
|
||||
|
||||
if (descriptor instanceof ValueParameterDescriptor && descriptor.getContainingDeclaration() instanceof ScriptDescriptor) {
|
||||
ScriptDescriptor scriptDescriptor = (ScriptDescriptor) descriptor.getContainingDeclaration();
|
||||
DeclarationDescriptor container = descriptor.getContainingDeclaration();
|
||||
if (descriptor instanceof ValueParameterDescriptor && container instanceof ScriptCodeDescriptor) {
|
||||
ScriptCodeDescriptor scriptCodeDescriptor = (ScriptCodeDescriptor) container;
|
||||
ScriptDescriptor scriptDescriptor = (ScriptDescriptor) scriptCodeDescriptor.getContainingDeclaration();
|
||||
Type scriptClassType = asmTypeForScriptDescriptor(bindingContext, scriptDescriptor);
|
||||
ValueParameterDescriptor valueParameterDescriptor = (ValueParameterDescriptor) descriptor;
|
||||
ClassDescriptor scriptClass = bindingContext.get(CLASS_FOR_SCRIPT, scriptDescriptor);
|
||||
//noinspection ConstantConditions
|
||||
StackValue script = StackValue.thisOrOuter(this, scriptClass, false, false);
|
||||
Type fieldType = typeMapper.mapType(valueParameterDescriptor);
|
||||
return StackValue.field(fieldType, scriptClassType, valueParameterDescriptor.getName().getIdentifier(), false, script,
|
||||
|
||||
@@ -345,18 +345,7 @@ public class DescriptorResolver {
|
||||
|
||||
@NotNull
|
||||
public ValueParameterDescriptorImpl resolveValueParameterDescriptor(
|
||||
JetScope scope, DeclarationDescriptor declarationDescriptor,
|
||||
JetParameter valueParameter, int index, JetType type, BindingTrace trace
|
||||
) {
|
||||
return resolveValueParameterDescriptor(declarationDescriptor, valueParameter, index, type, trace,
|
||||
annotationResolver.resolveAnnotationsWithoutArguments(scope, valueParameter.getModifierList(), trace));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private ValueParameterDescriptorImpl resolveValueParameterDescriptor(
|
||||
DeclarationDescriptor declarationDescriptor,
|
||||
JetParameter valueParameter, int index, JetType type, BindingTrace trace,
|
||||
Annotations annotations
|
||||
JetScope scope, FunctionDescriptor owner, JetParameter valueParameter, int index, JetType type, BindingTrace trace
|
||||
) {
|
||||
JetType varargElementType = null;
|
||||
JetType variableType = type;
|
||||
@@ -365,10 +354,10 @@ public class DescriptorResolver {
|
||||
variableType = getVarargParameterType(type);
|
||||
}
|
||||
ValueParameterDescriptorImpl valueParameterDescriptor = new ValueParameterDescriptorImpl(
|
||||
declarationDescriptor,
|
||||
owner,
|
||||
null,
|
||||
index,
|
||||
annotations,
|
||||
annotationResolver.resolveAnnotationsWithoutArguments(scope, valueParameter.getModifierList(), trace),
|
||||
JetPsiUtil.safeName(valueParameter.getName()),
|
||||
variableType,
|
||||
valueParameter.hasDefaultValue(),
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.ScriptDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement;
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ScriptCodeDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl;
|
||||
import org.jetbrains.kotlin.parsing.JetScriptDefinition;
|
||||
import org.jetbrains.kotlin.parsing.JetScriptDefinitionProvider;
|
||||
@@ -35,7 +36,7 @@ public final class ScriptParameterResolver {
|
||||
@NotNull
|
||||
public static List<ValueParameterDescriptor> resolveScriptParameters(
|
||||
@NotNull JetScript declaration,
|
||||
@NotNull ScriptDescriptor scriptDescriptor
|
||||
@NotNull ScriptCodeDescriptor scriptCodeDescriptor
|
||||
) {
|
||||
List<ValueParameterDescriptor> valueParameters = Lists.newArrayList();
|
||||
|
||||
@@ -44,23 +45,16 @@ public final class ScriptParameterResolver {
|
||||
|
||||
int index = 0;
|
||||
for (AnalyzerScriptParameter scriptParameter : scriptDefinition.getScriptParameters()) {
|
||||
ValueParameterDescriptor parameter = resolveScriptParameter(scriptParameter, index, scriptDescriptor);
|
||||
ValueParameterDescriptor parameter = new ValueParameterDescriptorImpl(
|
||||
scriptCodeDescriptor, null, index, Annotations.EMPTY, scriptParameter.getName(),
|
||||
scriptParameter.getType(), false, null, SourceElement.NO_SOURCE
|
||||
);
|
||||
valueParameters.add(parameter);
|
||||
++index;
|
||||
}
|
||||
return valueParameters;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static ValueParameterDescriptor resolveScriptParameter(
|
||||
@NotNull AnalyzerScriptParameter scriptParameter,
|
||||
int index,
|
||||
@NotNull ScriptDescriptor script
|
||||
) {
|
||||
return new ValueParameterDescriptorImpl(script, null, index, Annotations.EMPTY, scriptParameter.getName(),
|
||||
scriptParameter.getType(), false, null, SourceElement.NO_SOURCE);
|
||||
}
|
||||
|
||||
private ScriptParameterResolver() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,8 +148,7 @@ object DynamicCallableDescriptors {
|
||||
)
|
||||
}
|
||||
|
||||
private fun createValueParameters(owner: DeclarationDescriptor, call: Call): List<ValueParameterDescriptor> {
|
||||
|
||||
private fun createValueParameters(owner: FunctionDescriptor, call: Call): List<ValueParameterDescriptor> {
|
||||
val parameters = ArrayList<ValueParameterDescriptor>()
|
||||
|
||||
fun addParameter(arg : ValueArgument, outType: JetType, varargElementType: JetType?) {
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ public class LazyScriptDescriptor(
|
||||
val result = ScriptCodeDescriptor(this)
|
||||
result.initialize(
|
||||
implicitReceiver,
|
||||
ScriptParameterResolver.resolveScriptParameters(jetScript, this),
|
||||
ScriptParameterResolver.resolveScriptParameters(jetScript, result),
|
||||
DeferredType.create(resolveSession.getStorageManager(), resolveSession.getTrace()) {
|
||||
scriptBodyResolver.resolveScriptReturnType(jetScript, this, resolveSession.getTrace())
|
||||
}
|
||||
|
||||
@@ -16,8 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.load.java.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.module
|
||||
@@ -26,7 +25,7 @@ import org.jetbrains.kotlin.types.JetType
|
||||
fun createEnhancedValueParameters(
|
||||
enhancedTypes: Collection<JetType>,
|
||||
oldValueParameters: Collection<ValueParameterDescriptor>,
|
||||
newOwner: DeclarationDescriptor
|
||||
newOwner: CallableDescriptor
|
||||
): List<ValueParameterDescriptor> {
|
||||
assert(enhancedTypes.size() == oldValueParameters.size()) {
|
||||
"Different value parameters sizes: Enhanced = ${enhancedTypes.size()}, Old = ${oldValueParameters.size()}"
|
||||
|
||||
@@ -24,6 +24,10 @@ import org.jetbrains.kotlin.types.JetType;
|
||||
import java.util.Set;
|
||||
|
||||
public interface ValueParameterDescriptor extends VariableDescriptor, ParameterDescriptor {
|
||||
@NotNull
|
||||
@Override
|
||||
CallableDescriptor getContainingDeclaration();
|
||||
|
||||
/**
|
||||
* Returns the 0-based index of the value parameter in the parameter list of its containing function.
|
||||
*
|
||||
@@ -53,7 +57,7 @@ public interface ValueParameterDescriptor extends VariableDescriptor, ParameterD
|
||||
ValueParameterDescriptor getOriginal();
|
||||
|
||||
@NotNull
|
||||
ValueParameterDescriptor copy(@NotNull DeclarationDescriptor newOwner, @NotNull Name newName);
|
||||
ValueParameterDescriptor copy(@NotNull CallableDescriptor newOwner, @NotNull Name newName);
|
||||
|
||||
/**
|
||||
* Parameter p1 overrides p2 iff
|
||||
|
||||
+12
-3
@@ -39,7 +39,7 @@ public class ValueParameterDescriptorImpl extends VariableDescriptorImpl impleme
|
||||
private final Set<? extends ValueParameterDescriptor> readOnlyOverriddenDescriptors = Collections.unmodifiableSet(overriddenDescriptors);
|
||||
|
||||
public ValueParameterDescriptorImpl(
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@NotNull CallableDescriptor containingDeclaration,
|
||||
@Nullable ValueParameterDescriptor original,
|
||||
int index,
|
||||
@NotNull Annotations annotations,
|
||||
@@ -56,6 +56,12 @@ public class ValueParameterDescriptorImpl extends VariableDescriptorImpl impleme
|
||||
this.varargElementType = varargElementType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public CallableDescriptor getContainingDeclaration() {
|
||||
return (CallableDescriptor) super.getContainingDeclaration();
|
||||
}
|
||||
|
||||
public void setType(@NotNull JetType type) {
|
||||
setOutType(type);
|
||||
}
|
||||
@@ -124,8 +130,11 @@ public class ValueParameterDescriptorImpl extends VariableDescriptorImpl impleme
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ValueParameterDescriptor copy(@NotNull DeclarationDescriptor newOwner, @NotNull Name newName) {
|
||||
return new ValueParameterDescriptorImpl(newOwner, null, index, getAnnotations(), newName, getType(), declaresDefaultValue(), varargElementType, SourceElement.NO_SOURCE);
|
||||
public ValueParameterDescriptor copy(@NotNull CallableDescriptor newOwner, @NotNull Name newName) {
|
||||
return new ValueParameterDescriptorImpl(
|
||||
newOwner, null, index, getAnnotations(), newName, getType(), declaresDefaultValue(), varargElementType,
|
||||
SourceElement.NO_SOURCE
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+3
-2
@@ -170,11 +170,12 @@ public class MemberDeserializer(private val c: DeserializationContext) {
|
||||
}
|
||||
|
||||
private fun valueParameters(callable: Callable, kind: AnnotatedCallableKind): List<ValueParameterDescriptor> {
|
||||
val containerOfCallable = c.containingDeclaration.getContainingDeclaration()!!.asProtoContainer()
|
||||
val callableDescriptor = c.containingDeclaration as CallableDescriptor
|
||||
val containerOfCallable = callableDescriptor.getContainingDeclaration().asProtoContainer()
|
||||
|
||||
return callable.getValueParameterList().mapIndexed { i, proto ->
|
||||
ValueParameterDescriptorImpl(
|
||||
c.containingDeclaration, null, i,
|
||||
callableDescriptor, null, i,
|
||||
getParameterAnnotations(containerOfCallable, callable, kind, proto),
|
||||
c.nameResolver.getName(proto.getName()),
|
||||
c.typeDeserializer.type(proto.getType()),
|
||||
|
||||
Reference in New Issue
Block a user