Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
// KT-258 Support equality constraints in type inference
|
||||
|
||||
import java.util.*
|
||||
|
||||
fun test() {
|
||||
val attributes : HashMap<String, String> = HashMap()
|
||||
attributes["href"] = "1" // inference fails, but it shouldn't
|
||||
}
|
||||
|
||||
fun <K, V> java.util.Map<K, V>.set(key : K, value : V) {}//= this.put(key, value)
|
||||
@@ -0,0 +1,11 @@
|
||||
// KT-287 Infer constructor type arguments
|
||||
import java.util.*
|
||||
|
||||
fun attributes() : Map<String, String> = HashMap() // Should be inferred;
|
||||
val attributes : Map<String, String> = HashMap() // Should be inferred;
|
||||
|
||||
fun foo(m : Map<String, String>) {}
|
||||
|
||||
fun test() {
|
||||
foo(HashMap())
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
// KT-459 Type argument inference fails when class names are fully qualified
|
||||
|
||||
fun test() {
|
||||
val attributes : java.util.HashMap<String, String> = java.util.HashMap() // failure!
|
||||
attributes["href"] = "1" // inference fails, but it shouldn't
|
||||
}
|
||||
|
||||
fun <K, V> java.util.Map<K, V>.set(key : K, value : V) {}//= this.put(key, value)
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// http://youtrack.jetbrains.net/issue/KT-419
|
||||
|
||||
class A(w: Int) {
|
||||
var c = w
|
||||
|
||||
{
|
||||
c = 81
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// http://youtrack.jetbrains.net/issue/KT-449
|
||||
|
||||
class A {
|
||||
class B {
|
||||
<!CLASS_OBJECT_NOT_ALLOWED!>class object { }<!>
|
||||
}
|
||||
}
|
||||
|
||||
class B {
|
||||
class object {
|
||||
class B {
|
||||
class object {
|
||||
class C {
|
||||
class object { }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
class C<T>() {
|
||||
fun foo() : T <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!>
|
||||
}
|
||||
|
||||
fun foo(c: C<Int>) {}
|
||||
fun bar<T>() : C<T> <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!>
|
||||
|
||||
fun main(args : Array<String>) {
|
||||
val a : C<Int> = C();
|
||||
val x : C<in String> = C()
|
||||
val y : C<out String> = C()
|
||||
val z : C<*> = C()
|
||||
|
||||
val ba : C<Int> = bar();
|
||||
val bx : C<in String> = bar()
|
||||
val by : C<out String> = bar()
|
||||
val bz : C<*> = bar()
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
class Point() {
|
||||
}
|
||||
|
||||
class G<T>() {}
|
||||
|
||||
fun f<T>(expression : T) : G<out T> = G<T>
|
||||
|
||||
|
||||
fun foo() : G<Point> {
|
||||
val p = Point()
|
||||
return <!TYPE_MISMATCH!>f<Point>(p)<!>
|
||||
}
|
||||
|
||||
class Out<out T>() {}
|
||||
|
||||
fun fout<T>(expression : T) : Out<out T> = Out<T>
|
||||
|
||||
fun fooout() : Out<Point> {
|
||||
val p = Point();
|
||||
return fout<Point>(p);
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
// KT-353 Generic type argument inference sometimes doesn't work
|
||||
|
||||
trait A {
|
||||
fun <T> gen() : T
|
||||
}
|
||||
|
||||
fun foo(a: A) {
|
||||
val g : fun() : Unit = {
|
||||
a.gen() //it works: Unit is derived
|
||||
}
|
||||
|
||||
val u: Unit = a.gen() //type mismatch, but Unit can be derived
|
||||
|
||||
if (true) {
|
||||
a.gen() //it works: Unit is derived
|
||||
}
|
||||
|
||||
val b : fun() : Unit = {
|
||||
if (true) {
|
||||
a.gen() //type mismatch, but Unit can be derived
|
||||
}
|
||||
else {
|
||||
()
|
||||
}
|
||||
}
|
||||
|
||||
val f : fun() : Int = { () : Int =>
|
||||
a.gen() //type mismatch, but Int can be derived
|
||||
}
|
||||
|
||||
a.gen() //it works: Unit is derived
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// KT-399 Type argument inference not implemented for CALL_EXPRESSION
|
||||
|
||||
fun <T> getSameTypeChecker(obj: T) : Function1<Any,Boolean> {
|
||||
return { (a : Any) => a is T }
|
||||
}
|
||||
|
||||
fun box() : String {
|
||||
if(getSameTypeChecker<String>("lala")(10)) return "fail"
|
||||
if(!getSameTypeChecker<String>("mama")("lala")) return "fail"
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,35 +1,14 @@
|
||||
namespace x
|
||||
|
||||
class Outer(val name: String) {
|
||||
class Inner() {
|
||||
val me = name
|
||||
|
||||
class object {
|
||||
fun bar() = "bar"
|
||||
}
|
||||
}
|
||||
class Outer() {
|
||||
|
||||
class object {
|
||||
class StaticInner() {
|
||||
class object {
|
||||
fun f() = "oo"
|
||||
}
|
||||
class Inner() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box (): String {
|
||||
val inner = Outer("mama").Inner() //verify error
|
||||
if(inner.me != "mama")
|
||||
return "fail"
|
||||
|
||||
val outer = Outer ("papa")
|
||||
val inner2 = outer.Inner ()
|
||||
if(inner2.me != "papa")
|
||||
return "fail"
|
||||
|
||||
if(Outer.StaticInner.f() != "oo" )
|
||||
return "fail"
|
||||
|
||||
val inner = Outer.Inner()
|
||||
return "OK"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user