Deep ErrorType implementation
This commit is contained in:
@@ -3,6 +3,8 @@ package org.jetbrains.jet.lang.types;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.lang.resolve.JetScope;
|
import org.jetbrains.jet.lang.resolve.JetScope;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -10,52 +12,104 @@ import java.util.List;
|
|||||||
* @author abreslav
|
* @author abreslav
|
||||||
*/
|
*/
|
||||||
public class ErrorType {
|
public class ErrorType {
|
||||||
|
|
||||||
|
private static final ModuleDescriptor ERROR_MODULE = new ModuleDescriptor("<ERROR MODULE>");
|
||||||
private static final JetScope ERROR_SCOPE = new JetScope() {
|
private static final JetScope ERROR_SCOPE = new JetScope() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ClassDescriptor getClass(@NotNull String name) {
|
public ClassDescriptor getClass(@NotNull String name) {
|
||||||
throw new UnsupportedOperationException(); // TODO
|
return ERROR_CLASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PropertyDescriptor getProperty(@NotNull String name) {
|
public PropertyDescriptor getProperty(@NotNull String name) {
|
||||||
throw new UnsupportedOperationException(); // TODO
|
return ERROR_PROPERTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ExtensionDescriptor getExtension(@NotNull String name) {
|
public ExtensionDescriptor getExtension(@NotNull String name) {
|
||||||
throw new UnsupportedOperationException(); // TODO
|
return null; // TODO : review
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
public NamespaceDescriptor getNamespace(@NotNull String name) {
|
||||||
throw new UnsupportedOperationException(); // TODO
|
return null; // TODO : review
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TypeParameterDescriptor getTypeParameter(@NotNull String name) {
|
public TypeParameterDescriptor getTypeParameter(@NotNull String name) {
|
||||||
throw new UnsupportedOperationException(); // TODO
|
return null; // TODO : review
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public JetType getThisType() {
|
public JetType getThisType() {
|
||||||
throw new UnsupportedOperationException(); // TODO
|
return createErrorType("<ERROR TYPE>");
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public FunctionGroup getFunctionGroup(@NotNull String name) {
|
public FunctionGroup getFunctionGroup(@NotNull String name) {
|
||||||
throw new UnsupportedOperationException(); // TODO
|
return ERROR_FUNCTION_GROUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public DeclarationDescriptor getContainingDeclaration() {
|
public DeclarationDescriptor getContainingDeclaration() {
|
||||||
throw new UnsupportedOperationException(); // TODO
|
return ERROR_MODULE;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private static final ClassDescriptor ERROR_CLASS = new ClassDescriptorImpl(ERROR_MODULE, Collections.<Attribute>emptyList(), "<ERROR CLASS>").initialize(
|
||||||
|
true, Collections.<TypeParameterDescriptor>emptyList(), Collections.<JetType>emptyList(), getErrorScope()
|
||||||
|
);
|
||||||
|
|
||||||
|
private static JetScope getErrorScope() {
|
||||||
|
return ERROR_SCOPE;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final PropertyDescriptor ERROR_PROPERTY = new PropertyDescriptorImpl(ERROR_CLASS, Collections.<Attribute>emptyList(), "<ERROR PROPERTY>", createErrorType("<ERROR PROPERTY TYPE>"));
|
||||||
|
private static final FunctionGroup ERROR_FUNCTION_GROUP = new FunctionGroup() {
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "<ERROR FUNCTION>";
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public Collection<FunctionDescriptor> getPossiblyApplicableFunctions(@NotNull List<JetType> typeArguments, @NotNull List<JetType> positionedValueArgumentTypes) {
|
||||||
|
FunctionDescriptorImpl functionDescriptor = new FunctionDescriptorImpl(ERROR_CLASS, Collections.<Attribute>emptyList(), "<ERROR FUNCTION>");
|
||||||
|
return Collections.singletonList(functionDescriptor.initialize(
|
||||||
|
Collections.<TypeParameterDescriptor>emptyList(),
|
||||||
|
getValueParameters(functionDescriptor, positionedValueArgumentTypes),
|
||||||
|
createErrorType("<ERROR FUNCTION RETURN>")
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<ValueParameterDescriptor> getValueParameters(FunctionDescriptor functionDescriptor, List<JetType> argumentTypes) {
|
||||||
|
List<ValueParameterDescriptor> result = new ArrayList<ValueParameterDescriptor>();
|
||||||
|
for (int i = 0, argumentTypesSize = argumentTypes.size(); i < argumentTypesSize; i++) {
|
||||||
|
JetType argumentType = argumentTypes.get(i);
|
||||||
|
result.add(new ValueParameterDescriptorImpl(
|
||||||
|
functionDescriptor,
|
||||||
|
i,
|
||||||
|
Collections.<Attribute>emptyList(),
|
||||||
|
"<ERROR PARAMETER>",
|
||||||
|
createErrorType("<ERROR PARAMETER TYPE>"),
|
||||||
|
false,
|
||||||
|
false));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private ErrorType() {}
|
private ErrorType() {}
|
||||||
|
|
||||||
public static JetType createErrorType(String debugMessage) {
|
public static JetType createErrorType(String debugMessage) {
|
||||||
|
|||||||
@@ -32,13 +32,14 @@ public class FunctionDescriptorImpl extends DeclarationDescriptorImpl implements
|
|||||||
this.original = original;
|
this.original = original;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void initialize(
|
public final FunctionDescriptor initialize(
|
||||||
@NotNull List<TypeParameterDescriptor> typeParameters,
|
@NotNull List<TypeParameterDescriptor> typeParameters,
|
||||||
@NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
|
@NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters,
|
||||||
@NotNull JetType unsubstitutedReturnType) {
|
@NotNull JetType unsubstitutedReturnType) {
|
||||||
this.typeParameters = typeParameters;
|
this.typeParameters = typeParameters;
|
||||||
this.unsubstitutedValueParameters = unsubstitutedValueParameters;
|
this.unsubstitutedValueParameters = unsubstitutedValueParameters;
|
||||||
this.unsubstitutedReturnType = unsubstitutedReturnType;
|
this.unsubstitutedReturnType = unsubstitutedReturnType;
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -303,6 +303,9 @@ public class JetTypeChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSubtypeOf(@NotNull JetType subtype, @NotNull JetType supertype) {
|
public boolean isSubtypeOf(@NotNull JetType subtype, @NotNull JetType supertype) {
|
||||||
|
if (ErrorType.isErrorType(subtype) || ErrorType.isErrorType(supertype)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (!supertype.isNullable() && subtype.isNullable()) {
|
if (!supertype.isNullable() && subtype.isNullable()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -860,9 +860,9 @@ public class JetTypeInferrer {
|
|||||||
return resultType;
|
return resultType;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isBoolean(@NotNull JetType resultType) {
|
private boolean isBoolean(@NotNull JetType type) {
|
||||||
TypeConstructor booleanTypeConstructor = semanticServices.getStandardLibrary().getBoolean().getTypeConstructor();
|
TypeConstructor booleanTypeConstructor = semanticServices.getStandardLibrary().getBoolean().getTypeConstructor();
|
||||||
return resultType.getConstructor().equals(booleanTypeConstructor);
|
return type.getConstructor().equals(booleanTypeConstructor) || ErrorType.isErrorType(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user