treat function literals without value argument list

as without arguments by default
This commit is contained in:
Svetlana Isakova
2013-10-16 19:08:22 +04:00
parent ab7e3ce78c
commit 9fc66d686e
4 changed files with 22 additions and 9 deletions
@@ -225,20 +225,22 @@ public class ArgumentTypeResolver {
@NotNull ResolveArgumentsMode resolveArgumentsMode
) {
if (resolveArgumentsMode == SKIP_FUNCTION_ARGUMENTS) {
JetType type = getFunctionLiteralType(functionLiteralExpression, context.scope, context.trace);
JetType type = getShapeTypeOfFunctionLiteral(functionLiteralExpression, context.scope, context.trace, true);
return JetTypeInfo.create(type, context.dataFlowInfo);
}
return expressionTypingServices.getTypeInfo(expression, context);
}
@Nullable
public JetType getFunctionLiteralType(
public JetType getShapeTypeOfFunctionLiteral(
@NotNull JetFunctionLiteralExpression expression,
@NotNull JetScope scope,
@NotNull BindingTrace trace
@NotNull BindingTrace trace,
boolean expectedTypeIsUnknown
) {
if (expression.getFunctionLiteral().getValueParameterList() == null) {
return PLACEHOLDER_FUNCTION_TYPE;
return expectedTypeIsUnknown ? PLACEHOLDER_FUNCTION_TYPE : KotlinBuiltIns.getInstance().getFunctionType(
Collections.<AnnotationDescriptor>emptyList(), null, Collections.<JetType>emptyList(), DONT_CARE);
}
List<JetParameter> valueParameters = expression.getValueParameters();
TemporaryBindingTrace temporaryTrace = TemporaryBindingTrace.create(
@@ -25,6 +25,7 @@ import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.calls.autocasts.*;
@@ -48,10 +49,7 @@ import org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import static org.jetbrains.jet.lang.diagnostics.Errors.PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT;
import static org.jetbrains.jet.lang.diagnostics.Errors.SUPER_IS_NOT_AN_EXPRESSION;
@@ -477,7 +475,7 @@ public class CandidateResolver {
JetType effectiveExpectedType = getEffectiveExpectedType(valueParameterDescriptor, valueArgument);
JetType expectedType = constraintSystem.getCurrentSubstitutor().substitute(effectiveExpectedType, Variance.INVARIANT);
if (expectedType == null || expectedType == DONT_CARE) {
expectedType = argumentTypeResolver.getFunctionLiteralType(functionLiteralExpression, context.scope, context.trace);
expectedType = argumentTypeResolver.getShapeTypeOfFunctionLiteral(functionLiteralExpression, context.scope, context.trace, false);
}
if (expectedType == null || !KotlinBuiltIns.getInstance().isFunctionOrExtensionFunctionType(expectedType)
|| CallResolverUtil.hasUnknownFunctionParameter(expectedType)) {
@@ -0,0 +1,8 @@
class TypeOf<T>(t: T)
fun <T> id(t: T) = t
fun foo() {
val i = id { 22 } //type inference error: no information for parameter
TypeOf(i): TypeOf<()->Int>
}
@@ -2715,6 +2715,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
doTest("compiler/testData/diagnostics/tests/functionLiterals/functionLIteralInBlockInIf.kt");
}
@TestMetadata("functionLiteralWithoutArgumentList.kt")
public void testFunctionLiteralWithoutArgumentList() throws Exception {
doTest("compiler/testData/diagnostics/tests/functionLiterals/functionLiteralWithoutArgumentList.kt");
}
@TestMetadata("kt2906.kt")
public void testKt2906() throws Exception {
doTest("compiler/testData/diagnostics/tests/functionLiterals/kt2906.kt");