KT-2317 Wrong UNNECESSARY_SAFE_CALL

#KT-2317 Fixed
This commit is contained in:
Alexander Udalov
2012-06-26 01:36:29 +04:00
committed by Alexander Udalov
parent bb8dc49692
commit b2defb2cb4
7 changed files with 23 additions and 8 deletions
@@ -758,7 +758,7 @@ public class CallResolver {
result = OTHER_ERROR;
}
}
if (safeAccess && (receiverParameter.getType().isNullable() || !receiverArgumentType.isNullable())) {
if (safeAccess && !receiverArgumentType.isNullable()) {
context.tracing.unnecessarySafeCall(context.candidateCall.getTrace(), receiverArgumentType);
}
}
@@ -66,10 +66,10 @@ import outer.*
command.equals(null)
command?.equals(null)
command.equals1(null)
command<!UNNECESSARY_SAFE_CALL!>?.<!>equals1(null)
command?.equals1(null)
val c = Command()
c<!UNNECESSARY_SAFE_CALL!>?.<!>equals2(null)
if (command == null) 1
}
}
@@ -0,0 +1,15 @@
//KT-2317 Wrong UNNECESSARY_SAFE_CALL
package kt2317
fun Any?.baz() = 1
fun foo(l: Long?) = l?.baz()
fun Any?.bar(): Unit { }
fun quux(x: Int?): Unit {
x?.baz()
x?.bar()
}
@@ -32,7 +32,7 @@ fun test(x : Int?, a : A?) {
a.times(1)
a * 1
a times 1
a<!UNNECESSARY_SAFE_CALL!>?.<!>times(1)
a?.times(1)
1 <!UNSAFE_INFIX_CALL!>in<!> a
a <!UNSAFE_INFIX_CALL!>contains<!> 1
@@ -12,7 +12,7 @@ fun test(a : A?) {
a?.foo()
a?.bar()
a<!UNNECESSARY_SAFE_CALL!>?.<!>buzz() // warning
a?.buzz()
}
fun A.test2() {
@@ -40,5 +40,5 @@ fun A?.test3() {
this?.foo()
this?.bar()
this<!UNNECESSARY_SAFE_CALL!>?.<!>buzz() // warning
this?.buzz()
}
@@ -5,5 +5,5 @@ fun Array<String>.length() : Int {
}
fun test(array : Array<String?>?) {
array<!UNNECESSARY_SAFE_CALL!>?.<!>sure<Array<String?>>()<!UNSAFE_CALL!>.<!>length()
array?.sure<Array<String?>>()<!UNSAFE_CALL!>.<!>length()
}
+1 -1
View File
@@ -61,7 +61,7 @@ fun Int.foo() = this
command.equals(null)
command?.equals(null)
command.equals1(null)
command<warning>?.</warning>equals1(null)
command?.equals1(null)
val c = Command()
c<warning>?.</warning>equals2(null)