Constraint incorporation

In a constraint system a new bound is incorporated:
all new constrains that can be derived from it
(and from existing ones) are added
This commit is contained in:
Svetlana Isakova
2015-06-27 13:49:11 +03:00
parent 82acce4767
commit 9a5abf368f
30 changed files with 531 additions and 225 deletions
@@ -1,10 +1,10 @@
package foo
open class A {
val B.w: Int by <!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>MyProperty<!>()
val B.w: Int by <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>MyProperty<!>()
}
val B.r: Int by <!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>MyProperty<!>()
val B.r: Int by <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>MyProperty<!>()
val A.e: Int by MyProperty()
@@ -7,6 +7,6 @@ fun <T, C: Collection<T>> convert(src: Collection<T>, dest: C): C = throw Except
fun test(l: List<Int>) {
//todo should be inferred
val r = <!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>convert<!>(l, <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>HashSet<!>())
checkSubtype<Int>(<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>r<!>)
val r = convert(l, HashSet())
checkSubtype<Collection<Int>>(r)
}
@@ -29,8 +29,7 @@ fun test3() {
fun <T, R: T> emptyStrangeMap1(t: T): Map<T, R> = throw Exception("$t")
fun test4() {
//todo we may infer 'Int' for 'R' here
<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>emptyStrangeMap1<!>(1)
emptyStrangeMap1(1)
}
//--------------
@@ -38,8 +37,7 @@ fun test4() {
fun <T: A, R: T> emptyStrangeMap2(t: T): Map<T, R> where R: A = throw Exception("$t")
fun test5(a: A) {
//todo we may infer 'A' for 'R' here
<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>emptyStrangeMap2<!>(a)
emptyStrangeMap2(a)
}
//--------------
@@ -16,11 +16,10 @@ public class HS<T> extends Base<T> {}
import foo.*;
import java.util.HashSet
fun <T, C: Base<T>> convert(src: HS<T>, dest: C): C = throw Exception("$src $dest")
fun test(l: HS<Int>) {
//todo should be inferred
val r = <!TYPE_INFERENCE_UPPER_BOUND_VIOLATED!>convert<!>(l, <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>HS<!>())
checkSubtype<Int>(<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>r<!>)
val r = convert(l, HS())
checkSubtype<Base<Int>>(r)
}
@@ -1,4 +1,4 @@
fun bar() {
fun <T: <!CYCLIC_GENERIC_UPPER_BOUND!>T?<!>> foo() {}
foo()
<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!>()
}
@@ -1,10 +1,8 @@
// !CHECK_TYPE
interface Inv<I>
fun <S, T: S> Inv<T>.reduce2(): S = null!!
fun test(a: Inv<Int>): Int {
val b = 1 <!OVERLOAD_RESOLUTION_AMBIGUITY!>+<!> a.reduce2()
return <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>b<!>
val b = 1 + a.reduce2()
return b
}
@@ -6,7 +6,12 @@ fun <D, E : D> List<ResolutionTask<D, E>>.bar(t: ResolutionTask<D, E>) = t
public class ResolutionTaskHolder<F, G : F> {
fun test(candidate: ResolutionCandidate<F>, tasks: MutableList<ResolutionTask<F, G>>) {
tasks.bar(ResolutionTask(candidate))
tasks.bar(ResolutionTask<F, G>(candidate))
tasks.add(ResolutionTask<F, G>(candidate))
//todo the problem is the type of ResolutionTask is inferred as ResolutionTask<F, F> too early
tasks.<!TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>bar<!>(ResolutionTask(candidate))
tasks.<!NONE_APPLICABLE!>add<!>(ResolutionTask(candidate))
}
}
@@ -6,10 +6,10 @@ fun main(args:Array<String>) {
val startTimeNanos = System.nanoTime()
// the problem sits on the next line:
val pi = 4.0.toDouble() * delta <!OVERLOAD_RESOLUTION_AMBIGUITY!>*<!> (1..n).reduce(
val pi = 4.0.toDouble() * delta <!OVERLOAD_RESOLUTION_AMBIGUITY!>*<!> (1..n).<!TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS!>reduce<!>(
{t, i ->
val x = (i - 0.5) * delta
<!TYPE_MISMATCH!>t + 1.0 / (1.0 + x * x)<!>
t + 1.0 / (1.0 + x * x)
})
// !!! pi has error type here
@@ -12,7 +12,7 @@ fun bar() {
Resolved call:
Candidate descriptor: fun <T> foo(t: T): Unit defined in root package
Resulting descriptor: fun <T> foo(t: List<???>): Unit defined in root package
Resulting descriptor: fun <T> foo(t: ???): Unit defined in root package
Explicit receiver kind = NO_EXPLICIT_RECEIVER
Dispatch receiver = NO_RECEIVER
@@ -20,4 +20,4 @@ Extension receiver = NO_RECEIVER
Value arguments mapping:
MATCH_MODULO_UNINFERRED_TYPES t : List<???> = someList()
MATCH_MODULO_UNINFERRED_TYPES t : ??? = someList()
@@ -12,7 +12,7 @@ fun bar() {
Resolved call:
Candidate descriptor: fun <T> foo(t: T): Unit defined in root package
Resulting descriptor: fun <T> foo(t: MutableList<???>): Unit defined in root package
Resulting descriptor: fun <T> foo(t: ???): Unit defined in root package
Explicit receiver kind = NO_EXPLICIT_RECEIVER
Dispatch receiver = NO_RECEIVER
@@ -20,4 +20,4 @@ Extension receiver = NO_RECEIVER
Value arguments mapping:
MATCH_MODULO_UNINFERRED_TYPES t : MutableList<???> = someList()
MATCH_MODULO_UNINFERRED_TYPES t : ??? = someList()