diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java index e1c49da6c16..1815b8b37bd 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/inference/ConstraintSystemImpl.java @@ -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(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java index 9bfe8555f3c..3de9e447ba0 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/TypeUtils.java @@ -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 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; } diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2841.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2841.kt index c96ce4a16ca..a132cc388d9 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt2841.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2841.kt @@ -8,7 +8,7 @@ public inline fun T.use1(block: (T)-> R) : R { } fun main(args: Array) { - C().use1 { + C().use1 { w -> // ERROR here x } diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2841_it.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2841_it.kt index 4ba463002ad..aa0fbcbe7bd 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt2841_it.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2841_it.kt @@ -11,8 +11,8 @@ public inline fun T.use(block: (t: T)-> R) : R { } fun test() { - C().use { + C().use { it.close() x } -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2841_it_this.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2841_it_this.kt index 533b0884b5c..988a80d322a 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt2841_it_this.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2841_it_this.kt @@ -11,9 +11,9 @@ public inline fun use(t: T, block: T.(T)-> R) : R { } fun test() { - use(C()) { + use(C()) { this.close() it.close() xx } -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2841_this.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2841_this.kt index cdc9faa55cb..1eb4c5f5808 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt2841_this.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2841_this.kt @@ -11,8 +11,8 @@ public inline fun T.use(block: T.()-> R) : R { } fun test() { - C().use { + C().use { this.close() x } -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt3150.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt3150.kt new file mode 100644 index 00000000000..fb02f82a1e4 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt3150.kt @@ -0,0 +1,24 @@ +package aa + +class Some + +class SomeTemplate { + fun query(some: Class) = some + + + // Uncomment this to get CANNOT_COMPLETE_RESOLVE error + fun query1(some: Class) = some + fun query1(some: Some) = 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)-> } +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index d04388ca45c..86efe992c16 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -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");