Effects: add diagnostic tests on contracts

- Make AbstractDiagnosticsTest dump function contracts
- Add diagnostics tests on parsing contracts
- Add diagnostics tests on smartcats in presence of functions with
contracts
- Add diagnostics tests on initialization and flow in presence of
in-place called lambdas

==========
Introduction of EffectSystem: 16/18
This commit is contained in:
Dmitry Savvinov
2017-10-03 15:02:51 +03:00
parent f487525a1d
commit 4434db4d69
120 changed files with 4179 additions and 1 deletions
@@ -0,0 +1,22 @@
// !LANGUAGE: +ReturnsEffect
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.internal.contracts.*
fun foo(b: Boolean): Boolean {
contract {
// pointless, can be reduced to just "b"
returns(true) implies (<!ERROR_IN_CONTRACT_DESCRIPTION(only equality comparisons with 'null' allowed)!>b == true<!>)
}
return b
}
fun bar(b: Boolean?): Boolean {
contract {
// not pointless, but not supported yet
returns(true) implies (<!ERROR_IN_CONTRACT_DESCRIPTION(only equality comparisons with 'null' allowed)!>b == true<!>)
}
if (b == null) throw java.lang.IllegalArgumentException("")
return <!DEBUG_INFO_SMARTCAST!>b<!>
}
@@ -0,0 +1,4 @@
package
public fun bar(/*0*/ b: kotlin.Boolean?): kotlin.Boolean
public fun foo(/*0*/ b: kotlin.Boolean): kotlin.Boolean
@@ -0,0 +1,13 @@
// !LANGUAGE: +ReturnsEffect
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.internal.contracts.*
fun bar(x: Int): Boolean = x == 0
fun foo(x: Int): Boolean {
contract {
returns(true) implies (<!ERROR_IN_CONTRACT_DESCRIPTION(call-expressions are not supported yet)!>bar(x)<!>)
}
return x == 0
}
@@ -0,0 +1,4 @@
package
public fun bar(/*0*/ x: kotlin.Int): kotlin.Boolean
public fun foo(/*0*/ x: kotlin.Int): kotlin.Boolean
@@ -0,0 +1,10 @@
// !LANGUAGE: +ReturnsEffect
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.internal.contracts.*
fun foo(boolean: Boolean) {
contract {
(returns() implies (boolean)) <!UNRESOLVED_REFERENCE!>implies<!> (!boolean)
}
}
@@ -0,0 +1,3 @@
package
public fun foo(/*0*/ boolean: kotlin.Boolean): kotlin.Unit
@@ -0,0 +1,11 @@
// !LANGUAGE: +ReturnsEffect
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.internal.contracts.*
fun foo(y: Boolean) {
val <!UNUSED_VARIABLE!>x<!>: Int = 42
<!CONTRACT_NOT_ALLOWED!>contract {
returns() implies y
}<!>
}
@@ -0,0 +1,3 @@
package
public fun foo(/*0*/ y: kotlin.Boolean): kotlin.Unit
@@ -0,0 +1,13 @@
// !LANGUAGE: +ReturnsEffect
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.internal.contracts.*
class Foo(val x: Int?) {
fun isXNull(): Boolean {
contract {
returns(false) implies (<!ERROR_IN_CONTRACT_DESCRIPTION(only references to parameters are allowed in contract description)!>x<!> != null)
}
return x != null
}
}
@@ -0,0 +1,10 @@
package
public final class Foo {
public constructor Foo(/*0*/ x: kotlin.Int?)
public final val x: kotlin.Int?
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final fun isXNull(): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,11 @@
// !LANGUAGE: +ReturnsEffect
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
import kotlin.internal.contracts.*
fun Any?.foo(): Boolean {
contract {
returns(true) implies (<!ERROR_IN_CONTRACT_DESCRIPTION(only references to parameters are allowed. Did you miss label on <this>?)!>this<!> <!EQUALS_MISSING!>!=<!> null)
}
return this != null
}
@@ -0,0 +1,4 @@
package
public fun kotlin.Any?.foo(): kotlin.Boolean
Returns(TRUE) -> <this> != null