diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java index 6637d0bedec..9ab713325aa 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetParsing.java @@ -1429,7 +1429,7 @@ public class JetParsing extends AbstractJetParsing { /* * functionType - * : "fun" (type ".")? functionTypeContents + * : "fun" (type ".")? "(" (parameter | modifiers type){","} ")" (":" type)? // Unit by default * ; */ private void parseFunctionType() { @@ -1446,22 +1446,15 @@ public class JetParsing extends AbstractJetParsing { advance(); // DOT } - parseFunctionTypeContents(); - - functionType.done(FUNCTION_TYPE); - } - - /* - * functionTypeContents - * : "(" (parameter | type){","} ")" ":" type - * ; - */ - private void parseFunctionTypeContents() { parseValueParameterList(true, TokenSet.EMPTY); - expect(COLON, "Expecting ':' followed by a return type", TYPE_REF_FIRST); + if (at(COLON)) { + advance(); // COLON // expect(COLON, "Expecting ':' followed by a return type", TYPE_REF_FIRST); - parseTypeRef(); + parseTypeRef(); + } + + functionType.done(FUNCTION_TYPE); } /* diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeResolver.java index 76c23ca970d..fd60a354043 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeResolver.java @@ -105,12 +105,9 @@ public class TypeResolver { } else { if (actualArgumentCount != expectedArgumentCount) { -// String errorMessage = (expectedArgumentCount == 0 ? "No" : expectedArgumentCount) + " type arguments expected"; if (actualArgumentCount == 0) { -// trace.getErrorHandler().genericError(type.getNode(), errorMessage); trace.report(WRONG_NUMBER_OF_TYPE_ARGUMENTS.on(type, expectedArgumentCount)); } else { -// trace.getErrorHandler().genericError(type.getTypeArgumentList().getNode(), errorMessage); trace.report(WRONG_NUMBER_OF_TYPE_ARGUMENTS.on(type.getTypeArgumentList(), expectedArgumentCount)); } } else { @@ -160,10 +157,14 @@ public class TypeResolver { } JetTypeReference returnTypeRef = type.getReturnTypeRef(); + JetType returnType; if (returnTypeRef != null) { - JetType returnType = resolveType(scope, returnTypeRef); - result[0] = JetStandardClasses.getFunctionType(annotations, receiverType, parameterTypes, returnType); + returnType = resolveType(scope, returnTypeRef); } + else { + returnType = JetStandardClasses.getUnitType(); + } + result[0] = JetStandardClasses.getFunctionType(annotations, receiverType, parameterTypes, returnType); } @Override diff --git a/compiler/testData/checkerWithErrorTypes/quick/UnitByDefaultForFunctionTypes.jet b/compiler/testData/checkerWithErrorTypes/quick/UnitByDefaultForFunctionTypes.jet new file mode 100644 index 00000000000..383e67e16c4 --- /dev/null +++ b/compiler/testData/checkerWithErrorTypes/quick/UnitByDefaultForFunctionTypes.jet @@ -0,0 +1,3 @@ +fun foo(f : fun()) { + val x : Unit = f() +} \ No newline at end of file diff --git a/grammar/src/types.grm b/grammar/src/types.grm index a0c3ce44679..b92457e67ce 100644 --- a/grammar/src/types.grm +++ b/grammar/src/types.grm @@ -47,11 +47,7 @@ optionalProjection ; functionType - : "fun" (type ".")? functionTypeContents - ; - -functionTypeContents - : "(" (parameter | modifiers /*lazy out ref*/ type){","} ")" ":" type + : "fun" (type ".")? "(" (parameter | modifiers /*lazy out ref*/ type){","} ")" (":" type)? // Unit by default ; tupleType