Getting ready for receiver-functions: got rid of MutableFunctionDescriptor
This commit is contained in:
@@ -666,6 +666,7 @@ public class JetControlFlowProcessor {
|
|||||||
builder.bindLabel(nextLabel);
|
builder.bindLabel(nextLabel);
|
||||||
nextLabel = builder.createUnboundLabel();
|
nextLabel = builder.createUnboundLabel();
|
||||||
}
|
}
|
||||||
|
// TODO : if there's else, no error can happen
|
||||||
builder.jumpToError(null);
|
builder.jumpToError(null);
|
||||||
builder.bindLabel(doneLabel);
|
builder.bindLabel(doneLabel);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package org.jetbrains.jet.lang.descriptors;
|
package org.jetbrains.jet.lang.descriptors;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
import org.jetbrains.jet.lang.types.TypeSubstitutor;
|
||||||
|
|
||||||
@@ -15,6 +16,9 @@ public interface FunctionDescriptor extends DeclarationDescriptor {
|
|||||||
@NotNull
|
@NotNull
|
||||||
DeclarationDescriptor getContainingDeclaration();
|
DeclarationDescriptor getContainingDeclaration();
|
||||||
|
|
||||||
|
// @Nullable
|
||||||
|
// JetType getReceiverType();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
List<TypeParameterDescriptor> getTypeParameters();
|
List<TypeParameterDescriptor> getTypeParameters();
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import java.util.Set;
|
|||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements MutableFunctionDescriptor {
|
public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements FunctionDescriptor {
|
||||||
|
|
||||||
private List<TypeParameterDescriptor> typeParameters;
|
private List<TypeParameterDescriptor> typeParameters;
|
||||||
private List<ValueParameterDescriptor> unsubstitutedValueParameters;
|
private List<ValueParameterDescriptor> unsubstitutedValueParameters;
|
||||||
@@ -59,16 +59,6 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements
|
|||||||
overriddenFunctions.add(overriddenFunction);
|
overriddenFunctions.add(overriddenFunction);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setUnsubstitutedReturnType(@NotNull JetType unsubstitutedReturnType) {
|
|
||||||
this.unsubstitutedReturnType = unsubstitutedReturnType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isReturnTypeSet() {
|
|
||||||
return unsubstitutedReturnType != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
@NotNull
|
||||||
public List<TypeParameterDescriptor> getTypeParameters() {
|
public List<TypeParameterDescriptor> getTypeParameters() {
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
package org.jetbrains.jet.lang.descriptors;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author abreslav
|
|
||||||
*/
|
|
||||||
public interface MutableFunctionDescriptor extends FunctionDescriptor {
|
|
||||||
void setUnsubstitutedReturnType(@NotNull JetType type);
|
|
||||||
|
|
||||||
boolean isReturnTypeSet();
|
|
||||||
}
|
|
||||||
@@ -12,7 +12,7 @@ import java.util.Set;
|
|||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class PropertyGetterDescriptor extends PropertyAccessorDescriptor implements MutableFunctionDescriptor {
|
public class PropertyGetterDescriptor extends PropertyAccessorDescriptor {
|
||||||
private final Set<PropertyGetterDescriptor> overriddenGetters = Sets.newHashSet();
|
private final Set<PropertyGetterDescriptor> overriddenGetters = Sets.newHashSet();
|
||||||
private JetType returnType;
|
private JetType returnType;
|
||||||
|
|
||||||
@@ -43,17 +43,6 @@ public class PropertyGetterDescriptor extends PropertyAccessorDescriptor impleme
|
|||||||
return returnType;
|
return returnType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setUnsubstitutedReturnType(@NotNull JetType type) {
|
|
||||||
assert this.returnType == null : this.returnType;
|
|
||||||
this.returnType = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isReturnTypeSet() {
|
|
||||||
return returnType != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
public <R, D> R accept(DeclarationDescriptorVisitor<R, D> visitor, D data) {
|
||||||
return visitor.visitPropertyGetterDescriptor(this, data);
|
return visitor.visitPropertyGetterDescriptor(this, data);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import java.util.Set;
|
|||||||
/**
|
/**
|
||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class PropertySetterDescriptor extends PropertyAccessorDescriptor implements MutableFunctionDescriptor {
|
public class PropertySetterDescriptor extends PropertyAccessorDescriptor {
|
||||||
|
|
||||||
private MutableValueParameterDescriptor parameter;
|
private MutableValueParameterDescriptor parameter;
|
||||||
private final Set<PropertySetterDescriptor> overriddenSetters = Sets.newHashSet();
|
private final Set<PropertySetterDescriptor> overriddenSetters = Sets.newHashSet();
|
||||||
@@ -57,13 +57,4 @@ public class PropertySetterDescriptor extends PropertyAccessorDescriptor impleme
|
|||||||
return visitor.visitPropertySetterDescriptor(this, data);
|
return visitor.visitPropertySetterDescriptor(this, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setUnsubstitutedReturnType(@NotNull JetType type) {
|
|
||||||
throw new UnsupportedOperationException("Can't set return type for a setter");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isReturnTypeSet() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ public class ClassDescriptorResolver {
|
|||||||
List<ValueParameterDescriptor> valueParameterDescriptors = resolveValueParameters(functionDescriptor, innerScope, function.getValueParameters());
|
List<ValueParameterDescriptor> valueParameterDescriptors = resolveValueParameters(functionDescriptor, innerScope, function.getValueParameters());
|
||||||
|
|
||||||
JetTypeReference returnTypeRef = function.getReturnTypeRef();
|
JetTypeReference returnTypeRef = function.getReturnTypeRef();
|
||||||
JetType returnType = null;
|
JetType returnType;
|
||||||
if (returnTypeRef != null) {
|
if (returnTypeRef != null) {
|
||||||
returnType = typeResolver.resolveType(innerScope, returnTypeRef);
|
returnType = typeResolver.resolveType(innerScope, returnTypeRef);
|
||||||
}
|
}
|
||||||
@@ -194,6 +194,10 @@ public class ClassDescriptorResolver {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
trace.getErrorHandler().genericError(function.asElement().getNode(), "This function must either declare a return type or have a body element");
|
||||||
|
returnType = ErrorUtils.createErrorType("No type, no body");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
functionDescriptor.initialize(
|
functionDescriptor.initialize(
|
||||||
@@ -206,7 +210,7 @@ public class ClassDescriptorResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private List<ValueParameterDescriptor> resolveValueParameters(MutableFunctionDescriptor functionDescriptor, WritableScope parameterScope, List<JetParameter> valueParameters) {
|
private List<ValueParameterDescriptor> resolveValueParameters(FunctionDescriptor functionDescriptor, WritableScope parameterScope, List<JetParameter> valueParameters) {
|
||||||
List<ValueParameterDescriptor> result = new ArrayList<ValueParameterDescriptor>();
|
List<ValueParameterDescriptor> result = new ArrayList<ValueParameterDescriptor>();
|
||||||
for (int i = 0, valueParametersSize = valueParameters.size(); i < valueParametersSize; i++) {
|
for (int i = 0, valueParametersSize = valueParameters.size(); i < valueParametersSize; i++) {
|
||||||
JetParameter valueParameter = valueParameters.get(i);
|
JetParameter valueParameter = valueParameters.get(i);
|
||||||
|
|||||||
@@ -664,7 +664,7 @@ public class TopDownAnalyzer {
|
|||||||
private void resolveFunctionBody(
|
private void resolveFunctionBody(
|
||||||
@NotNull BindingTrace trace,
|
@NotNull BindingTrace trace,
|
||||||
@NotNull JetDeclarationWithBody function,
|
@NotNull JetDeclarationWithBody function,
|
||||||
@NotNull MutableFunctionDescriptor functionDescriptor,
|
@NotNull FunctionDescriptor functionDescriptor,
|
||||||
@NotNull JetScope declaringScope) {
|
@NotNull JetScope declaringScope) {
|
||||||
JetExpression bodyExpression = function.getBodyExpression();
|
JetExpression bodyExpression = function.getBodyExpression();
|
||||||
|
|
||||||
@@ -674,16 +674,7 @@ public class TopDownAnalyzer {
|
|||||||
|
|
||||||
assert readyToProcessExpressions : "Must be ready collecting types";
|
assert readyToProcessExpressions : "Must be ready collecting types";
|
||||||
|
|
||||||
if (functionDescriptor.isReturnTypeSet()) {
|
typeInferrer.checkFunctionReturnType(declaringScope, function, functionDescriptor);
|
||||||
typeInferrer.checkFunctionReturnType(declaringScope, function, functionDescriptor);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
JetType returnType = typeInferrer.getFunctionReturnType(declaringScope, function, functionDescriptor);
|
|
||||||
if (returnType == null) {
|
|
||||||
returnType = ErrorUtils.createErrorType("Unable to infer body type");
|
|
||||||
}
|
|
||||||
functionDescriptor.setUnsubstitutedReturnType(returnType);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<JetElement> unreachableElements = new ArrayList<JetElement>();
|
List<JetElement> unreachableElements = new ArrayList<JetElement>();
|
||||||
flowInformationProvider.collectUnreachableExpressions(function.asElement(), unreachableElements);
|
flowInformationProvider.collectUnreachableExpressions(function.asElement(), unreachableElements);
|
||||||
@@ -699,12 +690,8 @@ public class TopDownAnalyzer {
|
|||||||
trace.getErrorHandler().genericError(element.getNode(), "Unreachable code");
|
trace.getErrorHandler().genericError(element.getNode(), "Unreachable code");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
if (!functionDescriptor.isReturnTypeSet()) {
|
assert functionDescriptor.getUnsubstitutedReturnType() != null;
|
||||||
trace.getErrorHandler().genericError(function.asElement().getNode(), "This function must either declare a return type or have a body element");
|
|
||||||
functionDescriptor.setUnsubstitutedReturnType(ErrorUtils.createErrorType("No type, no body"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user