Do not lose information about contracts if call uses default value

It is safe to treat DefaultValueArgument as UNKNOWN_COMPUTATION, because
default arguments can't break smartcasts.

Possibly, they can add new ones, but it can be supported later.

^KT-25278 Fixed
This commit is contained in:
Dmitry Savvinov
2018-08-09 14:35:25 +03:00
parent cf62acc6d6
commit 57bafcf9e9
5 changed files with 63 additions and 10 deletions
@@ -0,0 +1,16 @@
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.internal.contracts.*
fun myAssert(condition: Boolean, message: String = "") {
contract {
returns() implies (condition)
}
if (!condition) throw kotlin.IllegalArgumentException(message)
}
fun test(x: Any?) {
myAssert(x is String)
<!DEBUG_INFO_SMARTCAST!>x<!>.length
}
@@ -0,0 +1,6 @@
package
public fun myAssert(/*0*/ condition: kotlin.Boolean, /*1*/ message: kotlin.String = ...): kotlin.Unit
Returns(WILDCARD) -> condition
public fun test(/*0*/ x: kotlin.Any?): kotlin.Unit