KT-351 Distinguish statement and expression positions

This commit is contained in:
svtk
2011-12-13 19:43:20 +04:00
parent 182009ab61
commit a41d33a56c
19 changed files with 318 additions and 65 deletions
@@ -0,0 +1,18 @@
//KT-510 `this.` allows initialization without backing field
namespace kt510
public open class Identifier1() {
var field : Boolean
{
field = false; // error
}
}
public open class Identifier2() {
var field : Boolean
{
this.field = false;
}
}
@@ -0,0 +1,18 @@
//KT-607 Val reassignment is not marked as an error
namespace kt607
fun foo(a: A) {
val o = object {
val y : Int
get() = 42
}
<!VAL_REASSIGNMENT!>a.z<!> = 23
<!VAL_REASSIGNMENT!>o.y<!> = 11 //Should be an error here
}
class A() {
val z : Int
get() = 3
}
@@ -0,0 +1,19 @@
//KT-609 Analyze not only local variables, but function parameters as well in 'unused values' analysis
namespace kt609
fun test(var a: Int) {
a = <!UNUSED_VALUE!>324<!> //should be an 'unused value' warning here
}
class C() {
fun foo(<!UNUSED_PARAMETER!>s<!>: String) {} //should be an 'unused variable' warning
}
open class A() {
open fun foo(s : String) {} //should not be a warning
}
class B() : A() {
final override fun foo(s : String) {} //should not be a warning
}
@@ -0,0 +1,10 @@
//KT-610 Distinguish errors 'unused variable' and 'variable is assigned but never accessed'
namespace kt610
fun foo() {
var <!UNUSED_VARIABLE!>j<!> = 9 //'unused variable' error
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>i<!> = 1 //should be an error 'variable i is assigned but never accessed'
i = <!UNUSED_VALUE!>2<!>
}