Distinguish between no declared arguments and an empty argument list

in a function literal
If there are no arguments, any number of them might be expected
This commit is contained in:
Svetlana Isakova
2015-05-25 14:24:35 +03:00
committed by Alexander Udalov
parent d9568ef88c
commit 14c2690447
6 changed files with 32 additions and 8 deletions
@@ -233,7 +233,7 @@ public class ArgumentTypeResolver {
boolean isFunctionLiteral = function instanceof JetFunctionLiteral;
if (function.getValueParameterList() == null && isFunctionLiteral) {
return expectedTypeIsUnknown
? ErrorUtils.createFunctionPlaceholderType(Collections.<JetType>emptyList())
? ErrorUtils.createFunctionPlaceholderType(Collections.<JetType>emptyList(), /* hasDeclaredArguments = */ false)
: builtIns.getFunctionType(Annotations.EMPTY, null, Collections.<JetType>emptyList(), DONT_CARE);
}
List<JetParameter> valueParameters = function.getValueParameters();
@@ -248,7 +248,7 @@ public class ArgumentTypeResolver {
JetType receiverType = resolveTypeRefWithDefault(function.getReceiverTypeReference(), scope, temporaryTrace, null);
return expectedTypeIsUnknown && isFunctionLiteral
? ErrorUtils.createFunctionPlaceholderType(parameterTypes)
? ErrorUtils.createFunctionPlaceholderType(parameterTypes, /* hasDeclaredArguments = */ true)
: builtIns.getFunctionType(Annotations.EMPTY, receiverType, parameterTypes, returnType);
}
@@ -0,0 +1,8 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun foo(g: () -> Int) {}
fun foo(f: (Int) -> Int) {}
fun test() {
foo { -> 42 }
}
@@ -0,0 +1,5 @@
package
internal fun foo(/*0*/ g: () -> kotlin.Int): kotlin.Unit
internal fun foo(/*0*/ f: (kotlin.Int) -> kotlin.Int): kotlin.Unit
internal fun test(): kotlin.Unit
@@ -9012,6 +9012,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("EmptyArgumentListInLambda.kt")
public void testEmptyArgumentListInLambda() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/overload/EmptyArgumentListInLambda.kt");
doTest(fileName);
}
@TestMetadata("ExtFunDifferentReceiver.kt")
public void testExtFunDifferentReceiver() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/overload/ExtFunDifferentReceiver.kt");