KT-339 Allow to omit Unit return type from function types
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fun foo(f : fun()) {
|
||||
val x : Unit = f()
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user