Fix false positive "Cannot capture" error reporting

There is no need to report an error in case of non-top-level
capture conversion, just don't add relevant capture type in the system instead

If system can be solved successfully without captured type, then it's just fine
(see KT-13950)
In case of contradiction TYPE_INFERENCE_PARAMETER_CONSTRAINT_ERROR is reported

 #KT-13950 Fixed
This commit is contained in:
Denis Zharkov
2016-09-21 11:57:28 +03:00
parent 4431c6ad02
commit 6663054f4d
10 changed files with 67 additions and 23 deletions
@@ -1,10 +1,8 @@
// !DIAGNOSTICS_NUMBER: 1
// !DIAGNOSTICS: TYPE_INFERENCE_CANNOT_CAPTURE_TYPES
class My<R, T>
fun <R : Any> bar(a: Array<R>): Array<R?> = null!!
fun <R, T> foo(my: My<Array<R>, T>): My<Array<R>, T> = my
fun test11(my: My<Array<out Int>, out Int>) {
foo(my)
}
fun test1(a: Array<in Int>) {
val r: Array<in Int?> = bar(a)
}
@@ -1,2 +1,2 @@
<!-- typeInferenceCannotCaptureTypes1 -->
Type inference failed: 'R' cannot capture 'out Int'. Only top-level type projections can be captured
Type inference failed: 'R' cannot capture 'in Int'. Type parameter has an upper bound 'Any' that cannot be satisfied capturing 'in' projection