From 826936785a95776af9ca47c3f12451b19fefa3f3 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Thu, 2 Jun 2011 06:26:33 +0400 Subject: [PATCH] A bug with single-parameter closures without type annotations fixed --- .../lang/parsing/JetExpressionParsing.java | 2 ++ .../jet/lang/types/JetTypeInferrer.java | 11 +++++-- idea/testData/psi/FunctionLiterals.txt | 5 +-- idea/testData/psi/FunctionLiterals_ERR.txt | 33 ++++++++++--------- .../psi/examples/FunctionsAndTypes.txt | 5 +-- idea/testData/psi/examples/Graph.txt | 5 +-- 6 files changed, 37 insertions(+), 24 deletions(-) diff --git a/idea/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java b/idea/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java index c8d070b14fa..97ef6239ea2 100644 --- a/idea/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java +++ b/idea/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java @@ -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 '=>'"); diff --git a/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java b/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java index 11af9e4e6b2..359cfec1ea5 100644 --- a/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java +++ b/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java @@ -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); diff --git a/idea/testData/psi/FunctionLiterals.txt b/idea/testData/psi/FunctionLiterals.txt index c93583fdf25..56b707fe898 100644 --- a/idea/testData/psi/FunctionLiterals.txt +++ b/idea/testData/psi/FunctionLiterals.txt @@ -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(' ') diff --git a/idea/testData/psi/FunctionLiterals_ERR.txt b/idea/testData/psi/FunctionLiterals_ERR.txt index b91f2080ffc..71a803d5c53 100644 --- a/idea/testData/psi/FunctionLiterals_ERR.txt +++ b/idea/testData/psi/FunctionLiterals_ERR.txt @@ -14,9 +14,10 @@ JetFile: FunctionLiterals_ERR.jet FUNCTION_LITERAL PsiElement(LBRACE)('{') PsiWhiteSpace(' ') - VALUE_PARAMETER - PsiErrorElement:Expecting parameter name - + VALUE_PARAMETER_LIST + VALUE_PARAMETER + PsiErrorElement:Expecting parameter name + 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(' ') diff --git a/idea/testData/psi/examples/FunctionsAndTypes.txt b/idea/testData/psi/examples/FunctionsAndTypes.txt index eb5b9249016..eddad940987 100644 --- a/idea/testData/psi/examples/FunctionsAndTypes.txt +++ b/idea/testData/psi/examples/FunctionsAndTypes.txt @@ -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(' ') diff --git a/idea/testData/psi/examples/Graph.txt b/idea/testData/psi/examples/Graph.txt index ba398dacba3..d497f822a97 100644 --- a/idea/testData/psi/examples/Graph.txt +++ b/idea/testData/psi/examples/Graph.txt @@ -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 ')