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:
Dmitry Savvinov
2019-01-15 11:37:37 +03:00
parent 04ff2a3ee7
commit e483f83666
4 changed files with 10 additions and 17 deletions
@@ -6,6 +6,6 @@ import kotlin.contracts.*
fun f3(value: String?) {
if (<!USELESS_IS_CHECK!>!value.isNullOrEmpty() is Boolean<!>) {
<!DEBUG_INFO_SMARTCAST!>value<!>.length
value<!UNSAFE_CALL!>.<!>length
}
}
@@ -1,4 +1,3 @@
package
public fun myIf(/*0*/ cond: kotlin.Boolean): kotlin.Any
public fun test(/*0*/ x: kotlin.Any?): kotlin.Unit
public fun f3(/*0*/ value: kotlin.String?): kotlin.Unit