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
|
* functionType
|
||||||
* : "fun" (type ".")? functionTypeContents
|
* : "fun" (type ".")? "(" (parameter | modifiers type){","} ")" (":" type)? // Unit by default
|
||||||
* ;
|
* ;
|
||||||
*/
|
*/
|
||||||
private void parseFunctionType() {
|
private void parseFunctionType() {
|
||||||
@@ -1446,22 +1446,15 @@ public class JetParsing extends AbstractJetParsing {
|
|||||||
advance(); // DOT
|
advance(); // DOT
|
||||||
}
|
}
|
||||||
|
|
||||||
parseFunctionTypeContents();
|
|
||||||
|
|
||||||
functionType.done(FUNCTION_TYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* functionTypeContents
|
|
||||||
* : "(" (parameter | type){","} ")" ":" type
|
|
||||||
* ;
|
|
||||||
*/
|
|
||||||
private void parseFunctionTypeContents() {
|
|
||||||
parseValueParameterList(true, TokenSet.EMPTY);
|
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 {
|
else {
|
||||||
if (actualArgumentCount != expectedArgumentCount) {
|
if (actualArgumentCount != expectedArgumentCount) {
|
||||||
// String errorMessage = (expectedArgumentCount == 0 ? "No" : expectedArgumentCount) + " type arguments expected";
|
|
||||||
if (actualArgumentCount == 0) {
|
if (actualArgumentCount == 0) {
|
||||||
// trace.getErrorHandler().genericError(type.getNode(), errorMessage);
|
|
||||||
trace.report(WRONG_NUMBER_OF_TYPE_ARGUMENTS.on(type, expectedArgumentCount));
|
trace.report(WRONG_NUMBER_OF_TYPE_ARGUMENTS.on(type, expectedArgumentCount));
|
||||||
} else {
|
} else {
|
||||||
// trace.getErrorHandler().genericError(type.getTypeArgumentList().getNode(), errorMessage);
|
|
||||||
trace.report(WRONG_NUMBER_OF_TYPE_ARGUMENTS.on(type.getTypeArgumentList(), expectedArgumentCount));
|
trace.report(WRONG_NUMBER_OF_TYPE_ARGUMENTS.on(type.getTypeArgumentList(), expectedArgumentCount));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -160,10 +157,14 @@ public class TypeResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JetTypeReference returnTypeRef = type.getReturnTypeRef();
|
JetTypeReference returnTypeRef = type.getReturnTypeRef();
|
||||||
|
JetType returnType;
|
||||||
if (returnTypeRef != null) {
|
if (returnTypeRef != null) {
|
||||||
JetType returnType = resolveType(scope, returnTypeRef);
|
returnType = resolveType(scope, returnTypeRef);
|
||||||
result[0] = JetStandardClasses.getFunctionType(annotations, receiverType, parameterTypes, returnType);
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
returnType = JetStandardClasses.getUnitType();
|
||||||
|
}
|
||||||
|
result[0] = JetStandardClasses.getFunctionType(annotations, receiverType, parameterTypes, returnType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo(f : fun()) {
|
||||||
|
val x : Unit = f()
|
||||||
|
}
|
||||||
@@ -47,11 +47,7 @@ optionalProjection
|
|||||||
;
|
;
|
||||||
|
|
||||||
functionType
|
functionType
|
||||||
: "fun" (type ".")? functionTypeContents
|
: "fun" (type ".")? "(" (parameter | modifiers /*lazy out ref*/ type){","} ")" (":" type)? // Unit by default
|
||||||
;
|
|
||||||
|
|
||||||
functionTypeContents
|
|
||||||
: "(" (parameter | modifiers /*lazy out ref*/ type){","} ")" ":" type
|
|
||||||
;
|
;
|
||||||
|
|
||||||
tupleType
|
tupleType
|
||||||
|
|||||||
Reference in New Issue
Block a user