Make 'is'-operator more stupid
Consider following expression: 'call() is Foo'. Suppose that we know something about the 'call()', e.g. 'returns(foo) -> <condition>' Previously, we've tried to re-use knowledge about 'call()', constructing some smart clause, like 'returns(true) -> foo is Foo && <condition>'. The conceptual error here is that *we can't* argue that <condition> holds. Imagine that 'call()' actually has unspecified 'returns(foo2) -> <!condition>', and 'foo2 is Foo' also holds. Then we would get 'returns(true) -> foo2 is Foo && <condition>' <=> 'returns(true) -> <condition>' for the whole call, which is not correct. More concrete example would be something like: 'if (!x.isNullOrEmpty() is Boolean)' ^KT-27241 Fixed
This commit is contained in:
+3
-4
@@ -7,7 +7,6 @@
|
||||
* SECTIONS: contracts, analysis, smartcasts
|
||||
* NUMBER: 15
|
||||
* DESCRIPTION: Check smartcasts working if type checking for contract function is used
|
||||
* UNEXPECTED BEHAVIOUR
|
||||
* ISSUES: KT-27241
|
||||
*/
|
||||
|
||||
@@ -40,20 +39,20 @@ import contracts.*
|
||||
// TESTCASE NUMBER: 1
|
||||
fun case_1(value: Any) {
|
||||
if (contracts.case_1_2(contracts.case_1_1(value is Char))) {
|
||||
println(<!DEBUG_INFO_SMARTCAST!>value<!>.category)
|
||||
println(value.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>category<!>)
|
||||
}
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 2
|
||||
fun case_2(value: Any) {
|
||||
if (contracts.case_2(value is Char) is Boolean) {
|
||||
println(<!DEBUG_INFO_SMARTCAST!>value<!>.category)
|
||||
println(value.<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>category<!>)
|
||||
}
|
||||
}
|
||||
|
||||
// TESTCASE NUMBER: 3
|
||||
fun case_3(value: String?) {
|
||||
if (<!USELESS_IS_CHECK!>!value.isNullOrEmpty() is Boolean<!>) {
|
||||
<!DEBUG_INFO_SMARTCAST!>value<!>.length
|
||||
value<!UNSAFE_CALL!>.<!>length
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user