[FIR-TEST] Add new testdata generated after changes in previous commit
This commit is contained in:
Vendored
+42
@@ -0,0 +1,42 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
|
||||
package my
|
||||
|
||||
// Accepts block, can't be distinguished from kotlin.contract without resolve
|
||||
fun contract(block: () -> Unit) {}
|
||||
|
||||
// Accepts int, potentially can be distinguished from kotlin.contract by PSI,
|
||||
// but as of Kotlin 1.3.0, we don't do that
|
||||
fun contract(i: Int) {}
|
||||
|
||||
fun doStuff() {}
|
||||
|
||||
class SomeClass {
|
||||
|
||||
fun contract() {}
|
||||
|
||||
fun callMemberContractWithThis() {
|
||||
this.contract()
|
||||
}
|
||||
|
||||
fun callMemberContractWithoutThis() {
|
||||
contract()
|
||||
}
|
||||
|
||||
fun callTopLevelSamePsiInMember() {
|
||||
contract { }
|
||||
}
|
||||
}
|
||||
|
||||
fun callTopLevelSamePsi() {
|
||||
contract { }
|
||||
}
|
||||
|
||||
fun callTopLevelDifferentPsi() {
|
||||
contract(42)
|
||||
}
|
||||
|
||||
fun callTopLevelSamePsiNotFirstStatement() {
|
||||
doStuff()
|
||||
contract { }
|
||||
}
|
||||
Vendored
+23
@@ -0,0 +1,23 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun foo(b: Boolean): Boolean {
|
||||
contract {
|
||||
// pointless, can be reduced to just "b"
|
||||
returns(true) implies (b == true)
|
||||
}
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
fun bar(b: Boolean?): Boolean {
|
||||
contract {
|
||||
// not pointless, but not supported yet
|
||||
returns(true) implies (b == true)
|
||||
}
|
||||
if (b == null) throw java.lang.<!UNRESOLVED_REFERENCE!>IllegalArgumentException<!>("")
|
||||
return b
|
||||
}
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun bar(x: Int): Boolean = x == 0
|
||||
|
||||
fun foo(x: Int): Boolean {
|
||||
contract {
|
||||
returns(true) implies (bar(x))
|
||||
}
|
||||
return x == 0
|
||||
}
|
||||
Vendored
+86
@@ -0,0 +1,86 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -NOTHING_TO_INLINE -ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS -ABSTRACT_FUNCTION_WITH_BODY -UNUSED_PARAMETER -UNUSED_VARIABLE -EXPERIMENTAL_FEATURE_WARNING
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
|
||||
// ============= Class =====================
|
||||
open class Class {
|
||||
fun member(x: Boolean) {
|
||||
contract { returns() implies (x) }
|
||||
}
|
||||
|
||||
inline fun inlineMember(x: Boolean) {
|
||||
contract { returns() implies (x) }
|
||||
}
|
||||
|
||||
abstract fun abstractMember(x: Boolean) {
|
||||
contract { returns() implies (x) }
|
||||
}
|
||||
|
||||
open fun openMemeber(x: Boolean) {
|
||||
contract { returns() implies (x) }
|
||||
}
|
||||
|
||||
suspend fun suspendMember(x: Boolean) {
|
||||
contract { returns() implies (x) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ============= Top-level =====================
|
||||
fun topLevel(x: Boolean) {
|
||||
contract { returns() implies (x) }
|
||||
}
|
||||
|
||||
inline fun inlineTopLevel(x: Boolean) {
|
||||
contract { returns() implies (x) }
|
||||
}
|
||||
|
||||
suspend fun suspendTopLevel(x: Boolean) {
|
||||
contract { returns() implies (x) }
|
||||
}
|
||||
|
||||
// Top-level operator
|
||||
operator fun Boolean.plus(x: Boolean): Boolean {
|
||||
contract { returns() implies (x) }
|
||||
return x
|
||||
}
|
||||
|
||||
val topLevelLambda: (Boolean) -> Unit = { x: Boolean ->
|
||||
contract { returns() implies (x) }
|
||||
}
|
||||
|
||||
val topLevelAnonymousFunction = fun (x: Boolean) {
|
||||
contract { returns() implies (x) }
|
||||
}
|
||||
|
||||
var topLevelPropertyAccessors: Int? = 42
|
||||
get() {
|
||||
contract { returns() implies (field != null) }
|
||||
return 42
|
||||
}
|
||||
set(value) {
|
||||
contract { returns() implies (field != null) }
|
||||
}
|
||||
|
||||
|
||||
// ============= Local =====================
|
||||
fun test() {
|
||||
fun localDeclaration(x: Boolean) {
|
||||
contract { returns() implies (x) }
|
||||
}
|
||||
|
||||
suspend fun suspendlocalDeclaration(x: Boolean) {
|
||||
contract { returns() implies (x) }
|
||||
}
|
||||
|
||||
val localAnonymousFunction = fun (x: Boolean) {
|
||||
contract { returns() implies (x) }
|
||||
}
|
||||
|
||||
val localLambda: (Boolean) -> Unit = { x: Boolean ->
|
||||
contract { returns() implies (x) }
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun emptyContract() {
|
||||
contract { }
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -NOTHING_TO_INLINE -ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS -ABSTRACT_FUNCTION_WITH_BODY -UNUSED_PARAMETER -UNUSED_VARIABLE -EXPERIMENTAL_FEATURE_WARNING
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun ifInContract(x: Any?, boolean: Boolean) {
|
||||
contract {
|
||||
if (boolean) {
|
||||
returns() implies (x is String)
|
||||
} else {
|
||||
returns() implies (x is Int)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun whenInContract(x: Any?, boolean: Boolean) {
|
||||
contract {
|
||||
when (boolean) {
|
||||
true -> returns() implies (x is String)
|
||||
else -> returns() implies (x is Int)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun forInContract(x: Any?) {
|
||||
contract {
|
||||
for (i in 0..1) {
|
||||
returns() implies (x is String)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun whileInContract(x: Any?) {
|
||||
contract {
|
||||
while (false) {
|
||||
returns() implies (x is String)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun doWhileInContract(x: Any?) {
|
||||
contract {
|
||||
do {
|
||||
returns() implies (x is String)
|
||||
} while (false)
|
||||
}
|
||||
}
|
||||
|
||||
fun localValInContract(x: Any?) {
|
||||
contract {
|
||||
val y: Int = 42
|
||||
returns() implies (x is String)
|
||||
}
|
||||
}
|
||||
Vendored
+30
@@ -0,0 +1,30 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun equalsWithVariables(x: Any?, y: Any?) {
|
||||
contract {
|
||||
returns() implies (x == y)
|
||||
}
|
||||
}
|
||||
|
||||
fun identityEqualsWithVariables(x: Any?, y: Any?) {
|
||||
contract {
|
||||
returns() implies (x === y)
|
||||
}
|
||||
}
|
||||
|
||||
fun equalConstants() {
|
||||
contract {
|
||||
returns() implies (null == null)
|
||||
}
|
||||
}
|
||||
|
||||
fun get(): Int? = null
|
||||
fun equalNullWithCall() {
|
||||
contract {
|
||||
returns() implies (get() == null)
|
||||
}
|
||||
}
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun foo(boolean: Boolean) {
|
||||
contract {
|
||||
(returns() implies (boolean)) <!UNRESOLVED_REFERENCE!>implies<!> (!boolean)
|
||||
}
|
||||
}
|
||||
compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/nonLambdaLiteralAsArgument.fir.kt
Vendored
+15
@@ -0,0 +1,15 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -EXPOSED_PARAMETER_TYPE
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun passLambdaValue(l: ContractBuilder.() -> Unit) {
|
||||
contract(l)
|
||||
}
|
||||
|
||||
fun passAnonymousFunction(x: Boolean) {
|
||||
contract(fun ContractBuilder.() {
|
||||
<!UNRESOLVED_REFERENCE!>returns<!>() <!UNRESOLVED_REFERENCE!>implies<!> x
|
||||
})
|
||||
}
|
||||
Vendored
+76
@@ -0,0 +1,76 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER -UNUSED_VARIABLE -REDUNDANT_LABEL_WARNING -UNUSED_PARAMETER -NOTHING_TO_INLINE -CAST_NEVER_SUCCEEDS
|
||||
// Issues: KT-26153, KT-26191
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun foo(y: Boolean) {
|
||||
val x: Int = 42
|
||||
contract {
|
||||
returns() implies y
|
||||
}
|
||||
}
|
||||
|
||||
inline fun case1(block: () -> Unit) {
|
||||
val contracts = listOf(
|
||||
contract {
|
||||
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
|
||||
}, contract {
|
||||
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
)
|
||||
block()
|
||||
}
|
||||
|
||||
inline fun case_2(block: () -> Unit) = contract {
|
||||
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
|
||||
fun case_3(block: () -> Unit) {
|
||||
class Class {
|
||||
fun innerFun(block2: () -> Unit) {
|
||||
contract {
|
||||
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block2, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
block2()
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
inline fun case_4(number: Int?): Boolean {
|
||||
val cond = number != null
|
||||
contract {
|
||||
returns(false) implies (cond)
|
||||
} as ContractBuilder
|
||||
return number == null
|
||||
}
|
||||
|
||||
inline fun case_5(cond: Boolean): Boolean {
|
||||
run {
|
||||
contract {
|
||||
returns(true) implies (cond)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
inline fun case_6(cond: Boolean): Boolean {
|
||||
run {
|
||||
val x = 10
|
||||
contract {
|
||||
returns(true) implies (cond)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun case_7(cond: Boolean): Boolean {
|
||||
fun innerFun() {
|
||||
contract {
|
||||
returns(true) implies (cond)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !LANGUAGE: +UseReturnsEffect
|
||||
// Issue: KT-26386
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun case_1(): Boolean {
|
||||
contract { returns(null) implies case_1() }
|
||||
return true
|
||||
}
|
||||
|
||||
fun case_2(): Boolean {
|
||||
contract { returns(null) implies case_3() }
|
||||
return true
|
||||
}
|
||||
|
||||
fun case_3(): Boolean {
|
||||
contract { returns(null) implies case_2() }
|
||||
return true
|
||||
}
|
||||
|
||||
fun case_4(): Boolean {
|
||||
kotlin.contracts.contract { returns(null) implies case_1() }
|
||||
return true
|
||||
}
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !LANGUAGE: +UseReturnsEffect
|
||||
// Issue: KT-26386
|
||||
|
||||
fun myRun(block: () -> Unit) {
|
||||
block()
|
||||
}
|
||||
|
||||
fun contract(block: () -> Unit) {
|
||||
block()
|
||||
}
|
||||
|
||||
fun case_1(): Boolean? {
|
||||
contract { case_1() }
|
||||
return null
|
||||
}
|
||||
|
||||
fun case_2(): Boolean? {
|
||||
contract { case_3() }
|
||||
return null
|
||||
}
|
||||
|
||||
fun case_3(): Boolean? {
|
||||
contract { case_2() }
|
||||
return null
|
||||
}
|
||||
|
||||
fun case4() {
|
||||
contract {
|
||||
myRun {
|
||||
val s: String
|
||||
run {
|
||||
s = "hello"
|
||||
}
|
||||
s.length
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
class Foo(val x: Int?) {
|
||||
fun isXNull(): Boolean {
|
||||
contract {
|
||||
returns(false) implies (x != null)
|
||||
}
|
||||
return x != null
|
||||
}
|
||||
}
|
||||
+53
@@ -0,0 +1,53 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
inline fun <reified T> referToReifiedGeneric(x: Any?) {
|
||||
contract {
|
||||
returns() implies (x is T)
|
||||
}
|
||||
}
|
||||
|
||||
class Generic<T> {
|
||||
fun referToCaptured(x: Any?) {
|
||||
contract {
|
||||
returns() implies (x is T)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun referToSubstituted(x: Any?) {
|
||||
contract {
|
||||
returns() implies (x is Generic<String>)
|
||||
}
|
||||
}
|
||||
|
||||
fun referToSubstitutedWithStar(x: Any?) {
|
||||
contract {
|
||||
returns() implies (x is Generic<*>)
|
||||
}
|
||||
}
|
||||
|
||||
typealias GenericString = Generic<String>
|
||||
typealias FunctionalType = () -> Unit
|
||||
typealias SimpleType = Int
|
||||
|
||||
fun referToAliasedGeneric(x: Any?) {
|
||||
contract {
|
||||
returns() implies (x is GenericString)
|
||||
}
|
||||
}
|
||||
|
||||
fun referToAliasedFunctionType(x: Any?) {
|
||||
contract {
|
||||
returns() implies (x is FunctionalType)
|
||||
}
|
||||
}
|
||||
|
||||
fun referToAliasedSimpleType(x: Any?) {
|
||||
contract {
|
||||
returns() implies (x is SimpleType)
|
||||
}
|
||||
}
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun Any?.foo(): Boolean {
|
||||
contract {
|
||||
returns(true) implies (this != null)
|
||||
}
|
||||
return this != null
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
|
||||
import kotlin.contracts.InvocationKind
|
||||
|
||||
inline fun foo(block: () -> Unit) {
|
||||
kotlin.contracts.contract {
|
||||
<!INAPPLICABLE_CANDIDATE!>callsInPlace<!>(block, InvocationKind.EXACTLY_ONCE)
|
||||
}
|
||||
block()
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val x: Int
|
||||
foo {
|
||||
x = 42
|
||||
}
|
||||
println(x)
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// See KT-28847
|
||||
|
||||
class Foo(val str: String?) {
|
||||
val first = run {
|
||||
str.isNullOrEmpty()
|
||||
second
|
||||
}
|
||||
|
||||
val second = str.isNullOrEmpty()
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect
|
||||
// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER
|
||||
// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts
|
||||
|
||||
import kotlin.contracts.*
|
||||
|
||||
fun test(x: Any?) {
|
||||
if (isString(x)) {
|
||||
x.<!UNRESOLVED_REFERENCE!>length<!>
|
||||
}
|
||||
}
|
||||
|
||||
fun isString(x: Any?): Boolean {
|
||||
contract {
|
||||
returns(true) implies (x is String)
|
||||
}
|
||||
return x is String
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user