KT-3150 Kotlin m4 don't recognize function literals

#KT-3150 fixed

 added check for PLACEHOLDER_FUNCTION_TYPE to constraint system
This commit is contained in:
Svetlana Isakova
2012-12-19 19:50:44 +04:00
parent b467638633
commit 972b234db6
8 changed files with 54 additions and 14 deletions
@@ -24,7 +24,6 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
import org.jetbrains.jet.lang.resolve.calls.CallResolverUtil;
import org.jetbrains.jet.lang.types.*;
import org.jetbrains.jet.lang.types.checker.TypeCheckingProcedure;
import org.jetbrains.jet.lang.resolve.calls.inference.TypeConstraintsImpl.ConstraintKind;
@@ -34,6 +33,7 @@ import java.util.*;
import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.CANT_INFER;
import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.DONT_CARE;
import static org.jetbrains.jet.lang.resolve.calls.CallResolverUtil.PLACEHOLDER_FUNCTION_TYPE;
import static org.jetbrains.jet.lang.resolve.calls.inference.TypeConstraintsImpl.ConstraintKind.*;
import static org.jetbrains.jet.lang.types.Variance.*;
@@ -164,12 +164,13 @@ public class ConstraintSystemImpl implements ConstraintSystem {
@NotNull ConstraintPosition constraintPosition) {
if (constrainingType == TypeUtils.NO_EXPECTED_TYPE
|| TypeUtils.identityEqualsOrContainsAsArgument(constrainingType, DONT_CARE)
|| TypeUtils.identityEqualsOrContainsAsArgument(constrainingType, CANT_INFER)) {
|| constrainingType == DONT_CARE
|| constrainingType == CANT_INFER) {
return;
}
if (constrainingType == null || ErrorUtils.containsErrorType(constrainingType)) {
if (constrainingType == null || (ErrorUtils.containsErrorType(constrainingType)
&& !TypeUtils.equalsOrContainsAsArgument(constrainingType, DONT_CARE, CANT_INFER, PLACEHOLDER_FUNCTION_TYPE))) {
hasErrorInConstrainingTypes = true;
return;
}
@@ -177,6 +178,12 @@ public class ConstraintSystemImpl implements ConstraintSystem {
assert subjectType != TypeUtils.NO_EXPECTED_TYPE : "Subject type shouldn't be NO_EXPECTED_TYPE (in position " + constraintPosition + " )";
if (ErrorUtils.isErrorType(subjectType)) return;
if (constrainingType == PLACEHOLDER_FUNCTION_TYPE) {
if (!KotlinBuiltIns.getInstance().isFunctionType(subjectType)) {
errorConstraintPositions.add(constraintPosition);
}
return;
}
DeclarationDescriptor constrainingTypeDescriptor = constrainingType.getConstructor().getDeclarationDescriptor();
DeclarationDescriptor subjectTypeDescriptor = subjectType.getConstructor().getDeclarationDescriptor();
@@ -488,12 +488,16 @@ public class TypeUtils {
return false;
}
public static boolean identityEqualsOrContainsAsArgument(@Nullable JetType type, @NotNull JetType argumentType) {
public static boolean equalsOrContainsAsArgument(@Nullable JetType type, @NotNull JetType... possibleArgumentTypes) {
return equalsOrContainsAsArgument(type, Sets.newHashSet(possibleArgumentTypes));
}
private static boolean equalsOrContainsAsArgument(@Nullable JetType type, @NotNull Set<JetType> possibleArgumentTypes) {
if (type == null) return false;
if (type == argumentType) return true;
if (possibleArgumentTypes.contains(type)) return true;
if (type instanceof NamespaceType) return false;
for (TypeProjection projection : type.getArguments()) {
if (identityEqualsOrContainsAsArgument(projection.getType(), argumentType)) return true;
if (equalsOrContainsAsArgument(projection.getType(), possibleArgumentTypes)) return true;
}
return false;
}
@@ -8,7 +8,7 @@ public inline fun <T: Closeable, R> T.use1(block: (T)-> R) : R {
}
fun main(args: Array<String>) {
C().<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>use1<!> {
C().use1 {
w -> // ERROR here
<!UNRESOLVED_REFERENCE!>x<!>
}
@@ -11,8 +11,8 @@ public inline fun <T: Closeable, R> T.use(block: (t: T)-> R) : R {
}
fun test() {
C().<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>use<!> {
C().use {
it.close()
<!UNRESOLVED_REFERENCE!>x<!>
}
}
}
@@ -11,9 +11,9 @@ public inline fun <T: Closeable, R> use(t: T, block: T.(T)-> R) : R {
}
fun test() {
<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>use<!>(C()) {
use(C()) {
this.close()
it.close()
<!UNRESOLVED_REFERENCE!>xx<!>
}
}
}
@@ -11,8 +11,8 @@ public inline fun <T: Closeable, R> T.use(block: T.()-> R) : R {
}
fun test() {
C().<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>use<!> {
C().use {
this.close()
<!UNRESOLVED_REFERENCE!>x<!>
}
}
}
@@ -0,0 +1,24 @@
package aa
class Some<T>
class SomeTemplate {
fun <T> query(some: Class<T>) = some
// Uncomment this to get CANNOT_COMPLETE_RESOLVE error
fun <T> query1(some: Class<T>) = some
fun <T> query1(some: Some<T>) = some
}
fun SomeTemplate.query(f: (i: Int) -> Unit) = f
fun SomeTemplate.query1(f: (i: Int) -> Unit) = f
fun test() {
val mapperFunction = {(i: Int)-> }
SomeTemplate().query(mapperFunction)
// TYPE_MISMATCH: Required Class<[ERROR: CANT_INFER]>, Found (jet.Int) -> Unit
SomeTemplate().query {(i: Int)-> }
SomeTemplate().query1 {(i: Int)-> }
}
@@ -2212,6 +2212,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
doTest("compiler/testData/diagnostics/tests/inference/regressions/kt2842.kt");
}
@TestMetadata("kt3150.kt")
public void testKt3150() throws Exception {
doTest("compiler/testData/diagnostics/tests/inference/regressions/kt3150.kt");
}
@TestMetadata("kt702.kt")
public void testKt702() throws Exception {
doTest("compiler/testData/diagnostics/tests/inference/regressions/kt702.kt");