"Unused value" error added to existed tests

This commit is contained in:
svtk
2011-11-24 15:59:44 +04:00
parent 97f377b529
commit a7bb30a18c
51 changed files with 342 additions and 203 deletions
@@ -236,6 +236,6 @@ abstract class B3(i: Int) {
}
fun foo(a: B3) {
val a = <!CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS!>B3()<!>
val b = <!CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS!>B1(2, "s")<!>
val <!UNUSED_VARIABLE!>a<!> = <!CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS!>B3()<!>
val <!UNUSED_VARIABLE!>b<!> = <!CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS!>B1(2, "s")<!>
}
@@ -28,7 +28,7 @@ class WithC() {
}
this(a : Int) : this() {
val b = x
val <!UNUSED_VARIABLE!>b<!> = x
}
}
@@ -28,7 +28,7 @@ fun A.plus(a : Int) {
fun <T> T.minus(t : T) : Int = 1
fun test() {
val y = 1.abs
val <!UNUSED_VARIABLE!>y<!> = 1.abs
}
val Int.abs : Int
get() = if (this > 0) this else -this;
@@ -116,7 +116,7 @@ fun blockReturnValueTypeMatch12() : Int {
else return <!ERROR_COMPILE_TIME_VALUE!>1.0<!>
}
fun blockNoReturnIfValDeclaration(): Int {
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>val x = 1<!>
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>val <!UNUSED_VARIABLE!>x<!> = 1<!>
}
fun blockNoReturnIfEmptyIf(): Int {
if (1 < 2) <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!> else <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!>
@@ -174,37 +174,37 @@ class B() {
}
fun testFunctionLiterals() {
val endsWithVarDeclaration : fun() : Boolean = {
val <!UNUSED_VARIABLE!>endsWithVarDeclaration<!> : fun() : Boolean = {
<!EXPECTED_TYPE_MISMATCH!>val x = 2<!>
}
val endsWithAssignment = { () : Int =>
val <!UNUSED_VARIABLE!>endsWithAssignment<!> = { () : Int =>
var x = 1
<!EXPECTED_TYPE_MISMATCH!>x = 333<!>
}
val endsWithReAssignment = { () : Int =>
val <!UNUSED_VARIABLE!>endsWithReAssignment<!> = { () : Int =>
var x = 1
<!ASSIGNMENT_TYPE_MISMATCH!>x += 333<!>
}
val endsWithFunDeclaration : fun() : String = {
val <!UNUSED_VARIABLE!>endsWithFunDeclaration<!> : fun() : String = {
var x = 1
x = 333
<!EXPECTED_TYPE_MISMATCH!>fun meow() : Unit {}<!>
}
val endsWithObjectDeclaration : fun() : Int = {
val <!UNUSED_VARIABLE!>endsWithObjectDeclaration<!> : fun() : Int = {
var x = 1
x = 333
<!EXPECTED_TYPE_MISMATCH!>object A {}<!>
}
val expectedUnitReturnType1 = { () : Unit =>
val <!UNUSED_VARIABLE!>expectedUnitReturnType1<!> = { () : Unit =>
val x = 1
}
val expectedUnitReturnType2 = { () : Unit =>
val <!UNUSED_VARIABLE!>expectedUnitReturnType2<!> = { () : Unit =>
fun meow() : Unit {}
object A {}
}
@@ -9,10 +9,10 @@ fun testIncDec() {
++x
x--
--x
x = x++
x = x--
x = <!UNUSED_CHANGED_VALUE!>x++<!>
x = <!UNUSED_CHANGED_VALUE!>x--<!>
x = ++x
x = --x
x = <!UNUSED_VALUE!>--x<!>
}
class WrongIncDec() {
@@ -39,8 +39,8 @@ fun testUnitIncDec() {
++x
x--
--x
x = <!TYPE_MISMATCH!>x++<!>
x = <!TYPE_MISMATCH!>x--<!>
x = <!TYPE_MISMATCH, UNUSED_CHANGED_VALUE!>x++<!>
x = <!TYPE_MISMATCH, UNUSED_CHANGED_VALUE!>x--<!>
x = <!TYPE_MISMATCH!>++x<!>
x = <!TYPE_MISMATCH!>--x<!>
x = <!TYPE_MISMATCH, UNUSED_VALUE!>--x<!>
}
@@ -1,11 +1,11 @@
namespace qualified_expressions
fun test(s: String?) {
val a: Int = <!TYPE_MISMATCH!>s?.length<!>
val <!UNUSED_VARIABLE!>a<!>: Int = <!TYPE_MISMATCH!>s?.length<!>
val b: Int? = s?.length
val c: Int = s?.length ?: -11
val d: Int = s?.length ?: <!TYPE_MISMATCH!>"empty"<!>
val <!UNUSED_VARIABLE!>c<!>: Int = s?.length ?: -11
val <!UNUSED_VARIABLE!>d<!>: Int = s?.length ?: <!TYPE_MISMATCH!>"empty"<!>
val e: String = <!TYPE_MISMATCH!>s?.length<!> ?: "empty"
val f: Int = s?.length ?: b ?: 1
val g: Int? = e? startsWith("s")?.length
val <!UNUSED_VARIABLE!>f<!>: Int = s?.length ?: b ?: 1
val <!UNUSED_VARIABLE!>g<!>: Int? = e? startsWith("s")?.length
}
@@ -31,11 +31,11 @@ namespace closures {
val Int.xx = this : Int
fun Char.xx() : Any {
this : Char
val a = {Double.() => this : Double + this@xx : Char}
val b = @a{Double.() => this@a : Double + this@xx : Char}
val c = @a{() => <!NO_THIS!>this@a<!> + this@xx : Char}
val <!UNUSED_VARIABLE!>a<!> = {Double.() => this : Double + this@xx : Char}
val <!UNUSED_VARIABLE!>b<!> = @a{Double.() => this@a : Double + this@xx : Char}
val <!UNUSED_VARIABLE!>c<!> = @a{() => <!NO_THIS!>this@a<!> + this@xx : Char}
return (@a{Double.() => this@a : Double + this@xx : Char})
}
}
}
}
}
@@ -8,13 +8,13 @@ import java.lang.Comparable as Com
val l : List<in Int> = ArrayList<Int>()
fun test(l : java.util.List<Int>) {
val x : java.<!UNRESOLVED_REFERENCE!>List<!>
val y : java.util.List<Int>
val b : java.lang.Object
val a : util.List<Int>
val z : java.<!UNRESOLVED_REFERENCE!>utils<!>.List<Int>
val <!UNUSED_VARIABLE!>x<!> : java.<!UNRESOLVED_REFERENCE!>List<!>
val <!UNUSED_VARIABLE!>y<!> : java.util.List<Int>
val <!UNUSED_VARIABLE!>b<!> : java.lang.Object
val <!UNUSED_VARIABLE!>a<!> : util.List<Int>
val <!UNUSED_VARIABLE!>z<!> : java.<!UNRESOLVED_REFERENCE!>utils<!>.List<Int>
val f : java.io.File? = null
val <!UNUSED_VARIABLE!>f<!> : java.io.File? = null
Collections.<!UNRESOLVED_REFERENCE!>emptyList<!>
Collections.emptyList<Int>
@@ -27,7 +27,7 @@ fun test(l : java.util.List<Int>) {
<!UNRESOLVED_REFERENCE!>List<!><Int>
val o = "sdf" <!CAST_NEVER_SUCCEEDS!>as<!> Object
val <!UNUSED_VARIABLE!>o<!> = "sdf" <!CAST_NEVER_SUCCEEDS!>as<!> Object
try {
// ...
@@ -49,4 +49,4 @@ fun test(l : java.util.List<Int>) {
namespace xxx {
import java.lang.Class;
}
}
@@ -1,13 +1,13 @@
namespace unresolved
fun testGenericArgumentsCount() {
val p1: Tuple2<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int><!> = (2, 2)
val p2: <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Tuple2<!> = (2, 2)
val <!UNUSED_VARIABLE!>p1<!>: Tuple2<!WRONG_NUMBER_OF_TYPE_ARGUMENTS!><Int><!> = (2, 2)
val <!UNUSED_VARIABLE!>p2<!>: <!WRONG_NUMBER_OF_TYPE_ARGUMENTS!>Tuple2<!> = (2, 2)
}
fun testUnresolved() {
if (<!UNRESOLVED_REFERENCE!>a<!> is String) {
val s = <!UNRESOLVED_REFERENCE!>a<!>
val <!UNUSED_VARIABLE!>s<!> = <!UNRESOLVED_REFERENCE!>a<!>
}
<!UNRESOLVED_REFERENCE!>foo<!>(<!UNRESOLVED_REFERENCE!>a<!>)
val s = "s"
@@ -28,4 +28,4 @@ fun testUnresolved() {
}
}
fun foo1(i: Int) {}
fun foo1(i: Int) {}
@@ -8,13 +8,13 @@ abstract class Usual<T> {}
fun foo(c: Consumer<Int>, p: Producer<Int>, u: Usual<Int>) {
val c1: Consumer<Any> = <!TYPE_MISMATCH!>c<!>
val c2: Consumer<Int> = c1
val <!UNUSED_VARIABLE!>c2<!>: Consumer<Int> = c1
val p1: Producer<Any> = p
val p2: Producer<Int> = <!TYPE_MISMATCH!>p1<!>
val <!UNUSED_VARIABLE!>p2<!>: Producer<Int> = <!TYPE_MISMATCH!>p1<!>
val u1: Usual<Any> = <!TYPE_MISMATCH!>u<!>
val u2: Usual<Int> = <!TYPE_MISMATCH!>u1<!>
val <!UNUSED_VARIABLE!>u2<!>: Usual<Int> = <!TYPE_MISMATCH!>u1<!>
}
//Arrays copy example
@@ -37,4 +37,4 @@ fun f(ints: Array<Int>, any: Array<Any>, numbers: Array<Number>) {
copy2(ints, <!TYPE_MISMATCH!>numbers<!>)
copy3<Int>(ints, numbers)
copy4(ints, numbers) //ok
}
}
@@ -165,42 +165,42 @@ fun illegalWhenBlock(a: Any): Int {
}
fun declarations(a: Any?) {
if (a is String) {
val p4: (Int, String) = (2, a)
val <!UNUSED_VARIABLE!>p4<!>: (Int, String) = (2, a)
}
if (a is String?) {
if (a != null) {
val s: String = a
val <!UNUSED_VARIABLE!>s<!>: String = a
}
}
if (a != null) {
if (a is String?) {
val s: String = a
val <!UNUSED_VARIABLE!>s<!>: String = a
}
}
}
fun vars(a: Any?) {
var b: Int = 0
var <!UNUSED_VARIABLE!>b<!>: Int = 0
if (a is Int) {
b = a
b = <!UNUSED_VALUE!>a<!>
}
}
fun tuples(a: Any?) {
if (a != null) {
val s: (Any, String) = (a, <!TYPE_MISMATCH!>a<!>)
val <!UNUSED_VARIABLE!>s<!>: (Any, String) = (a, <!TYPE_MISMATCH!>a<!>)
}
if (a is String) {
val s: (Any, String) = (a, a)
val <!UNUSED_VARIABLE!>s<!>: (Any, String) = (a, a)
}
fun illegalTupleReturnType(): (Any, String) = (<!TYPE_MISMATCH!>a<!>, <!TYPE_MISMATCH!>a<!>)
if (a is String) {
fun legalTupleReturnType(): (Any, String) = (a, a)
}
val illegalFunctionLiteral: Function0<Int> = <!TYPE_MISMATCH!>{ <!TYPE_MISMATCH!>a<!> }<!>
val illegalReturnValueInFunctionLiteral: Function0<Int> = { (): Int => <!TYPE_MISMATCH!>a<!> }
val <!UNUSED_VARIABLE!>illegalFunctionLiteral<!>: Function0<Int> = <!TYPE_MISMATCH!>{ <!TYPE_MISMATCH!>a<!> }<!>
val <!UNUSED_VARIABLE!>illegalReturnValueInFunctionLiteral<!>: Function0<Int> = { (): Int => <!TYPE_MISMATCH!>a<!> }
if (a is Int) {
val legalFunctionLiteral: Function0<Int> = { a }
val alsoLegalFunctionLiteral: Function0<Int> = { (): Int => a }
val <!UNUSED_VARIABLE!>legalFunctionLiteral<!>: Function0<Int> = { a }
val <!UNUSED_VARIABLE!>alsoLegalFunctionLiteral<!>: Function0<Int> = { (): Int => a }
}
}
fun returnFunctionLiteralBlock(a: Any?): Function0<Int> {
@@ -227,7 +227,7 @@ fun mergeAutocasts(a: Any?) {
is String, is Any => a.<!UNRESOLVED_REFERENCE!>compareTo<!>("")
}
if (a is String && a is Any) {
val i: Int = a.compareTo("")
val <!UNUSED_VARIABLE!>i<!>: Int = a.compareTo("")
}
if (a is String && a.compareTo("") == 0) {}
if (a is String || a.<!UNRESOLVED_REFERENCE!>compareTo<!>("") == 0) {}
@@ -237,9 +237,9 @@ fun mergeAutocasts(a: Any?) {
fun f(): String {
var a: Any = 11
if (a is String) {
val i: String = <!AUTOCAST_IMPOSSIBLE!>a<!>
val <!UNUSED_VARIABLE!>i<!>: String = <!AUTOCAST_IMPOSSIBLE!>a<!>
<!AUTOCAST_IMPOSSIBLE!>a<!>.compareTo("f")
val f: Function0<String> = { <!AUTOCAST_IMPOSSIBLE!>a<!> }
val <!UNUSED_VARIABLE!>f<!>: Function0<String> = { <!AUTOCAST_IMPOSSIBLE!>a<!> }
return <!AUTOCAST_IMPOSSIBLE!>a<!>
}
return ""
@@ -2,5 +2,5 @@ fun test() {
var a : Any? = null
if (a is Any) else a = null;
while (a is Any) a = null
while (true) a = null
while (true) a = <!UNUSED_VALUE!>null<!>
}
@@ -2,7 +2,7 @@ fun foo(u : Unit) : Int = 1
fun test() : Int {
foo(<!TYPE_MISMATCH!>1<!>)
val a : fun() : Unit = {
val <!UNUSED_VARIABLE!>a<!> : fun() : Unit = {
foo(<!TYPE_MISMATCH!>1<!>)
}
return 1
@@ -32,7 +32,7 @@ fun evaluateAdd(expr: StringBuilder, numbers: ArrayList<Int>): Int {
fun evaluate(expr: StringBuilder, numbers: ArrayList<Int>): Int {
val lhs = evaluateAdd(expr, numbers)
if (expr.length() > 0) {
val c = expr.charAt(0)
val <!UNUSED_VARIABLE!>c<!> = expr.charAt(0)
expr.deleteCharAt(0)
}
return lhs
@@ -63,4 +63,4 @@ fun main(args: Array<String>) {
catch(e: Throwable) {
System.out?.println(e.getMessage())
}
}
}
@@ -1,8 +1,8 @@
fun foo1() : fun (Int) : Int = { (x: Int) => x }
fun foo() {
val h : fun (Int) : Int = foo1();
val <!UNUSED_VARIABLE!>h<!> : fun (Int) : Int = foo1();
h(1)
val m : fun (Int) : Int = {(a : Int) => 1}//foo1()
val <!UNUSED_VARIABLE!>m<!> : fun (Int) : Int = {(a : Int) => 1}//foo1()
m(1)
}
@@ -18,5 +18,5 @@ enum class Foo<T> {
fun box() {
val x: ProtocolState = ProtocolState.WAITING
}
val <!UNUSED_VARIABLE!>x<!>: ProtocolState = ProtocolState.WAITING
}
@@ -1,4 +1,4 @@
class Foo(var bar : Int, var barr : Int, var barrr : Int) {
class Foo(var bar : Int, var barr : Int, var barrr : Int) {
{
bar = 1
barr = 1
@@ -11,8 +11,7 @@
bar = 1
this.bar
1 : Int
val a : Int =1
val <!UNUSED_VARIABLE!>a<!> : Int =1
this : Foo
}
}
}
@@ -17,42 +17,42 @@ class AClass() {
val x : Any? = 1
fun Any?.vars(a: Any?) : Int {
var b: Int = 0
var <!UNUSED_VARIABLE!>b<!>: Int = 0
if (ns.y is Int) {
b = ns.y
b = <!UNUSED_VALUE!>ns.y<!>
}
if (ns.y is Int) {
b = example.ns.y
b = <!UNUSED_VALUE!>example.ns.y<!>
}
if (example.ns.y is Int) {
b = ns.y
b = <!UNUSED_VALUE!>ns.y<!>
}
if (example.ns.y is Int) {
b = example.ns.y
b = <!UNUSED_VALUE!>example.ns.y<!>
}
// if (namespace.bottles.ns.y is Int) {
// b = ns.y
// }
if (Obj.y is Int) {
b = Obj.y
b = <!UNUSED_VALUE!>Obj.y<!>
}
if (example.Obj.y is Int) {
b = Obj.y
b = <!UNUSED_VALUE!>Obj.y<!>
}
if (AClass.y is Int) {
b = AClass.y
b = <!UNUSED_VALUE!>AClass.y<!>
}
if (example.AClass.y is Int) {
b = AClass.y
b = <!UNUSED_VALUE!>AClass.y<!>
}
if (x is Int) {
b = x
b = <!UNUSED_VALUE!>x<!>
}
if (example.x is Int) {
b = x
b = <!UNUSED_VALUE!>x<!>
}
if (example.x is Int) {
b = example.x
b = <!UNUSED_VALUE!>example.x<!>
}
return 1
}
@@ -74,18 +74,18 @@ trait T {}
open class C {
fun foo() {
var t : T? = null
var <!UNUSED_VARIABLE!>t<!> : T? = null
if (this is T) {
t = this
t = <!UNUSED_VALUE!>this<!>
}
if (this is T) {
t = this@C
t = <!UNUSED_VALUE!>this@C<!>
}
if (this@C is T) {
t = this
t = <!UNUSED_VALUE!>this<!>
}
if (this@C is T) {
t = this@C
t = <!UNUSED_VALUE!>this@C<!>
}
}
}
@@ -2,7 +2,7 @@ fun foo(u : Unit) : Int = 1
fun test() : Int {
foo(<!TYPE_MISMATCH!>1<!>)
val a : fun() : Unit = {
val <!UNUSED_VARIABLE!>a<!> : fun() : Unit = {
foo(<!TYPE_MISMATCH!>1<!>)
}
return 1 <!NONE_APPLICABLE!>-<!> "1"
@@ -2,11 +2,11 @@
// KT-451 Incorrect character literals cause assertion failures
fun ff() {
val b = <!ERROR_COMPILE_TIME_VALUE!>''<!>
val c = <!ERROR_COMPILE_TIME_VALUE!>'23'<!>
val d = <!ERROR_COMPILE_TIME_VALUE!>'a<!>
val e = <!ERROR_COMPILE_TIME_VALUE!>'ab<!>
val f = <!ERROR_COMPILE_TIME_VALUE!>'\'<!>
val <!UNUSED_VARIABLE!>b<!> = <!ERROR_COMPILE_TIME_VALUE!>''<!>
val <!UNUSED_VARIABLE!>c<!> = <!ERROR_COMPILE_TIME_VALUE!>'23'<!>
val <!UNUSED_VARIABLE!>d<!> = <!ERROR_COMPILE_TIME_VALUE!>'a<!>
val <!UNUSED_VARIABLE!>e<!> = <!ERROR_COMPILE_TIME_VALUE!>'ab<!>
val <!UNUSED_VARIABLE!>f<!> = <!ERROR_COMPILE_TIME_VALUE!>'\'<!>
}
fun test() {
@@ -34,5 +34,4 @@ fun test() {
<!ERROR_COMPILE_TIME_VALUE!>'\u000z'<!>
<!ERROR_COMPILE_TIME_VALUE!>'\\u000'<!>
<!ERROR_COMPILE_TIME_VALUE!>'\'<!>
}
}
@@ -2,5 +2,5 @@
fun ff() {
val i: Int = 1
val a: Int = i<!UNNECESSARY_SAFE_CALL!>?.<!>plus(2)
}
val <!UNUSED_VARIABLE!>a<!>: Int = i<!UNNECESSARY_SAFE_CALL!>?.<!>plus(2)
}
@@ -2,5 +2,5 @@ fun Int.gg() = null
fun ff() {
val a: Int = 1
val b: Int = <!TYPE_MISMATCH!>a<!UNNECESSARY_SAFE_CALL!>?.<!>gg()<!>
}
val <!UNUSED_VARIABLE!>b<!>: Int = <!TYPE_MISMATCH!>a<!UNNECESSARY_SAFE_CALL!>?.<!>gg()<!>
}
@@ -5,7 +5,7 @@ fun any(a : Any) {}
fun notAnExpression() {
any(<!SUPER_IS_NOT_AN_EXPRESSION!>super<!>) // not an expression
if (<!SUPER_IS_NOT_AN_EXPRESSION!>super<!>) {} else {} // not an expression
val x = <!SUPER_IS_NOT_AN_EXPRESSION!>super<!> // not an expression
val <!UNUSED_VARIABLE!>x<!> = <!SUPER_IS_NOT_AN_EXPRESSION!>super<!> // not an expression
when (1) {
<!SUPER_IS_NOT_AN_EXPRESSION!>super<!> => 1 // not an expression
}
@@ -6,13 +6,13 @@ 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 <!UNUSED_VARIABLE!>a<!> : C<Int> = C();
val <!UNUSED_VARIABLE!>x<!> : C<in String> = C()
val <!UNUSED_VARIABLE!>y<!> : C<out String> = C()
val <!UNUSED_VARIABLE!>z<!> : C<*> = C()
val ba : C<Int> = bar();
val bx : C<in String> = bar()
val by : C<out String> = bar()
val bz : C<*> = bar()
}
val <!UNUSED_VARIABLE!>ba<!> : C<Int> = bar();
val <!UNUSED_VARIABLE!>bx<!> : C<in String> = bar()
val <!UNUSED_VARIABLE!>by<!> : C<out String> = bar()
val <!UNUSED_VARIABLE!>bz<!> : C<*> = bar()
}
@@ -63,11 +63,11 @@ fun t4(a: A, val b: A, var c: A) {
// reassigned vals
fun t1() {
val a : Int = 1
<!VAL_REASSIGNMENT!>a<!> = 2
val <!UNUSED_VARIABLE!>a<!> : Int = 1
<!VAL_REASSIGNMENT!>a<!> = <!UNUSED_VALUE!>2<!>
var b : Int = 1
b = 3
var <!UNUSED_VARIABLE!>b<!> : Int = 1
b = <!UNUSED_VALUE!>3<!>
}
abstract enum class ProtocolState {
@@ -85,7 +85,7 @@ abstract enum class ProtocolState {
fun t3() {
val x: ProtocolState = ProtocolState.WAITING
<!VAL_REASSIGNMENT!>x<!> = x.signal()
x = x.signal() //repeat for x
x = <!UNUSED_VALUE!>x.signal()<!> //repeat for x
}
fun t4() {
@@ -265,7 +265,7 @@ class ClassObject() {
}
fun foo() {
val a = object {
val <!UNUSED_VARIABLE!>a<!> = object {
val x : Int
val <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>y<!> : Int
val z : Int
@@ -283,7 +283,7 @@ fun foo() {
class TestObjectExpression() {
val <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>a<!> : Int
fun foo() {
val a = object {
val <!UNUSED_VARIABLE!>a<!> = object {
val x : Int
val <!MUST_BE_INITIALIZED_OR_BE_ABSTRACT!>y<!> : Int
{
@@ -325,10 +325,10 @@ object TestObjectDeclaration {
fun func() {
val b = 1
val a = object {
val <!UNUSED_VARIABLE!>a<!> = object {
val x = b
{
<!VAL_REASSIGNMENT!>b<!> = 4
<!VAL_REASSIGNMENT!>b<!> = <!UNUSED_VALUE!>4<!>
<!UNRESOLVED_REFERENCE!>$b<!> = 3
}
}
@@ -349,4 +349,4 @@ fun test(m : M) {
fun test1(m : M) {
<!VAL_REASSIGNMENT!>m.x<!>++
m.y--
}
}
@@ -1,3 +1,3 @@
fun foo(f : fun()) {
val x : Unit = f()
val <!UNUSED_VARIABLE!>x<!> : Unit = f()
}
@@ -0,0 +1,142 @@
namespace unused_variables
fun testSimpleCases() {
var i = 2
i = <!UNUSED_VALUE!>34<!>
i = 34
doSmth(i)
i = <!UNUSED_VALUE!>5<!>
var j = 2
j = <!UNUSED_CHANGED_VALUE!>j++<!>
j = <!UNUSED_CHANGED_VALUE, UNUSED_VALUE!>j--<!>
}
class IncDec() {
fun inc() : IncDec = this
fun dec() : IncDec = this
}
class MyTest() {
fun testIncDec() {
var x = IncDec()
x++
++x
x--
--x
x = <!UNUSED_CHANGED_VALUE!>x++<!>
x = <!UNUSED_CHANGED_VALUE!>x--<!>
x = ++x
x = <!UNUSED_VALUE!>--x<!>
}
var a: String = "s"
set(v: String) {
var i: Int = 23
doSmth(i)
i = <!UNUSED_VALUE!>34<!>
$a = v
}
{
a = "rr"
}
fun testSimple() {
a = "rro"
var <!UNUSED_VARIABLE!>i<!> = 1;
i = <!UNUSED_VALUE!>34<!>;
i = <!UNUSED_VALUE!>456<!>;
}
fun testWhile(a : Any?, b : Any?) {
var a : Any? = true
var b : Any? = 34
while (a is Any) {
a = null
}
while (b != null) {
a = <!UNUSED_VALUE!>null<!>
}
}
fun testIf() {
var a : Any
if (1 < 2) {
a = 23
}
else {
a = "ss"
doSmth(a as String)
}
doSmth(a)
if (1 < 2) {
a = <!UNUSED_VALUE!>23<!>
}
else {
a = <!UNUSED_VALUE!>"ss"<!>
}
}
fun testFor() {
for (i in 1..10) {
doSmth(i)
}
}
fun doSmth(s: String) {}
fun doSmth(a: Any) {}
}
fun testInnerFunctions() {
var <!UNUSED_VARIABLE!>y<!> = 1
fun foo() {
y = <!UNUSED_VALUE!>1<!>
}
var z = 1
fun bar() {
doSmth(z)
}
}
fun testFunctionLiterals() {
var x = 1
var <!UNUSED_VARIABLE!>fl<!> = { (): Int =>
x
}
var y = 2
var <!UNUSED_VARIABLE!>fl1<!> = { (): Unit =>
doSmth(y)
}
}
trait Trait {
fun foo()
}
fun testObject() : Trait {
val x = 24
val o = object : Trait {
val y : Int //in this case y should not be marked as unused
get() = 55
override fun foo() {
doSmth(x)
}
}
return o
}
fun testBackingFieldsNotMarked() {
val <!UNUSED_VARIABLE!>a<!> = object {
val x : Int
{
$x = 1
}
}
}
fun doSmth(i : Int) {}
@@ -4,33 +4,33 @@ namespace kt235
fun main(args: Array<String>) {
val array = MyArray()
val f = { (): String =>
val <!UNUSED_VARIABLE!>f<!> = { (): String =>
<!EXPECTED_TYPE_MISMATCH!>array[2] = 23<!> //error: Type mismatch: inferred type is Int (!!!) but String was expected
}
val g = {(): String =>
val <!UNUSED_VARIABLE!>g<!> = {(): String =>
var x = 1
<!EXPECTED_TYPE_MISMATCH!>x += 2<!> //no error, but it should be here
}
val h = {(): String =>
val <!UNUSED_VARIABLE!>h<!> = {(): String =>
var x = 1
<!EXPECTED_TYPE_MISMATCH!>x = 2<!> //the same
}
val array1 = MyArray1()
val x = { (): String =>
val <!UNUSED_VARIABLE!>x<!> = { (): String =>
<!EXPECTED_TYPE_MISMATCH!>array1[2] = 23<!>
}
val fi = { (): Int =>
val <!UNUSED_VARIABLE!>fi<!> = { (): Int =>
<!ASSIGNMENT_TYPE_MISMATCH!>array[2] = 23<!>
}
val gi = {(): Int =>
val <!UNUSED_VARIABLE!>gi<!> = {(): Int =>
var x = 1
<!ASSIGNMENT_TYPE_MISMATCH!>x += 21<!>
}
var m: MyNumber = MyNumber()
val a = { (): MyNumber =>
m++
val <!UNUSED_VARIABLE!>a<!> = { (): MyNumber =>
<!UNUSED_CHANGED_VALUE!>m++<!>
}
}
@@ -5,7 +5,7 @@ namespace kt352
val f : fun(Any) : Unit = <!TYPE_MISMATCH!>{ () : Unit => }<!> //type mismatch
fun foo() {
val f : fun(Any) : Unit = <!TYPE_MISMATCH!>{ () : Unit => }<!> //!!! no error
val <!UNUSED_VARIABLE!>f<!> : fun(Any) : Unit = <!TYPE_MISMATCH!>{ () : Unit => }<!> //!!! no error
}
class A() {
@@ -5,17 +5,17 @@ trait A {
}
fun foo(a: A) {
val g : fun() : Unit = {
val <!UNUSED_VARIABLE!>g<!> : fun() : Unit = {
a.gen() //it works: Unit is derived
}
val u: Unit = a.gen() //type mismatch, but Unit can be derived
val <!UNUSED_VARIABLE!>u<!>: Unit = a.gen() //type mismatch, but Unit can be derived
if (true) {
a.gen() //it works: Unit is derived
}
val b : fun() : Unit = {
val <!UNUSED_VARIABLE!>b<!> : fun() : Unit = {
if (true) {
a.gen() //type mismatch, but Unit can be derived
}
@@ -24,9 +24,9 @@ fun foo(a: A) {
}
}
val f : fun() : Int = { () : Int =>
val <!UNUSED_VARIABLE!>f<!> : fun() : Int = { () : Int =>
a.gen() //type mismatch, but Int can be derived
}
a.gen() //it works: Unit is derived
}
}
@@ -13,13 +13,13 @@ fun invoker(gen : fun() : Int) : Int = 0
//more tests
fun t1() {
val v = @{ () : Int =>
val <!UNUSED_VARIABLE!>v<!> = @{ () : Int =>
return@ 111
}
}
fun t2() : String {
val g : fun(): Int = @{
val <!UNUSED_VARIABLE!>g<!> : fun(): Int = @{
if (true) {
return@ 1
}
@@ -54,10 +54,10 @@ fun t3() : String {
}
fun t4() : Int {
val h : fun (): String = @l{
val <!UNUSED_VARIABLE!>h<!> : fun (): String = @l{
return@l "a"
}
val g : fun (): String = @{ () : String =>
val <!UNUSED_VARIABLE!>g<!> : fun (): String = @{ () : String =>
return@ "a"
}
@@ -3,13 +3,13 @@
fun <T> funny(f : fun() : T) : T = f()
fun testFunny() {
val a : Int = funny {1}
val <!UNUSED_VARIABLE!>a<!> : Int = funny {1}
}
fun <T> funny2(f : fun(t : T) : T) : T <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>{}<!>
fun testFunny2() {
val a : Int = funny2 {it}
val <!UNUSED_VARIABLE!>a<!> : Int = funny2 {it}
}
fun box() : String {
@@ -25,7 +25,7 @@ fun <T> T.with(f : fun T.()) {
}
fun main(args : Array<String>) {
val a = 1 with {
val <!UNUSED_VARIABLE!>a<!> = 1 with {
plus(1)
}
}
@@ -10,7 +10,6 @@ class Foo {
}
class User {
fun main() : Unit {
var boo : Foo.Bar? /* <-- this reference is red */ = Foo.Bar()
var <!UNUSED_VARIABLE!>boo<!> : Foo.Bar? /* <-- this reference is red */ = Foo.Bar()
}
}
}
@@ -67,7 +67,7 @@ public class CheckerTestUtilTest extends JetLiteFixture {
doTest(new TheTest("Unexpected NONE_APPLICABLE at 122 to 123", "Missing TYPE_MISMATCH at 161 to 169") {
@Override
protected void makeTestData(List<Diagnostic> diagnostics, List<CheckerTestUtil.DiagnosedRange> diagnosedRanges) {
diagnosedRanges.remove(2);
diagnosedRanges.remove(3);
diagnostics.remove(diagnostics.size() - 3);
}
});
+2 -2
View File
@@ -161,6 +161,6 @@ abstract class B3(i: Int) {
}
fun foo(a: B3) {
val a = <error>B3()</error>
val b = <error>B1(2, "s")</error>
val <warning>a</warning> = <error>B3()</error>
val <warning>b</warning> = <error>B1(2, "s")</error>
}
@@ -28,7 +28,7 @@ class WithC() {
}
this(a : Int) : this() {
val b = x
val <warning>b</warning> = x
}
}
+1 -1
View File
@@ -28,7 +28,7 @@ fun A.plus(a : Int) {
fun <T> T.minus(t : T) : Int = 1
fun test() {
val y = 1.abs
val <warning>y</warning> = 1.abs
}
val Int.abs : Int
get() = if (this > 0) this else -this;
+3 -3
View File
@@ -9,10 +9,10 @@ fun testIncDec() {
++x
x--
--x
x = x++
x = x--
x = <warning>x++</warning>
x = <warning>x--</warning>
x = ++x
x = --x
x = <warning>--x</warning>
}
class WrongIncDec() {
@@ -1,11 +1,11 @@
namespace qualified_expressions
fun test(s: String?) {
val a: Int = <error>s?.length</error>
val <warning>a</warning>: Int = <error>s?.length</error>
val b: Int? = s?.length
val c: Int = s?.length ?: -11
val d: Int = s?.length ?: <error>"empty"</error>
val <warning>c</warning>: Int = s?.length ?: -11
val <warning>d</warning>: Int = s?.length ?: <error>"empty"</error>
val e: String = <error>s?.length</error> ?: "empty"
val f: Int = s?.length ?: b ?: 1
val g: Int? = e? startsWith("s")?.length
val <warning>f</warning>: Int = s?.length ?: b ?: 1
val <warning>g</warning>: Int? = e? startsWith("s")?.length
}
+3 -3
View File
@@ -31,9 +31,9 @@ namespace closures {
val Int.xx = this : Int
fun Char.xx() : Any {
this : Char
val a = {Double.() => this : Double + this@xx : Char}
val b = @a{Double.() => this@a : Double + this@xx : Char}
val c = @a{() => <error>this@a</error> + this@xx : Char}
val <warning>a</warning> = {Double.() => this : Double + this@xx : Char}
val <warning>b</warning> = @a{Double.() => this@a : Double + this@xx : Char}
val <warning>c</warning> = @a{() => <error>this@a</error> + this@xx : Char}
return (@a{Double.() => this@a : Double + this@xx : Char})
}
}
+7 -7
View File
@@ -8,13 +8,13 @@ import java.lang.Comparable as Com
val l : List<in Int> = ArrayList<Int>()
fun test(l : java.util.List<Int>) {
val x : java.<error>List</error>
val y : java.util.List<Int>
val b : java.lang.Object
val a : util.List<Int>
val z : java.<error>utils</error>.List<Int>
val <warning>x</warning> : java.<error>List</error>
val <warning>y</warning> : java.util.List<Int>
val <warning>b</warning> : java.lang.Object
val <warning>a</warning> : util.List<Int>
val <warning>z</warning> : java.<error>utils</error>.List<Int>
val f : java.io.File? = null
val <warning>f</warning> : java.io.File? = null
Collections.<error>emptyList</error>
Collections.emptyList<Int>
@@ -27,7 +27,7 @@ fun test(l : java.util.List<Int>) {
<error>List</error><Int>
val o = "sdf" <warning>as</warning> Object
val <warning>o</warning> = "sdf" <warning>as</warning> Object
try {
// ...
+3 -3
View File
@@ -1,13 +1,13 @@
namespace unresolved
fun testGenericArgumentsCount() {
val p1: Tuple2<error><Int></error> = (2, 2)
val p2: <error>Tuple2</error> = (2, 2)
val <warning>p1</warning>: Tuple2<error><Int></error> = (2, 2)
val <warning>p2</warning>: <error>Tuple2</error> = (2, 2)
}
fun testUnresolved() {
if (<error>a</error> is String) {
val s = <error>a</error>
val <warning>s</warning> = <error>a</error>
}
<error>foo</error>(<error>a</error>)
val s = "s"
+3 -3
View File
@@ -8,13 +8,13 @@ abstract class Usual<T> {}
fun foo(c: Consumer<Int>, p: Producer<Int>, u: Usual<Int>) {
val c1: Consumer<Any> = <error>c</error>
val c2: Consumer<Int> = c1
val <warning>c2</warning>: Consumer<Int> = c1
val p1: Producer<Any> = p
val p2: Producer<Int> = <error>p1</error>
val <warning>p2</warning>: Producer<Int> = <error>p1</error>
val u1: Usual<Any> = <error>u</error>
val u2: Usual<Int> = <error>u1</error>
val <warning>u2</warning>: Usual<Int> = <error>u1</error>
}
//Arrays copy example
+14 -14
View File
@@ -163,42 +163,42 @@ fun illegalWhenBlock(a: Any): Int {
}
fun declarations(a: Any?) {
if (a is String) {
val p4: (Int, String) = (2, <info descr="Automatically cast to String">a</info>)
val <warning>p4</warning>: (Int, String) = (2, <info descr="Automatically cast to String">a</info>)
}
if (a is String?) {
if (a != null) {
val s: String = <info descr="Automatically cast to String">a</info>
val <warning>s</warning>: String = <info descr="Automatically cast to String">a</info>
}
}
if (a != null) {
if (a is String?) {
val s: String = <info descr="Automatically cast to String">a</info>
val <warning>s</warning>: String = <info descr="Automatically cast to String">a</info>
}
}
}
fun vars(a: Any?) {
var b: Int = 0
var <warning>b</warning>: Int = 0
if (a is Int) {
b = <info descr="Automatically cast to Int">a</info>
b = <info descr="Automatically cast to Int"><warning>a</warning></info>
}
}
fun tuples(a: Any?) {
if (a != null) {
val s: (Any, String) = (<info descr="Automatically cast to Any">a</info>, <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but String was expected">a</error>)
val <warning>s</warning>: (Any, String) = (<info descr="Automatically cast to Any">a</info>, <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but String was expected">a</error>)
}
if (a is String) {
val s: (Any, String) = (<info descr="Automatically cast to Any">a</info>, <info descr="Automatically cast to String">a</info>)
val <warning>s</warning>: (Any, String) = (<info descr="Automatically cast to Any">a</info>, <info descr="Automatically cast to String">a</info>)
}
fun illegalTupleReturnType(): (Any, String) = (<error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but Any was expected">a</error>, <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but String was expected">a</error>)
if (a is String) {
fun legalTupleReturnType(): (Any, String) = (<info descr="Automatically cast to Any">a</info>, <info descr="Automatically cast to String">a</info>)
}
val illegalFunctionLiteral: Function0<Int> = <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Function0<Any?> but Function0<Int> was expected">{ <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but Int was expected">a</error> }</error>
val illegalReturnValueInFunctionLiteral: Function0<Int> = { (): Int => <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but Int was expected">a</error> }
val <warning>illegalFunctionLiteral</warning>: Function0<Int> = <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Function0<Any?> but Function0<Int> was expected">{ <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but Int was expected">a</error> }</error>
val <warning>illegalReturnValueInFunctionLiteral</warning>: Function0<Int> = { (): Int => <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but Int was expected">a</error> }
if (a is Int) {
val legalFunctionLiteral: Function0<Int> = { <info descr="Automatically cast to Int">a</info> }
val alsoLegalFunctionLiteral: Function0<Int> = { (): Int => <info descr="Automatically cast to Int">a</info> }
val <warning>legalFunctionLiteral</warning>: Function0<Int> = { <info descr="Automatically cast to Int">a</info> }
val <warning>alsoLegalFunctionLiteral</warning>: Function0<Int> = { (): Int => <info descr="Automatically cast to Int">a</info> }
}
}
fun returnFunctionLiteralBlock(a: Any?): Function0<Int> {
@@ -225,7 +225,7 @@ fun mergeAutocasts(a: Any?) {
is String, is Any => a.<error descr="Unresolved reference: compareTo">compareTo</error>("")
}
if (a is String && a is Any) {
val i: Int = <info descr="Automatically cast to String">a</info>.compareTo("")
val <warning>i</warning>: Int = <info descr="Automatically cast to String">a</info>.compareTo("")
}
if (a is String && <info descr="Automatically cast to String">a</info>.compareTo("") == 0) {}
if (a is String || a.<error descr="Unresolved reference: compareTo">compareTo</error>("") == 0) {}
@@ -235,9 +235,9 @@ fun mergeAutocasts(a: Any?) {
fun f(): String {
var a: Any = 11
if (a is String) {
val i: String = <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to String is impossible, because a could have changed since the is-check">a</error>
val <warning>i</warning>: String = <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to String is impossible, because a could have changed since the is-check">a</error>
<error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to String is impossible, because a could have changed since the is-check">a</error>.compareTo("f")
val f: Function0<String> = { <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to String is impossible, because a could have changed since the is-check">a</error> }
val <warning>f</warning>: Function0<String> = { <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to String is impossible, because a could have changed since the is-check">a</error> }
return <error descr="[AUTOCAST_IMPOSSIBLE] Automatic cast to String is impossible, because a could have changed since the is-check">a</error>
}
return ""
+10 -10
View File
@@ -1,30 +1,30 @@
fun refs() {
var <info>a</info> = 1
val v = {
<info>a</info> = 2
var <info><warning>a</warning></info> = 1
val <warning>v</warning> = {
<info>a</info> = <warning>2</warning>
}
var <info>x</info> = 1
val b = object {
var <info><warning>x</warning></info> = 1
val <warning>b</warning> = object {
fun foo() {
<info>x</info> = 2
<info>x</info> = <warning>2</warning>
}
}
var <info>y</info> = 1
var <info><warning>y</warning></info> = 1
fun foo() {
<info>y</info> = 1
<info>y</info> = <warning>1</warning>
}
}
fun refsPlusAssign() {
var <info>a</info> = 1
val v = {
val <warning>v</warning> = {
<info>a</info> += 2
}
var <info>x</info> = 1
val b = object {
val <warning>b</warning> = object {
fun foo() {
<info>x</info> += 2
}
@@ -2,5 +2,5 @@ fun test() {
var a : Any? = null
if (a is Any) else a = null;
while (a is Any) a = null
while (true) a = null
while (true) a = <warning>null</warning>
}
@@ -2,7 +2,7 @@ fun foo(u : Unit) : Int = 1
fun test() : Int {
foo(<error>1</error>)
val a : fun() : Unit = {
val <warning>a</warning> : fun() : Unit = {
foo(<error>1</error>)
}
return 1
@@ -32,7 +32,7 @@ fun evaluateAdd(expr: StringBuilder, numbers: ArrayList<Int>): Int {
fun evaluate(expr: StringBuilder, numbers: ArrayList<Int>): Int {
val lhs = evaluateAdd(expr, numbers)
if (expr.length() > 0) {
val c = expr.charAt(0)
val <warning>c</warning> = expr.charAt(0)
expr.deleteCharAt(0)
}
return lhs
+2 -2
View File
@@ -1,8 +1,8 @@
fun foo1() : fun (Int) : Int = { (x: Int) => x }
fun foo() {
val h : fun (Int) : Int = foo1();
val <warning>h</warning> : fun (Int) : Int = foo1();
h(1)
val m : fun (Int) : Int = {(a : Int) => 1}//foo1()
val <warning>m</warning> : fun (Int) : Int = {(a : Int) => 1}//foo1()
m(1)
}
+1 -1
View File
@@ -18,5 +18,5 @@ enum class Foo<T> {
fun box() {
val x: ProtocolState = ProtocolState.WAITING
val <warning>x</warning>: ProtocolState = ProtocolState.WAITING
}
@@ -11,7 +11,7 @@
bar = 1
this.bar
1 : Int
val a : Int =1
val <warning>a</warning> : Int =1
this : Foo
}
}