KT-1273 Unused assignment - should highlight assignment instead of expression
#KT-1273 Fixed
This commit is contained in:
@@ -632,7 +632,7 @@ public class JetFlowInformationProvider {
|
||||
((JetBinaryExpression) element).getOperationToken() == JetTokens.EQ) {
|
||||
JetExpression right = ((JetBinaryExpression) element).getRight();
|
||||
if (right != null) {
|
||||
report(Errors.UNUSED_VALUE.on(right, right, variableDescriptor), ctxt);
|
||||
report(Errors.UNUSED_VALUE.on((JetBinaryExpression) element, right, variableDescriptor), ctxt);
|
||||
}
|
||||
}
|
||||
else if (element instanceof JetPostfixExpression) {
|
||||
|
||||
@@ -531,7 +531,7 @@ public interface Errors {
|
||||
DiagnosticFactory1<JetNamedDeclaration, VariableDescriptor> ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE =
|
||||
DiagnosticFactory1.create(WARNING, DECLARATION_NAME);
|
||||
DiagnosticFactory1<JetExpression, DeclarationDescriptor> VARIABLE_WITH_REDUNDANT_INITIALIZER = DiagnosticFactory1.create(WARNING);
|
||||
DiagnosticFactory2<JetElement, JetElement, DeclarationDescriptor> UNUSED_VALUE = DiagnosticFactory2.create(WARNING);
|
||||
DiagnosticFactory2<JetBinaryExpression, JetElement, DeclarationDescriptor> UNUSED_VALUE = DiagnosticFactory2.create(WARNING, PositioningStrategies.UNUSED_VALUE);
|
||||
DiagnosticFactory1<JetElement, JetElement> UNUSED_CHANGED_VALUE = DiagnosticFactory1.create(WARNING);
|
||||
DiagnosticFactory0<JetElement> UNUSED_EXPRESSION = DiagnosticFactory0.create(WARNING);
|
||||
DiagnosticFactory0<JetFunctionLiteralExpression> UNUSED_FUNCTION_LITERAL = DiagnosticFactory0.create(WARNING);
|
||||
@@ -680,7 +680,7 @@ public interface Errors {
|
||||
INVISIBLE_MEMBER, INVISIBLE_MEMBER_FROM_INLINE, INVISIBLE_REFERENCE, INVISIBLE_SETTER);
|
||||
ImmutableSet<? extends DiagnosticFactory<?>> UNUSED_ELEMENT_DIAGNOSTICS = ImmutableSet.of(
|
||||
UNUSED_VARIABLE, UNUSED_PARAMETER, ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE, VARIABLE_WITH_REDUNDANT_INITIALIZER,
|
||||
UNUSED_FUNCTION_LITERAL, USELESS_CAST);
|
||||
UNUSED_FUNCTION_LITERAL, USELESS_CAST, UNUSED_VALUE);
|
||||
ImmutableSet<? extends DiagnosticFactory<?>> TYPE_INFERENCE_ERRORS = ImmutableSet.of(
|
||||
TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER, TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS, TYPE_INFERENCE_TYPE_CONSTRUCTOR_MISMATCH,
|
||||
TYPE_INFERENCE_UPPER_BOUND_VIOLATED, TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH);
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getCalleeHighlightingRange
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
import org.jetbrains.kotlin.utils.sure
|
||||
import kotlin.platform.platformStatic
|
||||
|
||||
@@ -435,4 +436,10 @@ public object PositioningStrategies {
|
||||
return markElement(if (specifiers.isEmpty()) element else specifiers[0])
|
||||
}
|
||||
}
|
||||
|
||||
public val UNUSED_VALUE: PositioningStrategy<JetBinaryExpression> = object: PositioningStrategy<JetBinaryExpression>() {
|
||||
override fun mark(element: JetBinaryExpression): List<TextRange> {
|
||||
return listOf(TextRange(element.getLeft()!!.startOffset, element.getOperationReference().endOffset))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ fun testFunctionLiterals() {
|
||||
|
||||
val <!UNUSED_VARIABLE!>endsWithAssignment<!>: () -> Int = {
|
||||
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>x<!> = 1
|
||||
<!EXPECTED_TYPE_MISMATCH!>x = <!UNUSED_VALUE!>333<!><!>
|
||||
<!EXPECTED_TYPE_MISMATCH!><!UNUSED_VALUE!>x =<!> 333<!>
|
||||
}
|
||||
|
||||
val <!UNUSED_VARIABLE!>endsWithReAssignment<!>: () -> Int = {
|
||||
@@ -186,13 +186,13 @@ fun testFunctionLiterals() {
|
||||
|
||||
val <!UNUSED_VARIABLE!>endsWithFunDeclaration<!> : () -> String = {
|
||||
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>x<!> = 1
|
||||
x = <!UNUSED_VALUE!>333<!>
|
||||
<!UNUSED_VALUE!>x =<!> 333
|
||||
<!EXPECTED_TYPE_MISMATCH!>fun meow() : Unit {}<!>
|
||||
}
|
||||
|
||||
val <!UNUSED_VARIABLE!>endsWithObjectDeclaration<!> : () -> Int = {
|
||||
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>x<!> = 1
|
||||
x = <!UNUSED_VALUE!>333<!>
|
||||
<!UNUSED_VALUE!>x =<!> 333
|
||||
<!LOCAL_OBJECT_NOT_ALLOWED, EXPECTED_TYPE_MISMATCH!>object A<!> {}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ fun testIncDec() {
|
||||
x = <!UNUSED_CHANGED_VALUE!>x++<!>
|
||||
x = <!UNUSED_CHANGED_VALUE!>x--<!>
|
||||
x = ++x
|
||||
x = <!UNUSED_VALUE!>--x<!>
|
||||
<!UNUSED_VALUE!>x =<!> --x
|
||||
}
|
||||
|
||||
class WrongIncDec() {
|
||||
@@ -42,5 +42,5 @@ fun testUnitIncDec() {
|
||||
x = <!UNUSED_CHANGED_VALUE!>x<!INC_DEC_SHOULD_NOT_RETURN_UNIT!>++<!><!>
|
||||
x = <!UNUSED_CHANGED_VALUE!>x<!INC_DEC_SHOULD_NOT_RETURN_UNIT!>--<!><!>
|
||||
x = <!INC_DEC_SHOULD_NOT_RETURN_UNIT!>++<!>x
|
||||
x = <!UNUSED_VALUE!><!INC_DEC_SHOULD_NOT_RETURN_UNIT!>--<!>x<!>
|
||||
<!UNUSED_VALUE!>x =<!> <!INC_DEC_SHOULD_NOT_RETURN_UNIT!>--<!>x
|
||||
}
|
||||
|
||||
@@ -53,16 +53,16 @@ fun cannotBe() {
|
||||
|
||||
fun canBe(i0: Int, j: Int) {
|
||||
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>i<!> = i0
|
||||
(label@ i) = <!UNUSED_VALUE!>34<!>
|
||||
<!UNUSED_VALUE!>(label@ i) =<!> 34
|
||||
|
||||
(label@ <!VAL_REASSIGNMENT!>j<!>) = <!UNUSED_VALUE!>34<!> //repeat for j
|
||||
<!UNUSED_VALUE!>(label@ <!VAL_REASSIGNMENT!>j<!>) =<!> 34 //repeat for j
|
||||
|
||||
val a = A()
|
||||
(l@ a.a) = 3894
|
||||
}
|
||||
|
||||
fun canBe2(j: Int) {
|
||||
(label@ <!VAL_REASSIGNMENT!>j<!>) = <!UNUSED_VALUE!>34<!>
|
||||
<!UNUSED_VALUE!>(label@ <!VAL_REASSIGNMENT!>j<!>) =<!> 34
|
||||
}
|
||||
|
||||
class A() {
|
||||
|
||||
@@ -2,14 +2,14 @@ package unused_variables
|
||||
|
||||
fun testSimpleCases() {
|
||||
var i = <!VARIABLE_WITH_REDUNDANT_INITIALIZER!>2<!>
|
||||
i = <!UNUSED_VALUE!>34<!>
|
||||
<!UNUSED_VALUE!>i =<!> 34
|
||||
i = 34
|
||||
doSmth(i)
|
||||
i = <!UNUSED_VALUE!>5<!>
|
||||
<!UNUSED_VALUE!>i =<!> 5
|
||||
|
||||
var j = 2
|
||||
j = <!UNUSED_CHANGED_VALUE!>j++<!>
|
||||
j = <!UNUSED_VALUE, UNUSED_CHANGED_VALUE!>j--<!>
|
||||
<!UNUSED_VALUE!>j =<!> <!UNUSED_CHANGED_VALUE!>j--<!>
|
||||
}
|
||||
|
||||
class IncDec() {
|
||||
@@ -27,14 +27,14 @@ class MyTest() {
|
||||
x = <!UNUSED_CHANGED_VALUE!>x++<!>
|
||||
x = <!UNUSED_CHANGED_VALUE!>x--<!>
|
||||
x = ++x
|
||||
x = <!UNUSED_VALUE!>--x<!>
|
||||
<!UNUSED_VALUE!>x =<!> --x
|
||||
}
|
||||
|
||||
var a: String = "s"
|
||||
set(v: String) {
|
||||
var i: Int = 23
|
||||
doSmth(i)
|
||||
i = <!UNUSED_VALUE!>34<!>
|
||||
<!UNUSED_VALUE!>i =<!> 34
|
||||
$a = v
|
||||
}
|
||||
|
||||
@@ -46,8 +46,8 @@ class MyTest() {
|
||||
a = "rro"
|
||||
|
||||
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>i<!> = 1;
|
||||
i = <!UNUSED_VALUE!>34<!>;
|
||||
i = <!UNUSED_VALUE!>456<!>;
|
||||
<!UNUSED_VALUE!>i =<!> 34;
|
||||
<!UNUSED_VALUE!>i =<!> 456;
|
||||
}
|
||||
|
||||
fun testWhile() {
|
||||
@@ -57,7 +57,7 @@ class MyTest() {
|
||||
a = null
|
||||
}
|
||||
while (b != null) {
|
||||
a = <!UNUSED_VALUE!>null<!>
|
||||
<!UNUSED_VALUE!>a =<!> null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,10 +73,10 @@ class MyTest() {
|
||||
doSmth(a)
|
||||
|
||||
if (1 < 2) {
|
||||
a = <!UNUSED_VALUE!>23<!>
|
||||
<!UNUSED_VALUE!>a =<!> 23
|
||||
}
|
||||
else {
|
||||
a = <!UNUSED_VALUE!>"ss"<!>
|
||||
<!UNUSED_VALUE!>a =<!> "ss"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -54,7 +54,7 @@ fun t2() {
|
||||
class A() {}
|
||||
|
||||
fun t4(a: A) {
|
||||
<!VAL_REASSIGNMENT!>a<!> = <!UNUSED_VALUE!>A()<!>
|
||||
<!UNUSED_VALUE!><!VAL_REASSIGNMENT!>a<!> =<!> A()
|
||||
}
|
||||
|
||||
// ------------------------------------------------
|
||||
@@ -62,10 +62,10 @@ fun t4(a: A) {
|
||||
|
||||
fun t1() {
|
||||
val <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>a<!> : Int = 1
|
||||
<!VAL_REASSIGNMENT!>a<!> = <!UNUSED_VALUE!>2<!>
|
||||
<!UNUSED_VALUE!><!VAL_REASSIGNMENT!>a<!> =<!> 2
|
||||
|
||||
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>b<!> : Int = 1
|
||||
b = <!UNUSED_VALUE!>3<!>
|
||||
<!UNUSED_VALUE!>b =<!> 3
|
||||
}
|
||||
|
||||
enum class ProtocolState {
|
||||
@@ -83,7 +83,7 @@ enum class ProtocolState {
|
||||
fun t3() {
|
||||
val x: ProtocolState = ProtocolState.WAITING
|
||||
<!VAL_REASSIGNMENT!>x<!> = x.signal()
|
||||
x = <!UNUSED_VALUE!>x.signal()<!> //repeat for x
|
||||
<!UNUSED_VALUE!>x =<!> x.signal() //repeat for x
|
||||
}
|
||||
|
||||
fun t4() {
|
||||
@@ -189,7 +189,7 @@ class AnonymousInitializers(var a: String, val b: String) {
|
||||
}
|
||||
|
||||
fun reassignFunParams(a: Int) {
|
||||
<!VAL_REASSIGNMENT!>a<!> = <!UNUSED_VALUE!>1<!>
|
||||
<!UNUSED_VALUE!><!VAL_REASSIGNMENT!>a<!> =<!> 1
|
||||
}
|
||||
|
||||
open class Open(<!UNUSED_PARAMETER!>a<!>: Int, <!UNUSED_PARAMETER!>w<!>: Int) {}
|
||||
|
||||
@@ -4,7 +4,7 @@ package kt609
|
||||
|
||||
fun test(a: Int) {
|
||||
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>aa<!> = a
|
||||
aa = <!UNUSED_VALUE!>324<!> //should be an 'unused value' warning here
|
||||
<!UNUSED_VALUE!>aa =<!> 324 //should be an 'unused value' warning here
|
||||
}
|
||||
|
||||
class C() {
|
||||
|
||||
@@ -6,5 +6,5 @@ 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<!>
|
||||
<!UNUSED_VALUE!>i =<!> 2
|
||||
}
|
||||
|
||||
+5
-5
@@ -95,13 +95,13 @@ fun testImplicitCoercion() {
|
||||
|
||||
var <!UNUSED_VARIABLE!>u<!> = <!IMPLICIT_CAST_TO_UNIT_OR_ANY!>when(d) {
|
||||
3 -> {
|
||||
z = <!UNUSED_VALUE!>34<!>
|
||||
<!UNUSED_VALUE!>z =<!> 34
|
||||
}
|
||||
else -> <!UNUSED_CHANGED_VALUE!>z--<!>
|
||||
}<!>
|
||||
|
||||
var <!UNUSED_VARIABLE!>iff<!> = <!IMPLICIT_CAST_TO_UNIT_OR_ANY!>if (true) {
|
||||
z = <!UNUSED_VALUE!>34<!>
|
||||
<!UNUSED_VALUE!>z =<!> 34
|
||||
}<!>
|
||||
val <!UNUSED_VARIABLE!>g<!> = <!IMPLICIT_CAST_TO_UNIT_OR_ANY!>if (true) 4<!>
|
||||
val <!UNUSED_VARIABLE!>h<!> = <!IMPLICIT_CAST_TO_UNIT_OR_ANY!>if (false) 4 else {}<!>
|
||||
@@ -110,7 +110,7 @@ fun testImplicitCoercion() {
|
||||
<!CONSTANT_EXPECTED_TYPE_MISMATCH!>4<!>
|
||||
}
|
||||
else {
|
||||
z = <!UNUSED_VALUE!>342<!>
|
||||
<!UNUSED_VALUE!>z =<!> 342
|
||||
})
|
||||
}
|
||||
|
||||
@@ -118,9 +118,9 @@ fun bar(<!UNUSED_PARAMETER!>a<!>: Unit) {}
|
||||
|
||||
fun testStatementInExpressionContext() {
|
||||
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>z<!> = 34
|
||||
val <!UNUSED_VARIABLE!>a1<!>: Unit = <!ASSIGNMENT_IN_EXPRESSION_CONTEXT!>z = <!UNUSED_VALUE!>334<!><!>
|
||||
val <!UNUSED_VARIABLE!>a1<!>: Unit = <!ASSIGNMENT_IN_EXPRESSION_CONTEXT!><!UNUSED_VALUE!>z =<!> 334<!>
|
||||
val <!UNUSED_VARIABLE!>f<!> = <!EXPRESSION_EXPECTED!>for (i in 1..10) {}<!>
|
||||
if (true) return <!ASSIGNMENT_IN_EXPRESSION_CONTEXT!>z = <!UNUSED_VALUE!>34<!><!>
|
||||
if (true) return <!ASSIGNMENT_IN_EXPRESSION_CONTEXT!><!UNUSED_VALUE!>z =<!> 34<!>
|
||||
return <!EXPRESSION_EXPECTED!>while (true) {}<!>
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ fun foo() : Int {
|
||||
var z = 0
|
||||
when(d) {
|
||||
5, 3 -> <!UNUSED_CHANGED_VALUE!>z++<!>
|
||||
<!ELSE_MISPLACED_IN_WHEN!>else<!> -> { z = <!UNUSED_VALUE!>-1000<!> }
|
||||
<!ELSE_MISPLACED_IN_WHEN!>else<!> -> { <!UNUSED_VALUE!>z =<!> -1000 }
|
||||
<!UNREACHABLE_CODE!>return z -> 34<!>
|
||||
}
|
||||
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
|
||||
+15
-15
@@ -23,40 +23,40 @@ val x : Any? = 1
|
||||
fun Any?.vars(<!UNUSED_PARAMETER!>a<!>: Any?) : Int {
|
||||
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>b<!>: Int = 0
|
||||
if (ns.y is Int) {
|
||||
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>ns.y<!>
|
||||
<!UNUSED_VALUE!>b =<!> <!DEBUG_INFO_SMARTCAST!>ns.y<!>
|
||||
}
|
||||
if (ns.y is Int) {
|
||||
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>example.ns.y<!>
|
||||
<!UNUSED_VALUE!>b =<!> <!DEBUG_INFO_SMARTCAST!>example.ns.y<!>
|
||||
}
|
||||
if (example.ns.y is Int) {
|
||||
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>ns.y<!>
|
||||
<!UNUSED_VALUE!>b =<!> <!DEBUG_INFO_SMARTCAST!>ns.y<!>
|
||||
}
|
||||
if (example.ns.y is Int) {
|
||||
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>example.ns.y<!>
|
||||
<!UNUSED_VALUE!>b =<!> <!DEBUG_INFO_SMARTCAST!>example.ns.y<!>
|
||||
}
|
||||
// if (package.bottles.ns.y is Int) {
|
||||
// b = ns.y
|
||||
// }
|
||||
if (Obj.y is Int) {
|
||||
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>Obj.y<!>
|
||||
<!UNUSED_VALUE!>b =<!> <!DEBUG_INFO_SMARTCAST!>Obj.y<!>
|
||||
}
|
||||
if (example.Obj.y is Int) {
|
||||
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>Obj.y<!>
|
||||
<!UNUSED_VALUE!>b =<!> <!DEBUG_INFO_SMARTCAST!>Obj.y<!>
|
||||
}
|
||||
if (AClass.y is Int) {
|
||||
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>AClass.y<!>
|
||||
<!UNUSED_VALUE!>b =<!> <!DEBUG_INFO_SMARTCAST!>AClass.y<!>
|
||||
}
|
||||
if (example.AClass.y is Int) {
|
||||
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>AClass.y<!>
|
||||
<!UNUSED_VALUE!>b =<!> <!DEBUG_INFO_SMARTCAST!>AClass.y<!>
|
||||
}
|
||||
if (x is Int) {
|
||||
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>x<!>
|
||||
<!UNUSED_VALUE!>b =<!> <!DEBUG_INFO_SMARTCAST!>x<!>
|
||||
}
|
||||
if (example.x is Int) {
|
||||
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>x<!>
|
||||
<!UNUSED_VALUE!>b =<!> <!DEBUG_INFO_SMARTCAST!>x<!>
|
||||
}
|
||||
if (example.x is Int) {
|
||||
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>example.x<!>
|
||||
<!UNUSED_VALUE!>b =<!> <!DEBUG_INFO_SMARTCAST!>example.x<!>
|
||||
}
|
||||
return 1
|
||||
}
|
||||
@@ -80,16 +80,16 @@ open class C {
|
||||
fun foo() {
|
||||
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>t<!> : T? = null
|
||||
if (this is T) {
|
||||
t = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>this<!>
|
||||
<!UNUSED_VALUE!>t =<!> <!DEBUG_INFO_SMARTCAST!>this<!>
|
||||
}
|
||||
if (this is T) {
|
||||
t = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>this@C<!>
|
||||
<!UNUSED_VALUE!>t =<!> <!DEBUG_INFO_SMARTCAST!>this@C<!>
|
||||
}
|
||||
if (this@C is T) {
|
||||
t = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>this<!>
|
||||
<!UNUSED_VALUE!>t =<!> <!DEBUG_INFO_SMARTCAST!>this<!>
|
||||
}
|
||||
if (this@C is T) {
|
||||
t = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>this@C<!>
|
||||
<!UNUSED_VALUE!>t =<!> <!DEBUG_INFO_SMARTCAST!>this@C<!>
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ class A {
|
||||
|
||||
fun foo(list: List<A>) {
|
||||
for (var (c1, c2, c3) in list) {
|
||||
c1 = <!UNUSED_VALUE!>1<!>
|
||||
<!UNUSED_VALUE!>c1 =<!> 1
|
||||
c3 + 1
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ fun test2(c: C) {
|
||||
|
||||
fun test3(c: C) {
|
||||
var (<!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>a<!>, <!UNUSED_VARIABLE!>b<!>) = c
|
||||
a = <!UNUSED_VALUE!>3<!>
|
||||
<!UNUSED_VALUE!>a =<!> 3
|
||||
}
|
||||
|
||||
fun test4(c: C) {
|
||||
|
||||
@@ -5,5 +5,5 @@ enum class E {
|
||||
|
||||
fun foo() {
|
||||
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>e<!> = E.E1
|
||||
e = <!UNUSED_VALUE!>E.E2<!>
|
||||
<!UNUSED_VALUE!>e =<!> E.E2
|
||||
}
|
||||
@@ -169,7 +169,7 @@ fun declarations(a: Any?) {
|
||||
fun vars(a: Any?) {
|
||||
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>b<!>: Int = 0
|
||||
if (a is Int) {
|
||||
b = <!UNUSED_VALUE, DEBUG_INFO_SMARTCAST!>a<!>
|
||||
<!UNUSED_VALUE!>b =<!> <!DEBUG_INFO_SMARTCAST!>a<!>
|
||||
}
|
||||
}
|
||||
fun returnFunctionLiteralBlock(a: Any?): Function0<Int> {
|
||||
|
||||
@@ -14,7 +14,7 @@ fun foo(a: Any?): Int {
|
||||
|
||||
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>b<!> = 1
|
||||
|
||||
(<!SYNTAX!>@<!> b) = <!UNUSED_VALUE!>2<!>
|
||||
<!UNUSED_VALUE!>(<!SYNTAX!>@<!> b) =<!> 2
|
||||
|
||||
return<!SYNTAX!>@<!> 1
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@ fun test() {
|
||||
var res : Boolean = true
|
||||
res = (res and false)
|
||||
res = (res or false)
|
||||
res = <!UNUSED_VALUE!>(res xor false)<!>
|
||||
res = <!UNUSED_VALUE!>(true and false)<!>
|
||||
res = <!UNUSED_VALUE!>(true or false)<!>
|
||||
res = <!UNUSED_VALUE!>(true xor false)<!>
|
||||
res = <!UNUSED_VALUE!>(!true)<!>
|
||||
res = <!UNUSED_VALUE!>(true && false)<!>
|
||||
res = <!UNUSED_VALUE!>(true || false)<!>
|
||||
<!UNUSED_VALUE!>res =<!> (res xor false)
|
||||
<!UNUSED_VALUE!>res =<!> (true and false)
|
||||
<!UNUSED_VALUE!>res =<!> (true or false)
|
||||
<!UNUSED_VALUE!>res =<!> (true xor false)
|
||||
<!UNUSED_VALUE!>res =<!> (!true)
|
||||
<!UNUSED_VALUE!>res =<!> (true && false)
|
||||
<!UNUSED_VALUE!>res =<!> (true || false)
|
||||
}
|
||||
|
||||
@@ -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 = <!UNUSED_VALUE!>null<!>
|
||||
while (true) <!UNUSED_VALUE!>a =<!> null
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ fun main(args: Array<String>) {
|
||||
}
|
||||
val <!UNUSED_VARIABLE!>h<!>: () -> String = {
|
||||
var <!ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE!>x<!> = 1
|
||||
<!EXPECTED_TYPE_MISMATCH!>x = <!UNUSED_VALUE!>2<!><!> //the same
|
||||
<!EXPECTED_TYPE_MISMATCH!><!UNUSED_VALUE!>x =<!> 2<!> //the same
|
||||
}
|
||||
val array1 = MyArray1()
|
||||
val <!UNUSED_VARIABLE!>i<!>: () -> String = {
|
||||
|
||||
@@ -45,6 +45,8 @@ import org.jetbrains.kotlin.psi.JetCodeFragment
|
||||
import org.jetbrains.kotlin.psi.JetFile
|
||||
import org.jetbrains.kotlin.psi.JetParameter
|
||||
import org.jetbrains.kotlin.psi.JetReferenceExpression
|
||||
import org.jetbrains.kotlin.psi.psiUtil.endOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.startOffset
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics
|
||||
import kotlin.platform.platformStatic
|
||||
@@ -93,7 +95,7 @@ public open class JetPsiChecker : Annotator, HighlightRangeExtension {
|
||||
|
||||
assert(diagnostic.getPsiElement() == element)
|
||||
|
||||
val textRanges = diagnostic.getTextRanges()
|
||||
var textRanges = diagnostic.getTextRanges()
|
||||
val factory = diagnostic.getFactory()
|
||||
when (diagnostic.getSeverity()) {
|
||||
Severity.ERROR -> {
|
||||
@@ -147,6 +149,7 @@ public open class JetPsiChecker : Annotator, HighlightRangeExtension {
|
||||
if (factory == Errors.UNUSED_PARAMETER && shouldSuppressUnusedParameter(diagnostic.getPsiElement() as JetParameter)) {
|
||||
return
|
||||
}
|
||||
|
||||
for (textRange in textRanges) {
|
||||
val annotation = holder.createWarningAnnotation(textRange, getDefaultMessage(diagnostic))
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ fun testIncDec() {
|
||||
x = <warning>x++</warning>
|
||||
x = <warning>x--</warning>
|
||||
x = ++x
|
||||
x = <warning>--x</warning>
|
||||
<warning>x =</warning> --x
|
||||
}
|
||||
|
||||
class WrongIncDec() {
|
||||
@@ -42,5 +42,5 @@ fun testUnitIncDec() {
|
||||
x = <warning>x<error>++</error></warning>
|
||||
x = <warning>x<error>--</error></warning>
|
||||
x = <error>++</error>x
|
||||
x = <warning><error>--</error>x</warning>
|
||||
<warning>x =</warning> <error>--</error>x
|
||||
}
|
||||
@@ -9,7 +9,7 @@ fun test(<warning textAttributesKey="NOT_USED_ELEMENT_ATTRIBUTES">unusedParam</w
|
||||
|
||||
val <warning textAttributesKey="NOT_USED_ELEMENT_ATTRIBUTES">unusedVar</warning> = ":(" // UNUSED_VARIABLE
|
||||
var <warning textAttributesKey="NOT_USED_ELEMENT_ATTRIBUTES">neverAccessed</warning>: Int // ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE
|
||||
neverAccessed = <warning>2</warning>
|
||||
<warning>neverAccessed =</warning> 2
|
||||
|
||||
var redundantInitializer = <warning textAttributesKey="NOT_USED_ELEMENT_ATTRIBUTES">1</warning> // VARIABLE_WITH_REDUNDANT_INITIALIZER
|
||||
redundantInitializer = 2
|
||||
|
||||
@@ -165,7 +165,7 @@ fun declarations(a: Any?) {
|
||||
fun vars(a: Any?) {
|
||||
var <warning>b</warning>: Int = 0
|
||||
if (a is Int) {
|
||||
b = <warning><info descr="Smart cast to kotlin.Int">a</info></warning>
|
||||
<warning>b =</warning> <info descr="Smart cast to kotlin.Int">a</info>
|
||||
}
|
||||
}
|
||||
fun returnFunctionLiteralBlock(<info>a</info>: Any?): Function0<Int> {
|
||||
|
||||
@@ -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 = <warning>null</warning>
|
||||
while (true) <warning>a =</warning> null
|
||||
}
|
||||
Reference in New Issue
Block a user