function invocation with only type parameters prohibited

This commit is contained in:
Svetlana Isakova
2012-05-23 22:04:22 +04:00
parent 327b471eaf
commit 0fd882741b
22 changed files with 78 additions and 47 deletions
@@ -321,7 +321,7 @@ public interface Errors {
DiagnosticFactory2<JetDeclaration, CallableMemberDescriptor, String> CONFLICTING_OVERLOADS = DiagnosticFactory2.create(ERROR, DECLARATION);
DiagnosticFactory2<JetReferenceExpression, JetExpression, JetType> FUNCTION_EXPECTED = DiagnosticFactory2.create(ERROR);
DiagnosticFactory2<JetReferenceExpression, JetExpression, Boolean> FUNCTION_CALL_EXPECTED = DiagnosticFactory2.create(ERROR);
DiagnosticFactory2<JetExpression, JetExpression, Boolean> FUNCTION_CALL_EXPECTED = DiagnosticFactory2.create(ERROR, CALL_EXPRESSION);
DiagnosticFactory3<JetExpression, String, JetType, JetType> RESULT_TYPE_MISMATCH = DiagnosticFactory3.create(ERROR);
DiagnosticFactory3<JetReferenceExpression, String, String, String> UNSAFE_INFIX_CALL = DiagnosticFactory3.create(ERROR);
@@ -298,4 +298,28 @@ public class PositioningStrategies {
return markNode(element.getQuestionMarkNode());
}
};
public static PositioningStrategy<JetExpression> CALL_EXPRESSION = new PositioningStrategy<JetExpression>() {
@NotNull
@Override
public List<TextRange> mark(@NotNull JetExpression element) {
if (element instanceof JetCallExpression) {
JetCallExpression callExpression = (JetCallExpression) element;
PsiElement endElement;
JetTypeArgumentList typeArgumentList = callExpression.getTypeArgumentList();
JetExpression calleeExpression = callExpression.getCalleeExpression();
if (typeArgumentList != null) {
endElement = typeArgumentList;
}
else if (calleeExpression != null) {
endElement = calleeExpression;
}
else {
endElement = element;
}
return markRange(new TextRange(element.getTextRange().getStartOffset(), endElement.getTextRange().getEndOffset()));
}
return super.mark(element);
}
};
}
@@ -77,6 +77,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
return type; // TODO : Extensions to this
}
@Nullable
private JetType lookupNamespaceOrClassObject(JetSimpleNameExpression expression, Name referencedName, ExpressionTypingContext context) {
ClassifierDescriptor classifier = context.scope.getClassifier(referencedName);
if (classifier != null) {
@@ -90,9 +91,9 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
context.trace.report(NO_CLASS_OBJECT.on(expression, classifier));
}
context.trace.record(REFERENCE_TARGET, expression, classifier);
if (result == null) {
return ErrorUtils.createErrorType("No class object in " + expression.getReferencedName());
}
//if (result == null) {
// return ErrorUtils.createErrorType("No class object in " + expression.getReferencedName());
//}
return DataFlowUtils.checkType(result, expression, context);
}
}
@@ -684,7 +685,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
if (result[0]) {
traceForFunction.commit();
boolean hasValueParameters = functionDescriptor == null || functionDescriptor.getValueParameters().size() > 0;
context.trace.report(Errors.FUNCTION_CALL_EXPECTED.on(nameExpression, nameExpression, hasValueParameters));
context.trace.report(FUNCTION_CALL_EXPECTED.on(nameExpression, nameExpression, hasValueParameters));
return functionDescriptor != null ? functionDescriptor.getReturnType() : null;
}
@@ -704,17 +705,23 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
context.replaceBindingTrace(traceForFunction), result);
if (result[0]) {
traceForFunction.commit();
if (callExpression.getValueArgumentList() == null && callExpression.getFunctionLiteralArguments().isEmpty()) {
// there are only type arguments
boolean hasValueParameters = functionDescriptor == null || functionDescriptor.getValueParameters().size() > 0;
context.trace.report(FUNCTION_CALL_EXPECTED.on(callExpression, callExpression, hasValueParameters));
}
return functionDescriptor != null ? functionDescriptor.getReturnType() : null;
}
JetExpression calleeExpression = callExpression.getCalleeExpression();
if (calleeExpression instanceof JetSimpleNameExpression) {
if (calleeExpression instanceof JetSimpleNameExpression && callExpression.getTypeArgumentList() == null) {
TemporaryBindingTrace traceForVariable = TemporaryBindingTrace.create(context.trace);
JetType type = getVariableType((JetSimpleNameExpression) calleeExpression, receiver, callOperationNode,
context.replaceBindingTrace(traceForVariable), result);
context.replaceBindingTrace(traceForVariable), result);
if (result[0]) {
traceForVariable.commit();
context.trace.report(Errors.FUNCTION_EXPECTED.on((JetReferenceExpression) calleeExpression, callExpression, type != null ? type : ErrorUtils.createErrorType("")));
context.trace.report(FUNCTION_EXPECTED.on((JetReferenceExpression) calleeExpression, calleeExpression,
type != null ? type : ErrorUtils.createErrorType("")));
return null;
}
}
@@ -722,7 +729,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
return null;
}
private static void checkSuper(@NotNull ReceiverDescriptor receiverDescriptor, @NotNull OverloadResolutionResults<? extends CallableDescriptor> results, @NotNull BindingTrace trace, @NotNull JetExpression expression) {
private static void checkSuper(@NotNull ReceiverDescriptor receiverDescriptor, @NotNull OverloadResolutionResults<? extends CallableDescriptor> results,
@NotNull BindingTrace trace, @NotNull JetExpression expression) {
if (!results.isSingleResult()) return;
if (!(receiverDescriptor instanceof ExpressionReceiver)) return;
JetExpression receiver = ((ExpressionReceiver) receiverDescriptor).getExpression();