A bug with single-parameter closures without type annotations fixed

This commit is contained in:
Andrey Breslav
2011-06-02 06:26:33 +04:00
parent 13808dcf9b
commit 826936785a
6 changed files with 37 additions and 24 deletions
@@ -1024,6 +1024,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
}
}
} else if (!dontExpectParameters) {
PsiBuilder.Marker parameterList = mark();
PsiBuilder.Marker parameter = mark();
int parameterNamePos = matchTokenStreamPredicate(new LastBefore(new At(IDENTIFIER), new AtOffset(doubleArrowPos)));
@@ -1041,6 +1042,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
errorUntilOffset("Expecting '=>'", doubleArrowPos);
}
parameterList.done(VALUE_PARAMETER_LIST);
}
expectNoAdvance(DOUBLE_ARROW, "Expecting '=>'");
@@ -756,10 +756,15 @@ public class JetTypeInferrer {
for (int i = 0, parametersSize = parameters.size(); i < parametersSize; i++) {
JetParameter parameter = parameters.get(i);
JetTypeReference typeReference = parameter.getTypeReference();
if (typeReference == null) {
throw new UnsupportedOperationException("Type inference for parameters is not implemented yet");
JetType type;
if (typeReference != null) {
type = typeResolver.resolveType(scope, typeReference);
}
else {
trace.getErrorHandler().genericError(parameter.getNode(), "Type inference for parameters is not implemented yet");
type = ErrorUtils.createErrorType("Not inferred");
}
JetType type = typeResolver.resolveType(scope, typeReference);
ValueParameterDescriptor valueParameterDescriptor = classDescriptorResolver.resolveValueParameterDescriptor(functionDescriptor, parameter, i, type);
parameterTypes.add(valueParameterDescriptor.getOutType());
valueParameterDescriptors.add(valueParameterDescriptor);
+3 -2
View File
@@ -26,8 +26,9 @@ JetFile: FunctionLiterals.jet
PsiWhiteSpace('\n\n ')
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('a')
VALUE_PARAMETER_LIST
VALUE_PARAMETER
PsiElement(IDENTIFIER)('a')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
+18 -15
View File
@@ -14,9 +14,10 @@ JetFile: FunctionLiterals_ERR.jet
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
PsiWhiteSpace(' ')
VALUE_PARAMETER
PsiErrorElement:Expecting parameter name
<empty list>
VALUE_PARAMETER_LIST
VALUE_PARAMETER
PsiErrorElement:Expecting parameter name
<empty list>
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
BODY
@@ -26,12 +27,13 @@ JetFile: FunctionLiterals_ERR.jet
PsiWhiteSpace('\n ')
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('a')
PsiErrorElement:To specify many parameters, use the full notation: {(p1, p2, ...) => ...}
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('b')
VALUE_PARAMETER_LIST
VALUE_PARAMETER
PsiElement(IDENTIFIER)('a')
PsiErrorElement:To specify many parameters, use the full notation: {(p1, p2, ...) => ...}
PsiElement(COMMA)(',')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('b')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
@@ -275,13 +277,14 @@ JetFile: FunctionLiterals_ERR.jet
PsiWhiteSpace('\n\n ')
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('a')
PsiWhiteSpace(' ')
PsiErrorElement:To specify a type of a parameter or a return type, use the full notation: {(parameter : Type) : ReturnType => ...}
PsiElement(COLON)(':')
VALUE_PARAMETER_LIST
VALUE_PARAMETER
PsiElement(IDENTIFIER)('a')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('b')
PsiErrorElement:To specify a type of a parameter or a return type, use the full notation: {(parameter : Type) : ReturnType => ...}
PsiElement(COLON)(':')
PsiWhiteSpace(' ')
PsiElement(IDENTIFIER)('b')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
@@ -600,8 +600,9 @@ JetFile: FunctionsAndTypes.jet
PsiWhiteSpace(' ')
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('t')
VALUE_PARAMETER_LIST
VALUE_PARAMETER
PsiElement(IDENTIFIER)('t')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace(' ')
+3 -2
View File
@@ -944,8 +944,9 @@ JetFile: Graph.jet
FUNCTION_LITERAL
PsiElement(LBRACE)('{')
PsiWhiteSpace(' ')
VALUE_PARAMETER
PsiElement(IDENTIFIER)('n')
VALUE_PARAMETER_LIST
VALUE_PARAMETER
PsiElement(IDENTIFIER)('n')
PsiWhiteSpace(' ')
PsiElement(DOUBLE_ARROW)('=>')
PsiWhiteSpace('\n ')