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:
+22
@@ -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<!>
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
public fun bar(/*0*/ b: kotlin.Boolean?): kotlin.Boolean
|
||||
public fun foo(/*0*/ b: kotlin.Boolean): kotlin.Boolean
|
||||
Vendored
+13
@@ -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
|
||||
}
|
||||
Vendored
+4
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
public fun bar(/*0*/ x: kotlin.Int): kotlin.Boolean
|
||||
public fun foo(/*0*/ x: kotlin.Int): kotlin.Boolean
|
||||
Vendored
+10
@@ -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)
|
||||
}
|
||||
}
|
||||
Vendored
+3
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
public fun foo(/*0*/ boolean: kotlin.Boolean): kotlin.Unit
|
||||
+11
@@ -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
|
||||
}<!>
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
public fun foo(/*0*/ y: kotlin.Boolean): kotlin.Unit
|
||||
+13
@@ -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
|
||||
}
|
||||
}
|
||||
+10
@@ -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
|
||||
}
|
||||
+11
@@ -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
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
public fun kotlin.Any?.foo(): kotlin.Boolean
|
||||
Returns(TRUE) -> <this> != null
|
||||
Reference in New Issue
Block a user