'quick' directory renamed to 'tests' which reflects its contents
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
class A() {
|
||||
fun plus(<!UNUSED_PARAMETER!>i<!> : Int) {}
|
||||
fun minus() {}
|
||||
fun contains(<!UNUSED_PARAMETER!>a<!> : Any?) : Boolean = true
|
||||
}
|
||||
|
||||
fun A.div(<!UNUSED_PARAMETER!>i<!> : Int) {}
|
||||
fun A?.times(<!UNUSED_PARAMETER!>i<!> : Int) {}
|
||||
|
||||
fun test(x : Int?, a : A?) {
|
||||
x<!UNSAFE_CALL!>.<!>plus(1)
|
||||
x?.plus(1)
|
||||
x <!UNSAFE_INFIX_CALL!>plus<!> 1
|
||||
x <!UNSAFE_INFIX_CALL!>+<!> 1
|
||||
<!UNSAFE_CALL!>-<!>x
|
||||
x<!UNSAFE_CALL!>.<!>minus()
|
||||
x?.minus()
|
||||
|
||||
a<!UNSAFE_CALL!>.<!>plus(1)
|
||||
a?.plus(1)
|
||||
a <!UNSAFE_INFIX_CALL!>plus<!> 1
|
||||
a <!UNSAFE_INFIX_CALL!>+<!> 1
|
||||
<!UNSAFE_CALL!>-<!>a
|
||||
a<!UNSAFE_CALL!>.<!>minus()
|
||||
a?.minus()
|
||||
|
||||
a<!UNSAFE_CALL!>.<!>div(1)
|
||||
a <!UNSAFE_INFIX_CALL!>/<!> 1
|
||||
a <!UNSAFE_INFIX_CALL!>div<!> 1
|
||||
a?.div(1)
|
||||
|
||||
a.times(1)
|
||||
a * 1
|
||||
a times 1
|
||||
a<!UNNECESSARY_SAFE_CALL!>?.<!>times(1)
|
||||
|
||||
1 <!UNSAFE_INFIX_CALL!>in<!> a
|
||||
a <!UNSAFE_INFIX_CALL!>contains<!> 1
|
||||
a<!UNSAFE_CALL!>.<!>contains(1)
|
||||
a?.contains(1)
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
fun test() {
|
||||
val out : Int? = null
|
||||
val x : Nothing? = null
|
||||
if (out != x)
|
||||
out.plus(1)
|
||||
if (out == x) return
|
||||
out.plus(1)
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
class Foo {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
fun Any?.foo() {}
|
||||
|
||||
fun test(f : Foo?) {
|
||||
f.foo()
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
class A {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
fun A.bar() {}
|
||||
fun A?.buzz() {}
|
||||
|
||||
fun test(a : A?) {
|
||||
a<!UNSAFE_CALL!>.<!>foo() // error
|
||||
a<!UNSAFE_CALL!>.<!>bar() // error
|
||||
a.buzz()
|
||||
|
||||
a?.foo()
|
||||
a?.bar()
|
||||
a<!UNNECESSARY_SAFE_CALL!>?.<!>buzz() // warning
|
||||
}
|
||||
|
||||
fun A.test2() {
|
||||
foo()
|
||||
bar()
|
||||
buzz()
|
||||
|
||||
this.foo()
|
||||
this.bar()
|
||||
this.buzz()
|
||||
|
||||
this<!UNNECESSARY_SAFE_CALL!>?.<!>foo() // warning
|
||||
this<!UNNECESSARY_SAFE_CALL!>?.<!>bar() // warning
|
||||
this<!UNNECESSARY_SAFE_CALL!>?.<!>buzz() // warning
|
||||
}
|
||||
|
||||
fun A?.test3() {
|
||||
<!UNSAFE_CALL!>foo<!>() // error
|
||||
<!UNSAFE_CALL!>bar<!>() // error
|
||||
buzz()
|
||||
|
||||
this<!UNSAFE_CALL!>.<!>foo() // error
|
||||
this<!UNSAFE_CALL!>.<!>bar() // error
|
||||
this.buzz()
|
||||
|
||||
this?.foo()
|
||||
this?.bar()
|
||||
this<!UNNECESSARY_SAFE_CALL!>?.<!>buzz() // warning
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// KT-362 Don't allow autocasts on vals that are not internal
|
||||
namespace example;
|
||||
|
||||
namespace test {
|
||||
public class Public() {
|
||||
public val public : Int? = 1;
|
||||
protected val protected : Int? = 1;
|
||||
internal protected val i_protected : Int? = 1;
|
||||
val internal : Int? = 1
|
||||
}
|
||||
internal class Internal() {
|
||||
public val public : Int? = 1;
|
||||
protected val protected : Int? = 1;
|
||||
internal protected val i_protected : Int? = 1;
|
||||
val internal : Int? = 1
|
||||
}
|
||||
}
|
||||
|
||||
fun test() {
|
||||
val p = test.Public()
|
||||
if (p.public is Int) <!AUTOCAST_IMPOSSIBLE!>p.public<!> + 1
|
||||
if (p.protected is Int) <!AUTOCAST_IMPOSSIBLE!>p.protected<!> + 1
|
||||
if (p.i_protected is Int) p.i_protected + 1
|
||||
if (p.internal is Int) p.internal + 1
|
||||
val i = test.Public()
|
||||
if (i.public is Int) <!AUTOCAST_IMPOSSIBLE!>i.public<!> + 1
|
||||
if (i.protected is Int) <!AUTOCAST_IMPOSSIBLE!>i.protected<!> + 1
|
||||
if (i.i_protected is Int) i.i_protected + 1
|
||||
if (i.internal is Int) i.internal + 1
|
||||
}
|
||||
Reference in New Issue
Block a user