FIR checker: report errors in contract description
This commit is contained in:
committed by
TeamCityServer
parent
3d635b6a94
commit
20f9787c70
Vendored
+4
-4
@@ -10,19 +10,19 @@ class Foo {
|
||||
inner class Bar {
|
||||
fun good() {
|
||||
contract {
|
||||
returns() implies (<!UNRESOLVED_LABEL!>this@Bar<!> != null)
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (<!UNRESOLVED_LABEL!>this@Bar<!> != null)<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun badOuter() {
|
||||
contract {
|
||||
returns() implies (<!UNRESOLVED_LABEL!>this@Foo<!> != null)
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (<!UNRESOLVED_LABEL!>this@Foo<!> != null)<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun badInner() {
|
||||
contract {
|
||||
returns() implies (this != null)
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (this != null)<!>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class Foo {
|
||||
|
||||
fun A?.badWithReceiver() {
|
||||
contract {
|
||||
returns() implies (<!UNRESOLVED_LABEL!>this@Bar<!> != null)
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (<!UNRESOLVED_LABEL!>this@Bar<!> != null)<!>
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -7,7 +7,7 @@ import kotlin.contracts.*
|
||||
fun foo(b: Boolean): Boolean {
|
||||
contract {
|
||||
// pointless, can be reduced to just "b"
|
||||
returns(true) implies (b == true)
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (b == true)<!>
|
||||
}
|
||||
|
||||
return b
|
||||
@@ -16,7 +16,7 @@ fun foo(b: Boolean): Boolean {
|
||||
fun bar(b: Boolean?): Boolean {
|
||||
contract {
|
||||
// not pointless, but not supported yet
|
||||
returns(true) implies (b == true)
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (b == true)<!>
|
||||
}
|
||||
if (b == null) throw java.lang.IllegalArgumentException("")
|
||||
return b
|
||||
|
||||
Vendored
+1
-1
@@ -8,7 +8,7 @@ fun bar(x: Int): Boolean = x == 0
|
||||
|
||||
fun foo(x: Int): Boolean {
|
||||
contract {
|
||||
returns(true) implies (bar(x))
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (bar(x))<!>
|
||||
}
|
||||
return x == 0
|
||||
}
|
||||
+10
-10
@@ -6,26 +6,26 @@ import kotlin.contracts.*
|
||||
|
||||
fun ifInContract(x: Any?, boolean: Boolean) {
|
||||
contract {
|
||||
if (boolean) {
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>if (boolean) {
|
||||
returns() implies (x is String)
|
||||
} else {
|
||||
returns() implies (x is Int)
|
||||
}
|
||||
}<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun whenInContract(x: Any?, boolean: Boolean) {
|
||||
contract {
|
||||
when (boolean) {
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>when (boolean) {
|
||||
true -> returns() implies (x is String)
|
||||
else -> returns() implies (x is Int)
|
||||
}
|
||||
}<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun forInContract(x: Any?) {
|
||||
contract {
|
||||
<!UNRESOLVED_REFERENCE!>for (i in 0..1) {
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION, UNRESOLVED_REFERENCE!>for (i in 0..1) {
|
||||
returns() implies (x is String)
|
||||
}<!>
|
||||
}
|
||||
@@ -33,23 +33,23 @@ fun forInContract(x: Any?) {
|
||||
|
||||
fun whileInContract(x: Any?) {
|
||||
contract {
|
||||
while (false) {
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>while (false) {
|
||||
returns() implies (x is String)
|
||||
}
|
||||
}<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun doWhileInContract(x: Any?) {
|
||||
contract {
|
||||
do {
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>do {
|
||||
returns() implies (x is String)
|
||||
} while (false)
|
||||
} while (false)<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun localValInContract(x: Any?) {
|
||||
<!WRONG_IMPLIES_CONDITION!>contract {
|
||||
val y: Int = 42
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>val y: Int = 42<!>
|
||||
returns() implies (x is String)
|
||||
}<!>
|
||||
}
|
||||
Vendored
+4
-4
@@ -6,25 +6,25 @@ import kotlin.contracts.*
|
||||
|
||||
fun equalsWithVariables(x: Any?, y: Any?) {
|
||||
contract {
|
||||
returns() implies (x == y)
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (x == y)<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun identityEqualsWithVariables(x: Any?, y: Any?) {
|
||||
contract {
|
||||
returns() implies (x === y)
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (x === y)<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun equalConstants() {
|
||||
contract {
|
||||
returns() implies (null == null)
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (null == null)<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun get(): Int? = null
|
||||
fun equalNullWithCall() {
|
||||
contract {
|
||||
returns() implies (get() == null)
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (get() == null)<!>
|
||||
}
|
||||
}
|
||||
Vendored
+1
-1
@@ -6,6 +6,6 @@ import kotlin.contracts.*
|
||||
|
||||
fun foo(boolean: Boolean) {
|
||||
contract {
|
||||
(returns() implies (boolean)) <!UNRESOLVED_REFERENCE!>implies<!> (!boolean)
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>(returns() implies (boolean)) <!UNRESOLVED_REFERENCE!>implies<!> (!boolean)<!>
|
||||
}
|
||||
}
|
||||
Vendored
+4
-4
@@ -5,21 +5,21 @@
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun case_1(): Boolean {
|
||||
contract { returns(null) implies case_1() }
|
||||
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(null) implies case_1()<!> }
|
||||
return true
|
||||
}
|
||||
|
||||
fun case_2(): Boolean {
|
||||
contract { returns(null) implies case_3() }
|
||||
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(null) implies case_3()<!> }
|
||||
return true
|
||||
}
|
||||
|
||||
fun case_3(): Boolean {
|
||||
contract { returns(null) implies case_2() }
|
||||
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(null) implies case_2()<!> }
|
||||
return true
|
||||
}
|
||||
|
||||
fun case_4(): Boolean {
|
||||
kotlin.contracts.contract { returns(null) implies case_1() }
|
||||
kotlin.contracts.contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(null) implies case_1()<!> }
|
||||
return true
|
||||
}
|
||||
Vendored
+1
-1
@@ -7,7 +7,7 @@ import kotlin.contracts.*
|
||||
class Foo(val x: Int?) {
|
||||
fun isXNull(): Boolean {
|
||||
contract {
|
||||
returns(false) implies (<!UNRESOLVED_REFERENCE!>x<!> != null)
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns(false) implies (<!UNRESOLVED_REFERENCE!>x<!> != null)<!>
|
||||
}
|
||||
return x != null
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -7,7 +7,7 @@ import kotlin.contracts.*
|
||||
class Foo(val x: Int?) {
|
||||
fun isXNull(): Boolean {
|
||||
contract {
|
||||
returns(false) implies (<!UNRESOLVED_REFERENCE!>x<!> != null)
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns(false) implies (<!UNRESOLVED_REFERENCE!>x<!> != null)<!>
|
||||
}
|
||||
return x != null
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -6,7 +6,7 @@ import kotlin.contracts.*
|
||||
|
||||
fun Any?.foo(): Boolean {
|
||||
contract {
|
||||
returns(true) implies (this != null)
|
||||
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (this != null)<!>
|
||||
}
|
||||
return this != null
|
||||
}
|
||||
Reference in New Issue
Block a user