Little fixes for resolve

This commit is contained in:
Andrey Breslav
2011-03-14 22:47:21 +03:00
parent ae2a4afa36
commit 74190bf773
4 changed files with 25 additions and 19 deletions
@@ -21,7 +21,6 @@ public class JetSemanticServices {
return new JetSemanticServices(JetStandardLibrary.getJetStandardLibrary(project), errorHandler);
}
private final JetTypeInferrer typeInferrer;
private final JetStandardLibrary standardLibrary;
private final JetTypeChecker typeChecker;
private final OverloadResolver overloadResolver;
@@ -31,7 +30,6 @@ public class JetSemanticServices {
private JetSemanticServices(JetStandardLibrary standardLibrary, ErrorHandler errorHandler) {
this.standardLibrary = standardLibrary;
this.errorHandler = errorHandler;
this.typeInferrer = new JetTypeInferrer(BindingTrace.DUMMY, this);
this.typeChecker = new JetTypeChecker(standardLibrary);
this.overloadResolver = new OverloadResolver(typeChecker);
}
@@ -41,11 +39,6 @@ public class JetSemanticServices {
return standardLibrary;
}
@NotNull
public JetTypeInferrer getTypeInferrer() {
return typeInferrer;
}
@NotNull
public ClassDescriptorResolver getClassDescriptorResolver(BindingTrace trace) {
return new ClassDescriptorResolver(this, trace);
@@ -138,14 +138,21 @@ public class ClassDescriptorResolver {
Type returnType;
JetTypeReference returnTypeRef = function.getReturnTypeRef();
JetExpression bodyExpression = function.getBodyExpression();
if (returnTypeRef != null) {
returnType = typeResolver.resolveType(parameterScope, returnTypeRef);
// TODO : CHeck type of body
// TODO : check body type, consider recursion
if (bodyExpression != null) {
semanticServices.getTypeInferrer(trace).getType(parameterScope, bodyExpression, function.hasBlockBody());
}
} else {
JetExpression bodyExpression = function.getBodyExpression();
assert bodyExpression != null : "No type, no body"; // TODO
// TODO : Recursion possible
returnType = semanticServices.getTypeInferrer().safeGetType(parameterScope, bodyExpression, function.hasBlockBody());
if (bodyExpression == null) {
semanticServices.getErrorHandler().structuralError(function.getNode(), "This function must either declare a return type or have a body expression");
returnType = ErrorType.createErrorType("No type, no body");
} else {
// TODO : Recursion possible
returnType = semanticServices.getTypeInferrer(trace).safeGetType(parameterScope, bodyExpression, function.hasBlockBody());
}
}
functionDescriptor.initialize(
@@ -245,9 +252,13 @@ public class ClassDescriptorResolver {
Type type;
if (propertyTypeRef == null) {
JetExpression initializer = property.getInitializer();
assert initializer != null;
// TODO : ??? Fix-point here: what if we have something like "val a = foo {a.bar()}"
type = semanticServices.getTypeInferrer().getType(scope, initializer, false);
if (initializer == null) {
semanticServices.getErrorHandler().structuralError(property.getNode(), "This property must either have a type annotation or be initialized");
type = ErrorType.createErrorType("No type, no body");
} else {
// TODO : ??? Fix-point here: what if we have something like "val a = foo {a.bar()}"
type = semanticServices.getTypeInferrer(trace).getType(scope, initializer, false);
}
} else {
type = typeResolver.resolveType(scope, propertyTypeRef);
}
@@ -301,6 +301,7 @@ public class JetTypeInferrer {
List<JetTypeProjection> typeArguments = expression.getTypeArguments();
List<JetArgument> valueArguments = expression.getValueArguments();
boolean someNamed = false;
for (JetArgument argument : valueArguments) {
if (argument.isNamed()) {
@@ -365,7 +366,8 @@ public class JetTypeInferrer {
resolveArrayAccessToLValue(arrayAccessExpression, expression.getRight(), expression.getOperationReference());
}
else {
throw new UnsupportedOperationException();
getType(scope, expression.getRight(), false);
//throw new UnsupportedOperationException();
}
result[0] = null; // TODO : This is not an expression, in fact!
} else {
@@ -449,14 +449,14 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
private void assertType(String expression, Type expectedType) {
Project project = getProject();
JetExpression jetExpression = JetChangeUtil.createExpression(project, expression);
Type type = semanticServices.getTypeInferrer().getType(classDefinitions.BASIC_SCOPE, jetExpression, false);
Type type = semanticServices.getTypeInferrer(BindingTrace.DUMMY).getType(classDefinitions.BASIC_SCOPE, jetExpression, false);
assertTrue(type + " != " + expectedType, TypeImpl.equalTypes(type, expectedType));
}
private void assertErrorType(String expression) {
Project project = getProject();
JetExpression jetExpression = JetChangeUtil.createExpression(project, expression);
Type type = semanticServices.getTypeInferrer().getType(classDefinitions.BASIC_SCOPE, jetExpression, false);
Type type = semanticServices.getTypeInferrer(BindingTrace.DUMMY).getType(classDefinitions.BASIC_SCOPE, jetExpression, false);
assertTrue("Error type expected but " + type + " returned", ErrorType.isErrorType(type));
}
@@ -479,7 +479,7 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
private void assertType(JetScope scope, String expression, String expectedTypeStr) {
Project project = getProject();
JetExpression jetExpression = JetChangeUtil.createExpression(project, expression);
Type type = semanticServices.getTypeInferrer().getType(scope, jetExpression, false);
Type type = semanticServices.getTypeInferrer(BindingTrace.DUMMY).getType(scope, jetExpression, false);
Type expectedType = expectedTypeStr == null ? null : makeType(expectedTypeStr);
assertEquals(expectedType, type);
}