FIR checker: report errors in contract description

This commit is contained in:
Jinseong Jeon
2021-02-09 15:58:30 -08:00
committed by TeamCityServer
parent 3d635b6a94
commit 20f9787c70
36 changed files with 166 additions and 91 deletions
@@ -26,7 +26,7 @@ inline fun case_1(block: () -> Unit) {
// TESTCASE NUMBER: 2
inline fun case_2(block: () -> Unit) {
contract { callsInPlaceEffectBuilder(block) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>callsInPlaceEffectBuilder(block)<!> }
return block()
}
@@ -5,6 +5,6 @@ import kotlin.contracts.*
// TESTCASE NUMBER: 1
fun case_1(value_1: Any?, block: () -> Unit) {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) <!UNRESOLVED_REFERENCE!>implies<!> (value_1 != null) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>callsInPlace(block, InvocationKind.EXACTLY_ONCE) <!UNRESOLVED_REFERENCE!>implies<!> (value_1 != null)<!> }
if (value_1 != null) block()
}
@@ -5,7 +5,7 @@ import kotlin.contracts.*
// TESTCASE NUMBER: 1
fun case_1(): Boolean {
contract { returns(null) implies throw Exception() }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(null) implies throw Exception()<!> }
return true
}
@@ -17,6 +17,6 @@ fun case_2(): Boolean {
// TESTCASE NUMBER: 3
fun case_3(): Boolean {
contract { returns(null) implies return return return false && throw throw throw throw Exception() }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(null) implies return return return false && throw throw throw throw Exception()<!> }
return true
}
@@ -5,24 +5,24 @@ import kotlin.contracts.*
// TESTCASE NUMBER: 1
fun case_1(value_1: Boolean): Boolean {
contract { returns(true) implies (value_1 == true) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (value_1 == true)<!> }
return value_1 == true
}
// TESTCASE NUMBER: 2
fun case_2(value_1: Boolean): Boolean? {
contract { returnsNotNull() implies (value_1 != false) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returnsNotNull() implies (value_1 != false)<!> }
return if (value_1 != false) true else null
}
// TESTCASE NUMBER: 3
fun case_3(value_1: String): Boolean {
contract { returns(false) implies (value_1 != "") }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(false) implies (value_1 != "")<!> }
return !(value_1 != "")
}
// TESTCASE NUMBER: 4
fun case_4(value_1: Int): Boolean? {
contract { returns(null) implies (value_1 == 0) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(null) implies (value_1 == 0)<!> }
return if (value_1 == 0) null else true
}
@@ -5,36 +5,36 @@ import kotlin.contracts.*
// TESTCASE NUMBER: 1
fun case_1(value_1: Boolean?): Boolean {
contract { returns(true) implies (value_1 != null && value_1 == false) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (value_1 != null && value_1 == false)<!> }
return value_1 != null && value_1 == false
}
// TESTCASE NUMBER: 2
fun case_2(value_1: Boolean, value_2: Boolean): Boolean? {
contract { returnsNotNull() implies (value_1 != false || value_2) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returnsNotNull() implies (value_1 != false || value_2)<!> }
return if (value_1 != false || value_2) true else null
}
// TESTCASE NUMBER: 3
fun case_3(value_1: String?, value_2: Boolean): Boolean {
contract { returns(false) implies (value_1 != null && value_2 != true) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(false) implies (value_1 != null && value_2 != true)<!> }
return !(value_1 != null && value_2 != true)
}
// TESTCASE NUMBER: 4
fun case_4(value_1: Nothing?, value_2: Boolean?): Boolean? {
contract { returns(null) implies (value_1 == null || value_2 != null || value_2 == false) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(null) implies (value_1 == null || value_2 != null || value_2 == false)<!> }
return if (value_1 == null || value_2 != null || value_2 == false) null else true
}
// TESTCASE NUMBER: 5
fun case_5(value_1: Any?, value_2: String?): Boolean? {
contract { returns(null) implies (value_1 != null && value_2 != null || value_2 == ".") }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(null) implies (value_1 != null && value_2 != null || value_2 == ".")<!> }
return if (value_1 != null && value_2 != null || value_2 == ".") null else true
}
// TESTCASE NUMBER: 6
fun case_6(value_1: Boolean, value_2: Int?): Boolean? {
contract { returns(null) implies (value_2 == null && value_1 || value_2 == 0) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(null) implies (value_2 == null && value_1 || value_2 == 0)<!> }
return if (value_2 == null && value_1 || value_2 == 0) null else true
}
@@ -6,18 +6,18 @@ import kotlin.contracts.*
// TESTCASE NUMBER: 1
fun case_1(): Boolean? {
contract { returnsNotNull() <!INAPPLICABLE_CANDIDATE!>implies<!> (null) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returnsNotNull() <!INAPPLICABLE_CANDIDATE!>implies<!> (null)<!> }
return true
}
// TESTCASE NUMBER: 2
fun case_2(): Boolean {
contract { returns(false) <!INAPPLICABLE_CANDIDATE!>implies<!> 0.000001 }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(false) <!INAPPLICABLE_CANDIDATE!>implies<!> 0.000001<!> }
return true
}
// TESTCASE NUMBER: 3
fun case_3(): Boolean? {
contract { returns(null) <!INAPPLICABLE_CANDIDATE!>implies<!> "" }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(null) <!INAPPLICABLE_CANDIDATE!>implies<!> ""<!> }
return null
}
@@ -6,7 +6,7 @@ import kotlin.contracts.*
// TESTCASE NUMBER: 1
fun case_1(): Boolean {
contract { returns(true) <!INAPPLICABLE_CANDIDATE!>implies<!> (-10) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) <!INAPPLICABLE_CANDIDATE!>implies<!> (-10)<!> }
return true
}
@@ -18,7 +18,7 @@ fun case_2(): Boolean {
// TESTCASE NUMBER: 3
fun case_3(): Boolean {
contract { returns(false) <!INAPPLICABLE_CANDIDATE!>implies<!> ("..." + "$<!UNRESOLVED_REFERENCE!>value_1<!>") }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(false) <!INAPPLICABLE_CANDIDATE!>implies<!> ("..." + "$<!UNRESOLVED_REFERENCE!>value_1<!>")<!> }
return true
}
@@ -27,26 +27,26 @@ fun case_3(): Boolean {
* ISSUES: KT-26386
*/
fun case_4(): Boolean? {
contract { returns(null) <!INAPPLICABLE_CANDIDATE!>implies<!> case_4() }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(null) <!INAPPLICABLE_CANDIDATE!>implies<!> case_4()<!> }
return null
}
// TESTCASE NUMBER: 5
fun case_5(): Boolean? {
contract { returns(null) <!INAPPLICABLE_CANDIDATE!>implies<!> listOf(0) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(null) <!INAPPLICABLE_CANDIDATE!>implies<!> listOf(0)<!> }
return null
}
// TESTCASE NUMBER: 6
fun case_6(value_1: Boolean): Boolean? {
contract { returns(null) <!INAPPLICABLE_CANDIDATE!>implies<!> contract { returns(null) implies (!value_1) } }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(null) <!INAPPLICABLE_CANDIDATE!>implies<!> contract { returns(null) implies (!value_1) }<!> }
return null
}
// TESTCASE NUMBER: 7
fun case_7(): Int {
contract {
callsInPlace(::case_7, InvocationKind.EXACTLY_ONCE)
<!ERROR_IN_CONTRACT_DESCRIPTION!>callsInPlace(::case_7, InvocationKind.EXACTLY_ONCE)<!>
}
return 1
}
@@ -57,7 +57,7 @@ fun case_7(): Int {
*/
fun case_8(): () -> Unit {
contract {
callsInPlace(case_8(), InvocationKind.EXACTLY_ONCE)
<!ERROR_IN_CONTRACT_DESCRIPTION!>callsInPlace(case_8(), InvocationKind.EXACTLY_ONCE)<!>
}
return {}
}
@@ -11,16 +11,16 @@ object case_1 {
private const val value_3 = false
fun case_1_1(): Boolean? {
contract { returnsNotNull() implies (<!UNRESOLVED_REFERENCE!>value_1<!>) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returnsNotNull() implies (<!UNRESOLVED_REFERENCE!>value_1<!>)<!> }
return if (value_1) true else null
}
fun case_1_2(): Boolean? {
contract { returns(null) implies (<!UNRESOLVED_REFERENCE!>value_2<!>) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(null) implies (<!UNRESOLVED_REFERENCE!>value_2<!>)<!> }
return if (value_2) null else true
}
fun case_1_3(): Boolean {
contract { returns(true) implies (<!UNRESOLVED_REFERENCE!>value_3<!>) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (<!UNRESOLVED_REFERENCE!>value_3<!>)<!> }
return value_3
}
}
@@ -42,22 +42,22 @@ class case_2(value_5: Boolean, val value_1: Boolean) {
}
fun case_2_2(): Boolean? {
contract { returns(null) implies (<!UNRESOLVED_REFERENCE!>value_1<!>) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(null) implies (<!UNRESOLVED_REFERENCE!>value_1<!>)<!> }
return if (value_1) null else true
}
fun case_2_3(): Boolean {
contract { returns(true) implies (<!UNRESOLVED_REFERENCE!>value_2<!>) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (<!UNRESOLVED_REFERENCE!>value_2<!>)<!> }
return value_2
}
fun case_2_4(): Boolean {
contract { returns(false) implies (<!UNRESOLVED_REFERENCE!>value_3<!>) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(false) implies (<!UNRESOLVED_REFERENCE!>value_3<!>)<!> }
return !(value_3)
}
inline fun <reified K : Number> K.case_2_5(): Boolean? {
contract { returnsNotNull() implies (<!UNRESOLVED_REFERENCE!>value_4<!>) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returnsNotNull() implies (<!UNRESOLVED_REFERENCE!>value_4<!>)<!> }
return if (value_4) true else null
}
}
@@ -6,7 +6,7 @@ import kotlin.contracts.*
// TESTCASE NUMBER: 1
inline fun case_1(block: () -> Unit) {
contract {
{ callsInPlace(block, InvocationKind.EXACTLY_ONCE) }()
<!ERROR_IN_CONTRACT_DESCRIPTION!>{ callsInPlace(block, InvocationKind.EXACTLY_ONCE) }()<!>
}
return block()
}
@@ -14,7 +14,7 @@ inline fun case_1(block: () -> Unit) {
// TESTCASE NUMBER: 2
fun case_2(x: Any?): Boolean {
contract {
returns(true).apply { implies (x is Number) } // 'Returns' as result
returns(true).<!ERROR_IN_CONTRACT_DESCRIPTION!>apply { implies (x is Number) }<!> // 'Returns' as result
}
return x is Number
}
@@ -22,7 +22,7 @@ fun case_2(x: Any?): Boolean {
// TESTCASE NUMBER: 3
fun case_3(x: Any?): Boolean {
contract {
returns(true).also { it implies (x is Number) } // 'Returns' as result
returns(true).<!ERROR_IN_CONTRACT_DESCRIPTION!>also { it implies (x is Number) }<!> // 'Returns' as result
}
return x is Number
}
@@ -30,7 +30,7 @@ fun case_3(x: Any?): Boolean {
// TESTCASE NUMBER: 4
fun case_4(x: Any?): Boolean {
contract {
returns(true).let { it implies (x is Number) } // 'ConditionalEffect' as result
returns(true).<!ERROR_IN_CONTRACT_DESCRIPTION!>let { it implies (x is Number) }<!> // 'ConditionalEffect' as result
}
return x is Number
}
@@ -38,7 +38,7 @@ fun case_4(x: Any?): Boolean {
// TESTCASE NUMBER: 5
fun case_5(x: Any?): Boolean {
contract {
returns(true).run { implies (x is Number) } // 'ConditionalEffect' as result
returns(true).<!ERROR_IN_CONTRACT_DESCRIPTION!>run { implies (x is Number) }<!> // 'ConditionalEffect' as result
}
return x is Number
}
@@ -46,7 +46,7 @@ fun case_5(x: Any?): Boolean {
// TESTCASE NUMBER: 6
fun case_6(x: Any?): Boolean {
contract {
returns(true).takeIf { it implies (x is Number); false } // null, must be unrecognized effect
returns(true).<!ERROR_IN_CONTRACT_DESCRIPTION!>takeIf { it implies (x is Number); false }<!> // null, must be unrecognized effect
}
return x is Number
}
@@ -4,24 +4,24 @@ import kotlin.contracts.*
// TESTCASE NUMBER: 1
fun case_1(x: Any?): Boolean {
contract { returns(true) implies (x == -.15f) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (x == -.15f)<!> }
return x !is Number
}
// TESTCASE NUMBER: 2
fun case_2(x: Any?): Boolean {
contract { returns(true) implies (x == "..." + ".") }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (x == "..." + ".")<!> }
return x !is Number
}
// TESTCASE NUMBER: 3
fun case_3(x: Int, y: Int): Boolean {
contract { returns(true) implies (x > y) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (x > y)<!> }
return x > y
}
// TESTCASE NUMBER: 4
fun case_4(x: Any?, y: Any?): Boolean {
contract { returns(true) implies (x == y.toString()) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (x == y.toString())<!> }
return x !is Number
}
@@ -5,7 +5,7 @@ import kotlin.contracts.*
// TESTCASE NUMBER: 1
fun Any?.case_1(): Boolean {
contract {
returns(true) implies (this != null)
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (this != null)<!>
}
return this != null
}
@@ -13,7 +13,7 @@ fun Any?.case_1(): Boolean {
// TESTCASE NUMBER: 2
fun Any?.case_2(): Boolean {
contract {
returnsNotNull() implies (this is Number?)
<!ERROR_IN_CONTRACT_DESCRIPTION!>returnsNotNull() implies (this is Number?)<!>
}
return this is Number?
}
@@ -21,7 +21,7 @@ fun Any?.case_2(): Boolean {
// TESTCASE NUMBER: 3
fun <T> T?.case_3(): Boolean {
contract {
returnsNotNull() implies (this != null)
<!ERROR_IN_CONTRACT_DESCRIPTION!>returnsNotNull() implies (this != null)<!>
}
return this != null
}
@@ -29,7 +29,7 @@ fun <T> T?.case_3(): Boolean {
// TESTCASE NUMBER: 4
inline fun <reified T : Number> T.case_4(): Boolean {
contract {
returns(null) implies (this is Int)
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns(null) implies (this is Int)<!>
}
return this is Int
}
@@ -5,7 +5,7 @@ import kotlin.contracts.*
// TESTCASE NUMBER: 1
fun case_1(x: Any?): Boolean {
contract {
returns(true) implies (x === EmptyObject) // should be not allowed
<!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (x === EmptyObject)<!> // should be not allowed
}
return x === EmptyObject
}
@@ -4,18 +4,18 @@ import kotlin.contracts.*
// TESTCASE NUMBER: 1
fun case_1(x: Any?): Boolean {
contract { returns(true) implies (x == .15f) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (x == .15f)<!> }
return x == .15f
}
// TESTCASE NUMBER: 2
fun case_2(x: Any?) {
contract { returns() implies (x == "...") }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (x == "...")<!> }
if (x != "...") throw Exception()
}
// TESTCASE NUMBER: 3
fun case_3(x: Any?): Boolean {
contract { returns(true) implies (x == '-') }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (x == '-')<!> }
return x == '-'
}
@@ -4,6 +4,6 @@ import kotlin.contracts.*
// TESTCASE NUMBER: 1
fun <T : Boolean>T.case_1(): Boolean? {
contract { returns(null) implies (!this@case_1) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(null) implies (!this@case_1)<!> }
return if (!this) null else true
}
@@ -4,42 +4,42 @@ import kotlin.contracts.*
// TESTCASE NUMBER: 1
fun Boolean?.case_1(): Boolean {
contract { returns(true) implies (this@case_1 != null && this@case_1) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (this@case_1 != null && this@case_1)<!> }
return this != null && this
}
// TESTCASE NUMBER: 2
fun <T : Boolean>T?.case_2(): Boolean {
contract { returns(true) implies (this@case_2 != null && this@case_2 !is Nothing && this@case_2) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (this@case_2 != null && this@case_2 !is Nothing && this@case_2)<!> }
return this != null && this !is Nothing && this
}
// TESTCASE NUMBER: 3
fun <T>T?.case_3() {
contract { returns() implies (this@case_3 == null || this@case_3 is Boolean? && !this@case_3) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (this@case_3 == null || this@case_3 is Boolean? && !this@case_3)<!> }
if (!(this == null || this is Boolean? && !this)) throw Exception()
}
// TESTCASE NUMBER: 4
fun case_4(value_1: Boolean?): Boolean {
contract { returns(true) implies (value_1 != null && !value_1) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(true) implies (value_1 != null && !value_1)<!> }
return value_1 != null && !value_1
}
// TESTCASE NUMBER: 5
fun Boolean.case_5(value_1: Any?): Boolean? {
contract { returnsNotNull() implies (value_1 is Boolean? && value_1 != null && value_1) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returnsNotNull() implies (value_1 is Boolean? && value_1 != null && value_1)<!> }
return if (value_1 is Boolean? && value_1 != null && value_1) true else null
}
// TESTCASE NUMBER: 6
fun Boolean?.case_6(): Boolean? {
contract { returnsNotNull() implies (this@case_6 != null && this@case_6) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returnsNotNull() implies (this@case_6 != null && this@case_6)<!> }
return if (this@case_6 != null && this@case_6) true else null
}
// TESTCASE NUMBER: 7
fun <T : Boolean?> T.case_7(value_1: Any?): Boolean? {
contract { returnsNotNull() implies (value_1 is Boolean? && value_1 != null && value_1 && this@case_7 != null && this@case_7) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returnsNotNull() implies (value_1 is Boolean? && value_1 != null && value_1 && this@case_7 != null && this@case_7)<!> }
return if (value_1 is Boolean? && value_1 != null && value_1 && this@case_7 != null && this@case_7) true else null
}
@@ -32,12 +32,12 @@ fun case_2() {
class case_4 : ClassLevel3() {
fun <T : Number?>T.case_4_1(): Boolean {
contract { returns(false) implies (<!UNRESOLVED_LABEL!>this@case_4<!> !is ClassLevel1) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns(false) implies (<!UNRESOLVED_LABEL!>this@case_4<!> !is ClassLevel1)<!> }
return this == null
}
fun <T : Boolean>T.case_4_2() {
contract { returns() implies (!this@case_4_2) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (!this@case_4_2)<!> }
if (this) throw Exception()
}
@@ -60,12 +60,12 @@ class case_4 : ClassLevel3() {
class case_5<T> : ClassLevel5() {
inner class case_5_1 {
fun <K : Number?>K.case_5_1_1() {
contract { returns() implies (<!UNRESOLVED_LABEL!>this@case_5_1<!> !is ClassLevel1 && <!UNRESOLVED_LABEL!>this@case_5_1<!> != null || <!UNRESOLVED_LABEL!>this@case_5<!> is ClassLevel1 && this@case_5_1_1 is Float) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (<!UNRESOLVED_LABEL!>this@case_5_1<!> !is ClassLevel1 && <!UNRESOLVED_LABEL!>this@case_5_1<!> != null || <!UNRESOLVED_LABEL!>this@case_5<!> is ClassLevel1 && this@case_5_1_1 is Float)<!> }
if (!(this@case_5_1 !is ClassLevel1 && this@case_5_1 != null || this@case_5 is ClassLevel1 && this is Float)) throw Exception()
}
fun case_5_1_2() {
contract { returns() implies (<!UNRESOLVED_LABEL!>this@case_5_1<!> !is ClassLevel1 || <!UNRESOLVED_LABEL!>this@case_5<!> is ClassLevel1 || <!UNRESOLVED_LABEL!>this@case_5_1<!> == null) }
contract { <!ERROR_IN_CONTRACT_DESCRIPTION!>returns() implies (<!UNRESOLVED_LABEL!>this@case_5_1<!> !is ClassLevel1 || <!UNRESOLVED_LABEL!>this@case_5<!> is ClassLevel1 || <!UNRESOLVED_LABEL!>this@case_5_1<!> == null)<!> }
if (!(this@case_5_1 !is ClassLevel1 || this@case_5 is ClassLevel1 || this@case_5_1 == null)) throw Exception()
}
}