use data flow info in constraint system

intersect data flow value possible types
add intersection type (or exact type for the most cases) as a lower bound to constraint system

always get common super type for intersection type as a result
(avoid returning it, even in error messages)
This commit is contained in:
Svetlana Isakova
2013-07-29 16:32:37 +04:00
parent b91846eb5d
commit 27cff93ed8
7 changed files with 195 additions and 2 deletions
@@ -0,0 +1,40 @@
//KT-1355 Type inference fails with autocast and generic function
//tests for Map.set
package a
import java.util.HashMap
fun foo(map: MutableMap<Int, String>, value: String?) {
if (value != null) {
map.put(1, value) //ok
map.set(1, value) //type inference failed
map[1] = value //type inference failed
}
}
//---------------------------
public data open class Tag(public var tagName: String) {
public val attributes: MutableMap<String, String> = HashMap<String, String>()
public val contents: MutableList<Tag> = arrayListOf()
public var id: String?
get() = attributes["id"]
set(value) {
if(value == null) {
attributes.remove("id")
}
else {
attributes["id"] = value<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
attributes["id"] = value
}
}
}
//from library
fun <K, V> MutableMap<K, V>.set(key : K, value : V) = this.put(key, value)
fun arrayListOf<T>(vararg <!UNUSED_PARAMETER!>values<!>: T): MutableList<T> = throw Exception()